Changeset 299

Show
Ignore:
Timestamp:
06/23/08 03:42:48 (2 months ago)
Author:
mario
Message:
 
Location:
branches/0.5/daemon/orbited/static
Files:
2 removed
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.5/daemon/orbited/static/demos/xmpp/xmpp.html

    r296 r299  
    1515     
    1616    <script src="/_/static/BinaryTCPConnectionBuild.js"></script> 
     17    <script src="/_/static/protocols/xmpp/xmpp.js"></script> 
    1718    <script src="chat.js"></script> 
    1819    <script src="userlist.js"></script> 
    1920    <script src="xmpp.js"></script> 
    20     <script src="parser.js"></script> 
    21     <script src="client.js"></script> 
    22     <script> 
    23     //// 
    24     // 'localhost' IS A PLACEHOLDER 
    25     xmpp = new XMPPClient(); 
    26     xmpp.connect('localhost', 5222); 
    27     // CHANGE TO ADDRESS OF PHYSICAL MACHINE 
    28     //// 
    29     </script> 
    3021    <link rel="stylesheet" href="xmpp.css" type="text/css" media="screen" title="no title" charset="utf-8"> 
    3122    </head> 
  • branches/0.5/daemon/orbited/static/demos/xmpp/xmpp.js

    r296 r299  
    122122} 
    123123 
     124//// 
     125// create xmpp client 
     126// register callbacks 
     127// connect to xmpp server 
     128xmpp = new XMPPClient(); 
     129xmpp.onPresence = function(ntype, from, to) { 
     130    if (! ntype) { 
     131        userList.onUserAvailable(from, from); 
     132    } 
     133    else if (ntype == "unavailable") { 
     134        userList.onUserUnavailable(from); 
     135    } 
     136    else if (ntype == "subscribe") { 
     137        xmpp.sendSubscribed(from, to); 
     138    } 
     139    else if (ntype == "subscribed") { 
     140        alert(from + " added to your buddy list!"); 
     141    } 
     142    else if (ntype == "unsubscribed") { 
     143        userList.onUserUnavailable(from); 
     144    } 
     145} 
     146xmpp.onMessage = onMessage; 
     147xmpp.onSocketConnect = function() { 
     148    domain = prompt("Domain","localhost"); 
     149    if (domain) { 
     150        xmpp.connectServer(domain, connectSuccess, connectFailure); 
     151    } 
     152} 
     153//// 
     154// 'localhost' IS A PLACEHOLDER 
     155xmpp.connect('localhost', 5222); 
     156// (CHANGE TO ADDRESS OF PHYSICAL MACHINE) 
     157//// 
     158// success / failure callbacks 
     159function registerSuccess() { 
     160    alert("Welcome!"); 
     161} 
     162function registerFailure() { 
     163    if (confirm("That user name is taken. Try again?")) { 
     164        prompt_register(); 
     165    } 
     166} 
     167function loginSuccess() { 
     168    alert("Welcome!"); 
     169} 
     170function loginFailure() { 
     171    if (confirm("Login failed. Register a new user account?")) { 
     172        prompt_register(); 
     173    } 
     174    else { 
     175        prompt_login(); 
     176    } 
     177} 
     178function connectSuccess() { 
     179    prompt_login(); 
     180} 
     181function connectFailure() { 
     182    alert("Unknown domain"); 
     183} 
     184//// 
     185// helpers 
     186function prompt_login() { 
     187    var u = prompt("User name","frank"); 
     188    if (u) { 
     189        var p = prompt("Password","pass"); 
     190        if (p) { 
     191            xmpp.login(u, p, loginSuccess, loginFailure); 
     192        } 
     193    } 
     194} 
     195function prompt_register() { 
     196    var u = prompt("New user name","ariel"); 
     197    if (u) { 
     198        var p = prompt("New password","pass"); 
     199        if (p) { 
     200            xmpp.register(u, p, registerSuccess, registerFailure); 
     201        } 
     202    } 
     203} 
     204//// 
     205 
    124206/** Used to track the open message windows, keyed by JID */ 
    125207var messageWindows = {}; 
     
    146228/** Called when the user wants to add that contact */ 
    147229function onAddContact(jid) { 
    148     xmpp.add(jid); 
     230    xmpp.subscribe(jid); 
     231    alert("Buddy request sent."); 
    149232} 
    150233 
    151234/** Called when the user clicks the user list's remove contact button */ 
    152235function onRemoveContact(jid, username) { 
    153     xmpp.remove(jid); 
    154 } 
    155  
    156  
     236    xmpp.unsubscribe(jid); 
     237    userList.onUserUnavailable(jid); 
     238} 
    157239 
    158240/// SAMPLE DATA