[2271] | 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
---|
| 2 | <html xmlns='http://www.w3.org/1999/xhtml'> |
---|
| 3 | <head> |
---|
| 4 | <title>Strophe Attach Example</title> |
---|
| 5 | <script language='javascript' |
---|
| 6 | type='text/javascript' |
---|
| 7 | src='http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js'></script> |
---|
| 8 | <script language='javascript' |
---|
| 9 | type='text/javascript' |
---|
| 10 | src='http://code.stanziq.com/svn/strophe/trunk/strophejs/b64.js'></script> |
---|
| 11 | <script language='javascript' |
---|
| 12 | type='text/javascript' |
---|
| 13 | src='http://code.stanziq.com/svn/strophe/trunk/strophejs/md5.js'></script> |
---|
| 14 | <script language='javascript' |
---|
| 15 | type='text/javascript' |
---|
| 16 | src='http://code.stanziq.com/svn/strophe/trunk/strophejs/sha1.js'></script> |
---|
| 17 | <script language='javascript' |
---|
| 18 | type='text/javascript' |
---|
| 19 | src='http://code.stanziq.com/svn/strophe/trunk/strophejs/strophe.js'></script> |
---|
| 20 | <script language='javascript' |
---|
| 21 | type='text/javascript'> |
---|
| 22 | <!-- |
---|
| 23 | var ATTACH_SID = "{{ sid }}"; |
---|
| 24 | var ATTACH_RID = "{{ rid }}"; |
---|
| 25 | var ATTACH_JID = "{{ jid }}"; |
---|
| 26 | var BOSH_SERVICE = '/xmpp-httpbind'; |
---|
| 27 | var connection = null; |
---|
| 28 | var startTime = null; |
---|
| 29 | |
---|
| 30 | function log(msg) |
---|
| 31 | { |
---|
| 32 | $('#log').append('<div></div>').append( |
---|
| 33 | document.createTextNode(msg)); |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | function onConnect(status) |
---|
| 37 | { |
---|
| 38 | if (status == Strophe.Status.DISCONNECTED) |
---|
| 39 | log('Disconnected.'); |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | function onResult(iq) { |
---|
| 43 | var elapsed = (new Date()) - startTime; |
---|
| 44 | log('Response from jabber.org took ' + elapsed + 'ms.'); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | $(document).ready(function () { |
---|
| 48 | // create the connection and attach it |
---|
| 49 | connection = new Strophe.Connection(BOSH_SERVICE); |
---|
| 50 | connection.rawInput = function (data) { |
---|
| 51 | log('RECV: ' + data); |
---|
| 52 | }; |
---|
| 53 | connection.rawOutput = function (data) { |
---|
| 54 | log('SENT: ' + data); |
---|
| 55 | }; |
---|
| 56 | // uncomment for extra debugging |
---|
| 57 | // Strophe.log = function (lvl, msg) { log(msg); }; |
---|
| 58 | connection.attach(ATTACH_JID, ATTACH_SID, ATTACH_RID, |
---|
| 59 | onConnect); |
---|
| 60 | |
---|
| 61 | // set up handler |
---|
| 62 | connection.addHandler(onResult, null, 'iq', |
---|
| 63 | 'result', 'disco-1', null); |
---|
| 64 | |
---|
| 65 | log('Strophe is attached.'); |
---|
| 66 | |
---|
| 67 | // send disco#info to jabber.org |
---|
| 68 | var iq = $iq({to: 'jabber.org', |
---|
| 69 | type: 'get', |
---|
| 70 | id: 'disco-1'}) |
---|
| 71 | .c('query', {xmlns: Strophe.NS.DISCO_INFO}) |
---|
| 72 | .tree() |
---|
| 73 | |
---|
| 74 | startTime = new Date(); |
---|
| 75 | connection.send(iq); |
---|
| 76 | }); |
---|
| 77 | // --> |
---|
| 78 | </script> |
---|
| 79 | </head> |
---|
| 80 | <body> |
---|
| 81 | <h1>Strophe Attach Example</h1> |
---|
| 82 | <p>This example shows how to attach to an existing BOSH session with |
---|
| 83 | Strophe.</p> |
---|
| 84 | <h2>Log</h2> |
---|
| 85 | <div id='log'> |
---|
| 86 | </div> |
---|
| 87 | </body> |
---|
| 88 | </html> |
---|