1
+ var BOSH_SERVICE = 'http://localhost:5280/bosh' ;
2
+
3
+ var connection = null ;
4
+ var browser = null ;
5
+ var show_log = true ;
6
+
7
+ function log ( msg )
8
+ {
9
+ $ ( '#log' ) . append ( '<div></div>' ) . append ( document . createTextNode ( msg ) ) ;
10
+ }
11
+
12
+
13
+ function rawInput ( data )
14
+ {
15
+ log ( 'RECV: ' + data ) ;
16
+ }
17
+
18
+ function rawOutput ( data )
19
+ {
20
+ log ( 'SENT: ' + data ) ;
21
+ }
22
+
23
+ function onConnect ( status )
24
+ {
25
+ if ( status == Strophe . Status . CONNECTING ) {
26
+ log ( 'Strophe is connecting.' ) ;
27
+
28
+ } else if ( status == Strophe . Status . CONNFAIL ) {
29
+ log ( 'Strophe failed to connect.' ) ;
30
+ showConnect ( ) ;
31
+ } else if ( status == Strophe . Status . DISCONNECTING ) {
32
+ log ( 'Strophe is disconnecting.' ) ;
33
+ } else if ( status == Strophe . Status . DISCONNECTED ) {
34
+ log ( 'Strophe is disconnected.' ) ;
35
+ showConnect ( ) ;
36
+
37
+ } else if ( status == Strophe . Status . CONNECTED ) {
38
+ log ( 'Strophe is connected.' ) ;
39
+ // Start up disco browser
40
+ browser . showBrowser ( ) ;
41
+ }
42
+ }
43
+
44
+ function showConnect ( )
45
+ {
46
+ var jid = $ ( '#jid' ) ;
47
+ var pass = $ ( '#pass' ) ;
48
+ var button = $ ( '#connect' ) . get ( 0 ) ;
49
+
50
+ browser . closeBrowser ( ) ;
51
+
52
+ $ ( 'label' ) . show ( ) ;
53
+ jid . show ( ) ;
54
+ pass . show ( ) ;
55
+ $ ( '#anon' ) . show ( ) ;
56
+ button . value = 'connect' ;
57
+ return false ;
58
+ }
59
+
60
+ function showDisconnect ( )
61
+ {
62
+ var jid = $ ( '#jid' ) ;
63
+ var pass = $ ( '#pass' ) ;
64
+ var button = $ ( '#connect' ) . get ( 0 ) ;
65
+
66
+ button . value = 'disconnect' ;
67
+ pass . hide ( ) ;
68
+ jid . hide ( ) ;
69
+ $ ( 'label' ) . hide ( ) ;
70
+ $ ( '#anon' ) . hide ( ) ;
71
+ return false ;
72
+ }
73
+
74
+ $ ( document ) . ready ( function ( ) {
75
+ connection = new Strophe . Connection ( BOSH_SERVICE ) ;
76
+ connection . rawInput = rawInput ;
77
+ connection . rawOutput = rawOutput ;
78
+
79
+ browser = new Disco ( ) ;
80
+
81
+ $ ( "#log_container" ) . bind ( 'click' , function ( ) {
82
+ $ ( "#log" ) . toggle ( ) ;
83
+ }
84
+ ) ;
85
+
86
+ $ ( '#cred' ) . bind ( 'submit' , function ( ) {
87
+ var button = $ ( '#connect' ) . get ( 0 ) ;
88
+ var jid = $ ( '#jid' ) ;
89
+ var pass = $ ( '#pass' ) ;
90
+
91
+ if ( button . value == 'connect' ) {
92
+ showDisconnect ( ) ;
93
+ connection . connect ( jid . get ( 0 ) . value ,
94
+ pass . get ( 0 ) . value ,
95
+ onConnect ) ;
96
+ } else {
97
+ connection . disconnect ( ) ;
98
+ showConnect ( ) ;
99
+ }
100
+ return false ;
101
+ } ) ;
102
+ } ) ;
0 commit comments