1 | // The BOSH_SERVICE here doesn't need to be on the same domain/port, but |
---|
2 | // it must have a /crossdomain.xml policy file that allows access from |
---|
3 | // wherever crossdomain.html lives. |
---|
4 | // |
---|
5 | // Most BOSH connection managers can serve static html files, so you should |
---|
6 | // be able to configure them to serve a /crossdomain.xml file to allow |
---|
7 | // access. |
---|
8 | var BOSH_SERVICE = 'http://localhost:5281/xmpp-httpbind' |
---|
9 | var connection = null; |
---|
10 | |
---|
11 | function log(msg) |
---|
12 | { |
---|
13 | $('#log').append('<div></div>').append(document.createTextNode(msg)); |
---|
14 | } |
---|
15 | |
---|
16 | function rawInput(data) |
---|
17 | { |
---|
18 | log('RECV: ' + data); |
---|
19 | } |
---|
20 | |
---|
21 | function rawOutput(data) |
---|
22 | { |
---|
23 | log('SENT: ' + data); |
---|
24 | } |
---|
25 | |
---|
26 | function onConnect(status) |
---|
27 | { |
---|
28 | if (status == Strophe.Status.CONNECTING) { |
---|
29 | log('Strophe is connecting.'); |
---|
30 | } else if (status == Strophe.Status.CONNFAIL) { |
---|
31 | log('Strophe failed to connect.'); |
---|
32 | $('#connect').get(0).value = 'connect'; |
---|
33 | } else if (status == Strophe.Status.DISCONNECTING) { |
---|
34 | log('Strophe is disconnecting.'); |
---|
35 | } else if (status == Strophe.Status.DISCONNECTED) { |
---|
36 | log('Strophe is disconnected.'); |
---|
37 | $('#connect').get(0).value = 'connect'; |
---|
38 | } else if (status == Strophe.Status.CONNECTED) { |
---|
39 | log('Strophe is connected.'); |
---|
40 | connection.disconnect(); |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | $(document).ready(function () { |
---|
45 | connection = new Strophe.Connection(BOSH_SERVICE); |
---|
46 | connection.rawInput = rawInput; |
---|
47 | connection.rawOutput = rawOutput; |
---|
48 | |
---|
49 | $('#connect').bind('click', function () { |
---|
50 | var button = $('#connect').get(0); |
---|
51 | if (button.value == 'connect') { |
---|
52 | button.value = 'disconnect'; |
---|
53 | |
---|
54 | connection.connect($('#jid').get(0).value, |
---|
55 | $('#pass').get(0).value, |
---|
56 | onConnect); |
---|
57 | } else { |
---|
58 | button.value = 'connect'; |
---|
59 | connection.disconnect(); |
---|
60 | } |
---|
61 | }); |
---|
62 | }); |
---|