[2271] | 1 | YUI().use('node', function (Y) { |
---|
| 2 | var BOSH_SERVICE = '/xmpp-httpbind'; |
---|
| 3 | var connection = null; |
---|
| 4 | |
---|
| 5 | var log = Y.one('#log'); |
---|
| 6 | |
---|
| 7 | Y.augment(Strophe.Connection, Y.EventTarget); |
---|
| 8 | |
---|
| 9 | Y.one('#connect').on('click', function (e) { |
---|
| 10 | var jid = Y.one('#jid').get('value'); |
---|
| 11 | var pass_node = Y.one('#pass'); |
---|
| 12 | var pass = pass_node.get('value'); |
---|
| 13 | pass_node.set('value', ''); |
---|
| 14 | |
---|
| 15 | connection = new Strophe.Connection(BOSH_SERVICE); |
---|
| 16 | |
---|
| 17 | log.append('<p>Connecting...</p>'); |
---|
| 18 | |
---|
| 19 | connection.connect(jid, pass, function (status) { |
---|
| 20 | if (status === Strophe.Status.CONNECTED) { |
---|
| 21 | connection.fire('connected'); |
---|
| 22 | } else if (status === Strophe.Status.DISCONNECTED) { |
---|
| 23 | connection.fire('disconnected'); |
---|
| 24 | } |
---|
| 25 | }); |
---|
| 26 | |
---|
| 27 | connection.on('connected', function () { |
---|
| 28 | log.append('<p>Connected.</p>'); |
---|
| 29 | |
---|
| 30 | var ping = $iq({to: 'jabber.org', type: 'get'}) |
---|
| 31 | .c('query', {xmlns: Strophe.NS.DISCO_ITEMS}); |
---|
| 32 | |
---|
| 33 | var sent_stamp = new Date(); |
---|
| 34 | connection.sendIQ(ping, function (iq) { |
---|
| 35 | var elapsed = new Date() - sent_stamp; |
---|
| 36 | |
---|
| 37 | // convert incoming XMPP stanza to a Node |
---|
| 38 | var stanza = Y.Selector.query('item', iq, null, true); |
---|
| 39 | window['stanza'] = iq; |
---|
| 40 | window['Y'] = Y; |
---|
| 41 | |
---|
| 42 | console.log(stanza); |
---|
| 43 | |
---|
| 44 | log.append("<p>Disco#items response received after " + |
---|
| 45 | elapsed + "ms. Jabber.org reports it has " + |
---|
| 46 | items + " items.</p>"); |
---|
| 47 | |
---|
| 48 | connection.disconnect(); |
---|
| 49 | }); |
---|
| 50 | |
---|
| 51 | log.append('<p>Ping sent.</p>'); |
---|
| 52 | }); |
---|
| 53 | |
---|
| 54 | connection.on('disconnected', function () { |
---|
| 55 | log.append('<p>Disconnected.</p>'); |
---|
| 56 | }); |
---|
| 57 | }); |
---|
| 58 | }); |
---|