25
25
*/
26
26
27
27
var xmpp = require ( 'node-xmpp-client' ) ;
28
+ var Stanza = xmpp . Stanza ;
28
29
var EventEmitter = require ( 'events' ) . EventEmitter ;
29
30
var util = require ( 'util' ) ;
30
31
var qbox = require ( 'qbox' ) ;
@@ -46,7 +47,6 @@ function SimpleXMPP() {
46
47
//setting status here
47
48
this . STATUS = STATUS ;
48
49
var self = this ;
49
- this . Element = xmpp . Element ;
50
50
var config ;
51
51
var conn ;
52
52
var probeBuddies = { } ;
@@ -83,7 +83,7 @@ function SimpleXMPP() {
83
83
if ( ! joinedRooms [ room ] ) {
84
84
joinedRooms [ room ] = true ;
85
85
}
86
- var stanza = new xmpp . Stanza . Element ( 'presence' , { to : to } ) .
86
+ var stanza = new Stanza ( 'presence' , { to : to } ) .
87
87
c ( 'x' , { xmlns : 'http://jabber.org/protocol/muc' } ) ;
88
88
// XEP-0045 7.2.6 Password-Protected Rooms
89
89
if ( password != null && password != "" )
@@ -95,7 +95,7 @@ function SimpleXMPP() {
95
95
this . invite = function ( to , room , reason ) {
96
96
97
97
$ . ready ( function ( ) {
98
- var stanza = new xmpp . Stanza . Element ( 'message' , { to : room } ) .
98
+ var stanza = new Stanza ( 'message' , { to : room } ) .
99
99
c ( 'x' , { xmlns : 'http://jabber.org/protocol/muc#user' } ) .
100
100
c ( 'invite' , { to : to } ) ;
101
101
if ( reason )
@@ -108,15 +108,15 @@ function SimpleXMPP() {
108
108
this . subscribe = function ( to ) {
109
109
110
110
$ . ready ( function ( ) {
111
- var stanza = new xmpp . Stanza ( 'presence' , { to : to , type : 'subscribe' } ) ;
111
+ var stanza = new Stanza ( 'presence' , { to : to , type : 'subscribe' } ) ;
112
112
conn . send ( stanza ) ;
113
113
} ) ;
114
114
} ;
115
115
116
116
this . unsubscribe = function ( to ) {
117
117
118
118
$ . ready ( function ( ) {
119
- var stanza = new xmpp . Stanza ( 'presence' , { to : to , type : 'unsubscribe' } ) ;
119
+ var stanza = new Stanza ( 'presence' , { to : to , type : 'unsubscribe' } ) ;
120
120
conn . send ( stanza ) ;
121
121
} ) ;
122
122
} ;
@@ -126,23 +126,23 @@ function SimpleXMPP() {
126
126
// Send a 'subscribed' notification back to accept the incoming
127
127
// subscription request
128
128
$ . ready ( function ( ) {
129
- var stanza = new xmpp . Stanza ( 'presence' , { to : to , type : 'subscribed' } ) ;
129
+ var stanza = new Stanza ( 'presence' , { to : to , type : 'subscribed' } ) ;
130
130
conn . send ( stanza ) ;
131
131
} ) ;
132
132
} ;
133
133
134
134
this . acceptUnsubscription = function ( to ) {
135
135
136
136
$ . ready ( function ( ) {
137
- var stanza = new xmpp . Stanza ( 'presence' , { to : to , type : 'unsubscribed' } ) ;
137
+ var stanza = new Stanza ( 'presence' , { to : to , type : 'unsubscribed' } ) ;
138
138
conn . send ( stanza ) ;
139
139
} ) ;
140
140
} ;
141
141
142
142
this . getRoster = function ( ) {
143
143
144
144
$ . ready ( function ( ) {
145
- var roster = new xmpp . Stanza ( 'iq' , { id : 'roster_0' , type : 'get' } ) ;
145
+ var roster = new Stanza ( 'iq' , { id : 'roster_0' , type : 'get' } ) ;
146
146
roster . c ( 'query' , { xmlns : 'jabber:iq:roster' } ) ;
147
147
conn . send ( roster ) ;
148
148
} ) ;
@@ -152,7 +152,7 @@ function SimpleXMPP() {
152
152
153
153
probeBuddies [ buddy ] = true ;
154
154
$ . ready ( function ( ) {
155
- var stanza = new xmpp . Stanza ( 'presence' , { type : 'probe' , to : buddy } ) ;
155
+ var stanza = new Stanza ( 'presence' , { type : 'probe' , to : buddy } ) ;
156
156
events . once ( 'probe_' + buddy , callback ) ;
157
157
conn . send ( stanza ) ;
158
158
} ) ;
@@ -177,7 +177,7 @@ function SimpleXMPP() {
177
177
this . getVCard = function ( buddy , callback ) {
178
178
$ . ready ( function ( ) {
179
179
var id = 'get-vcard-' + buddy . split ( '@' ) . join ( '--' ) ;
180
- var stanza = new xmpp . Stanza ( 'iq' , { type : 'get' , id : id } ) .
180
+ var stanza = new Stanza ( 'iq' , { type : 'get' , id : id } ) .
181
181
c ( 'vCard' , { xmlns : 'vcard-temp' } ) .
182
182
up ( ) ;
183
183
iqCallbacks [ id ] = function ( response ) {
@@ -195,7 +195,7 @@ function SimpleXMPP() {
195
195
this . getVCardForUser = function ( jid , user , callback ) {
196
196
$ . ready ( function ( ) {
197
197
var id = 'get-vcard-' + user . split ( '@' ) . join ( '-' ) ;
198
- var stanza = new xmpp . Stanza ( 'iq' , { from : jid , type : 'get' , id : id , to : user } ) .
198
+ var stanza = new Stanza ( 'iq' , { from : jid , type : 'get' , id : id , to : user } ) .
199
199
c ( 'vCard' , { xmlns : 'vcard-temp' } ) .
200
200
up ( ) ;
201
201
iqCallbacks [ id ] = function ( response ) {
@@ -228,7 +228,7 @@ function SimpleXMPP() {
228
228
// * add caps support
229
229
this . setPresence = function ( show , status ) {
230
230
$ . ready ( function ( ) {
231
- var stanza = new xmpp . Stanza ( 'presence' ) ;
231
+ var stanza = new Stanza ( 'presence' ) ;
232
232
if ( show && show !== STATUS . ONLINE ) {
233
233
stanza . c ( 'show' ) . t ( show ) ;
234
234
}
@@ -251,7 +251,7 @@ function SimpleXMPP() {
251
251
// See XEP-0085 for details on the meaning of those states.
252
252
this . setChatstate = function ( to , state ) {
253
253
$ . ready ( function ( ) {
254
- var stanza = new xmpp . Stanza ( 'message' , { to : to } ) .
254
+ var stanza = new Stanza ( 'message' , { to : to } ) .
255
255
c ( state , { xmlns : NS_CHATSTATES } ) .
256
256
up ( ) ;
257
257
conn . send ( stanza ) ;
@@ -267,7 +267,7 @@ function SimpleXMPP() {
267
267
268
268
this . disconnect = function ( ) {
269
269
$ . ready ( function ( ) {
270
- var stanza = new xmpp . Stanza ( 'presence' , { type : 'unavailable' } ) ;
270
+ var stanza = new Stanza ( 'presence' , { type : 'unavailable' } ) ;
271
271
stanza . c ( 'status' ) . t ( 'Logged out' ) ;
272
272
conn . send ( stanza ) ;
273
273
} ) ;
@@ -297,7 +297,7 @@ function SimpleXMPP() {
297
297
298
298
conn . on ( 'online' , function ( data ) {
299
299
if ( ! config . skipPresence ) {
300
- conn . send ( new xmpp . Stanza ( 'presence' ) ) ;
300
+ conn . send ( new Stanza ( 'presence' ) ) ;
301
301
}
302
302
events . emit ( 'online' , data ) ;
303
303
$ . start ( ) ;
@@ -406,7 +406,7 @@ function SimpleXMPP() {
406
406
}
407
407
capBuddies [ fullNode ] . push ( id ) ;
408
408
409
- var getCaps = new xmpp . Stanza ( 'iq' , { id : 'disco1' , to : from , type : 'get' } ) ;
409
+ var getCaps = new Stanza ( 'iq' , { id : 'disco1' , to : from , type : 'get' } ) ;
410
410
getCaps . c ( 'query' , { xmlns : 'http://jabber.org/protocol/disco#info' , node : fullNode } ) ;
411
411
conn . send ( getCaps ) ;
412
412
}
@@ -417,7 +417,7 @@ function SimpleXMPP() {
417
417
}
418
418
} else if ( stanza . is ( 'iq' ) ) {
419
419
if ( stanza . getChild ( 'ping' , 'urn:xmpp:ping' ) ) {
420
- conn . send ( new xmpp . Stanza ( 'iq' , { id : stanza . attrs . id , to : stanza . attrs . from , type : 'result' } ) ) ;
420
+ conn . send ( new Stanza ( 'iq' , { id : stanza . attrs . id , to : stanza . attrs . from , type : 'result' } ) ) ;
421
421
}
422
422
// Response to capabilities request?
423
423
else if ( stanza . attrs . id === 'disco1' ) {
@@ -464,5 +464,7 @@ function SimpleXMPP() {
464
464
465
465
}
466
466
467
+ SimpleXMPP . prototype . Element = xmpp . Element
468
+
467
469
// Allow for multiple connections
468
470
module . exports . SimpleXMPP = SimpleXMPP ;
0 commit comments