@babblevoice/projectrtp 2.4.10 → 2.4.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server.js +11 -3
- package/package.json +1 -1
- package/test/interface/rtpproxymultinode.js +252 -24
- package/test/interface/rtpproxyserver.js +12 -12
- package/test/mock/mocknode.js +74 -49
package/lib/server.js
CHANGED
|
@@ -12,6 +12,7 @@ const message = require( "./message" )
|
|
|
12
12
|
* @typedef { object } nodehost
|
|
13
13
|
* @property { number } port
|
|
14
14
|
* @property { string } host
|
|
15
|
+
* @property { string } [ instance ]
|
|
15
16
|
*/
|
|
16
17
|
|
|
17
18
|
const nodeconnectiontype = { "listen": 1, "connect": 2 }
|
|
@@ -221,7 +222,7 @@ class channel {
|
|
|
221
222
|
|
|
222
223
|
newchannel.connection = {
|
|
223
224
|
sock: net.createConnection( connecttonode.port, connecttonode.host ),
|
|
224
|
-
"instance":
|
|
225
|
+
"instance": connecttonode.instance,
|
|
225
226
|
"rejectconnections": false,
|
|
226
227
|
"status": {},
|
|
227
228
|
"type": nodeconnectiontype.connect
|
|
@@ -243,6 +244,11 @@ class channel {
|
|
|
243
244
|
if ( receivedmsg.id === chnl.id ) chnl._on( receivedmsg )
|
|
244
245
|
}
|
|
245
246
|
|
|
247
|
+
/* correct the instance id - i.e. in a proxy enviroment (docker swarm) instance may differ */
|
|
248
|
+
if( receivedmsg && receivedmsg.status && receivedmsg.status.instance ) {
|
|
249
|
+
newchannel.connection.instance = receivedmsg.status.instance
|
|
250
|
+
}
|
|
251
|
+
|
|
246
252
|
if ( openresolve ) openresolve( newchannel )
|
|
247
253
|
} )
|
|
248
254
|
} )
|
|
@@ -271,7 +277,7 @@ class channel {
|
|
|
271
277
|
|
|
272
278
|
options.channel = "open"
|
|
273
279
|
|
|
274
|
-
const resolvepromise = new Promise( (
|
|
280
|
+
const resolvepromise = new Promise( ( resolve ) => {
|
|
275
281
|
|
|
276
282
|
const newchannel = new channel()
|
|
277
283
|
if( cb ) newchannel.em.on( "all", cb )
|
|
@@ -279,7 +285,7 @@ class channel {
|
|
|
279
285
|
newchannel.connection = this.connection
|
|
280
286
|
newchannel.channels = this.channels
|
|
281
287
|
newchannel.channels.push( newchannel )
|
|
282
|
-
newchannel.openresolve =
|
|
288
|
+
newchannel.openresolve = resolve
|
|
283
289
|
newchannel._write( options )
|
|
284
290
|
} )
|
|
285
291
|
|
|
@@ -979,6 +985,8 @@ class serverinterface {
|
|
|
979
985
|
*/
|
|
980
986
|
addnode( node ) {
|
|
981
987
|
if ( !serverinterface._s ) serverinterface._s = new rtpserver()
|
|
988
|
+
|
|
989
|
+
node.instance = uuidv4()
|
|
982
990
|
listeningnodes.push( node )
|
|
983
991
|
return serverinterface._s
|
|
984
992
|
}
|
package/package.json
CHANGED
|
@@ -42,15 +42,13 @@ describe( "rtpproxy multi node", function() {
|
|
|
42
42
|
const rtp1 = new mocknode()
|
|
43
43
|
const rtp2 = new mocknode()
|
|
44
44
|
|
|
45
|
-
const listenport = 32443
|
|
46
|
-
|
|
47
45
|
const rtpreceveivedmessages = []
|
|
48
46
|
let ouruuid = 0
|
|
49
47
|
|
|
50
|
-
rtp1.setmessagehandler( "open", ( msg ) => {
|
|
48
|
+
rtp1.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
51
49
|
msg.node = "rtp1"
|
|
52
50
|
rtpreceveivedmessages.push ( msg )
|
|
53
|
-
|
|
51
|
+
sendmessage( {
|
|
54
52
|
"action": "open",
|
|
55
53
|
"id": msg.id,
|
|
56
54
|
"uuid": ""+ouruuid++,
|
|
@@ -67,10 +65,10 @@ describe( "rtpproxy multi node", function() {
|
|
|
67
65
|
rtpreceveivedmessages.push ( msg )
|
|
68
66
|
} )
|
|
69
67
|
|
|
70
|
-
rtp1.setmessagehandler( "unmix", ( msg ) => {
|
|
68
|
+
rtp1.setmessagehandler( "unmix", ( msg, sendmessage ) => {
|
|
71
69
|
msg.node = "rtp1"
|
|
72
70
|
rtpreceveivedmessages.push ( msg )
|
|
73
|
-
|
|
71
|
+
sendmessage( {
|
|
74
72
|
"action": "unmix",
|
|
75
73
|
"id": msg.id,
|
|
76
74
|
"uuid": msg.uuid,
|
|
@@ -87,20 +85,20 @@ describe( "rtpproxy multi node", function() {
|
|
|
87
85
|
rtpreceveivedmessages.push ( msg )
|
|
88
86
|
} )
|
|
89
87
|
|
|
90
|
-
rtp1.setmessagehandler( "close", ( msg ) => {
|
|
88
|
+
rtp1.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
91
89
|
msg.node = "rtp1"
|
|
92
90
|
rtpreceveivedmessages.push ( msg )
|
|
93
|
-
|
|
91
|
+
sendmessage( {
|
|
94
92
|
"action": "close",
|
|
95
93
|
"id": msg.id,
|
|
96
94
|
"uuid": msg.uuid,
|
|
97
95
|
} )
|
|
98
96
|
} )
|
|
99
97
|
|
|
100
|
-
rtp2.setmessagehandler( "open", ( msg ) => {
|
|
98
|
+
rtp2.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
101
99
|
msg.node = "rtp2"
|
|
102
100
|
rtpreceveivedmessages.push( msg )
|
|
103
|
-
|
|
101
|
+
sendmessage( {
|
|
104
102
|
"action": "open",
|
|
105
103
|
"id": msg.id,
|
|
106
104
|
"uuid": ""+ouruuid++,
|
|
@@ -117,10 +115,10 @@ describe( "rtpproxy multi node", function() {
|
|
|
117
115
|
rtpreceveivedmessages.push( msg )
|
|
118
116
|
} )
|
|
119
117
|
|
|
120
|
-
rtp2.setmessagehandler( "unmix", ( msg ) => {
|
|
118
|
+
rtp2.setmessagehandler( "unmix", ( msg, sendmessage ) => {
|
|
121
119
|
msg.node = "rtp2"
|
|
122
120
|
rtpreceveivedmessages.push( msg )
|
|
123
|
-
|
|
121
|
+
sendmessage( {
|
|
124
122
|
"action": "unmix",
|
|
125
123
|
"id": msg.id,
|
|
126
124
|
"uuid": msg.uuid,
|
|
@@ -137,17 +135,18 @@ describe( "rtpproxy multi node", function() {
|
|
|
137
135
|
rtpreceveivedmessages.push( msg )
|
|
138
136
|
} )
|
|
139
137
|
|
|
140
|
-
rtp2.setmessagehandler( "close", ( msg ) => {
|
|
138
|
+
rtp2.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
141
139
|
msg.node = "rtp2"
|
|
142
140
|
rtpreceveivedmessages.push( msg )
|
|
143
141
|
|
|
144
|
-
|
|
142
|
+
sendmessage( {
|
|
145
143
|
"action": "close",
|
|
146
144
|
"uuid": msg.uuid,
|
|
147
145
|
"id": msg.id
|
|
148
146
|
} )
|
|
149
147
|
} )
|
|
150
148
|
|
|
149
|
+
const listenport = 32443
|
|
151
150
|
const p = await prtp.proxy.listen( undefined, "127.0.0.1", listenport )
|
|
152
151
|
await rtp1.connect( listenport )
|
|
153
152
|
await rtp2.connect( listenport )
|
|
@@ -168,10 +167,240 @@ describe( "rtpproxy multi node", function() {
|
|
|
168
167
|
expect( actual ).to.deep.equal( { "mix": 2, "open": 4, "unmix": 4, "close": 4, "remote": 2 } )
|
|
169
168
|
|
|
170
169
|
/* Clean up */
|
|
171
|
-
rtp1.destroy()
|
|
172
|
-
rtp2.destroy()
|
|
173
|
-
p.destroy()
|
|
170
|
+
await rtp1.destroy()
|
|
171
|
+
await rtp2.destroy()
|
|
172
|
+
await p.destroy()
|
|
173
|
+
|
|
174
|
+
} )
|
|
175
|
+
|
|
176
|
+
it( "2 node 2 channel simple mix rtp server listening on same node", async function() {
|
|
177
|
+
|
|
178
|
+
/*
|
|
179
|
+
We need to check that the nodes are maintained when using the same rtp server.
|
|
180
|
+
*/
|
|
181
|
+
|
|
182
|
+
const actual = { "mix": 0, "open": 0, "unmix": 0, "close": 0, "remote": 0 }
|
|
183
|
+
|
|
184
|
+
const rtp1 = new mocknode()
|
|
185
|
+
const rtp2 = new mocknode()
|
|
174
186
|
|
|
187
|
+
const rtpreceveivedmessages = []
|
|
188
|
+
let ouruuid = 0
|
|
189
|
+
|
|
190
|
+
rtp1.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
191
|
+
msg.node = "rtp1"
|
|
192
|
+
rtpreceveivedmessages.push ( msg )
|
|
193
|
+
sendmessage( {
|
|
194
|
+
"action": "open",
|
|
195
|
+
"id": msg.id,
|
|
196
|
+
"uuid": ""+ouruuid++,
|
|
197
|
+
"local": {
|
|
198
|
+
"port": 10002,
|
|
199
|
+
"address": "192.168.0.141"
|
|
200
|
+
},
|
|
201
|
+
"status": rtp1.ourstats
|
|
202
|
+
} )
|
|
203
|
+
} )
|
|
204
|
+
|
|
205
|
+
rtp1.setmessagehandler( "mix", ( msg ) => {
|
|
206
|
+
msg.node = "rtp1"
|
|
207
|
+
rtpreceveivedmessages.push ( msg )
|
|
208
|
+
} )
|
|
209
|
+
|
|
210
|
+
rtp1.setmessagehandler( "unmix", ( msg, sendmessage ) => {
|
|
211
|
+
msg.node = "rtp1"
|
|
212
|
+
rtpreceveivedmessages.push ( msg )
|
|
213
|
+
sendmessage( {
|
|
214
|
+
"action": "unmix",
|
|
215
|
+
"id": msg.id,
|
|
216
|
+
"uuid": msg.uuid,
|
|
217
|
+
"local": {
|
|
218
|
+
"port": 10002,
|
|
219
|
+
"address": "192.168.0.141"
|
|
220
|
+
},
|
|
221
|
+
"status": rtp1.ourstats
|
|
222
|
+
} )
|
|
223
|
+
} )
|
|
224
|
+
|
|
225
|
+
rtp1.setmessagehandler( "remote", ( msg ) => {
|
|
226
|
+
msg.node = "rtp1"
|
|
227
|
+
rtpreceveivedmessages.push ( msg )
|
|
228
|
+
} )
|
|
229
|
+
|
|
230
|
+
rtp1.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
231
|
+
msg.node = "rtp1"
|
|
232
|
+
rtpreceveivedmessages.push ( msg )
|
|
233
|
+
sendmessage( {
|
|
234
|
+
"action": "close",
|
|
235
|
+
"id": msg.id,
|
|
236
|
+
"uuid": msg.uuid,
|
|
237
|
+
} )
|
|
238
|
+
} )
|
|
239
|
+
|
|
240
|
+
rtp2.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
241
|
+
msg.node = "rtp2"
|
|
242
|
+
rtpreceveivedmessages.push( msg )
|
|
243
|
+
sendmessage( {
|
|
244
|
+
"action": "open",
|
|
245
|
+
"id": msg.id,
|
|
246
|
+
"uuid": ""+ouruuid++,
|
|
247
|
+
"local": {
|
|
248
|
+
"port": 10004,
|
|
249
|
+
"address": "192.168.0.141"
|
|
250
|
+
},
|
|
251
|
+
"status": rtp2.ourstats
|
|
252
|
+
} )
|
|
253
|
+
} )
|
|
254
|
+
|
|
255
|
+
rtp2.setmessagehandler( "mix", ( msg ) => {
|
|
256
|
+
msg.node = "rtp2"
|
|
257
|
+
rtpreceveivedmessages.push( msg )
|
|
258
|
+
} )
|
|
259
|
+
|
|
260
|
+
rtp2.setmessagehandler( "unmix", ( msg, sendmessage ) => {
|
|
261
|
+
msg.node = "rtp2"
|
|
262
|
+
rtpreceveivedmessages.push( msg )
|
|
263
|
+
sendmessage( {
|
|
264
|
+
"action": "unmix",
|
|
265
|
+
"id": msg.id,
|
|
266
|
+
"uuid": msg.uuid,
|
|
267
|
+
"local": {
|
|
268
|
+
"port": 10002,
|
|
269
|
+
"address": "192.168.0.141"
|
|
270
|
+
},
|
|
271
|
+
"status": rtp2.ourstats
|
|
272
|
+
} )
|
|
273
|
+
} )
|
|
274
|
+
|
|
275
|
+
rtp2.setmessagehandler( "remote", ( msg ) => {
|
|
276
|
+
msg.node = "rtp2"
|
|
277
|
+
rtpreceveivedmessages.push( msg )
|
|
278
|
+
} )
|
|
279
|
+
|
|
280
|
+
rtp2.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
281
|
+
msg.node = "rtp2"
|
|
282
|
+
rtpreceveivedmessages.push( msg )
|
|
283
|
+
|
|
284
|
+
sendmessage( {
|
|
285
|
+
"action": "close",
|
|
286
|
+
"uuid": msg.uuid,
|
|
287
|
+
"id": msg.id
|
|
288
|
+
} )
|
|
289
|
+
} )
|
|
290
|
+
|
|
291
|
+
const listenport1 = await rtp1.listen( 0 )
|
|
292
|
+
const listenport2 = await rtp2.listen( 0 )
|
|
293
|
+
prtp.proxy.addnode( { "host": "127.0.0.1", "port": listenport1 } )
|
|
294
|
+
prtp.proxy.addnode( { "host": "127.0.0.1", "port": listenport2 } )
|
|
295
|
+
|
|
296
|
+
const channel1 = await prtp.openchannel()
|
|
297
|
+
const channel2 = await channel1.openchannel()
|
|
298
|
+
await channel1.mix( channel2 )
|
|
299
|
+
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 1000 ) } )
|
|
300
|
+
channel1.unmix()
|
|
301
|
+
channel2.unmix()
|
|
302
|
+
|
|
303
|
+
channel1.close()
|
|
304
|
+
channel2.close()
|
|
305
|
+
|
|
306
|
+
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 10 ) } )
|
|
307
|
+
|
|
308
|
+
for ( const msg of rtpreceveivedmessages ) actual[ msg.channel ] += 1
|
|
309
|
+
expect( actual ).to.deep.equal( { "mix": 1, "open": 2, "unmix": 2, "close": 2, "remote": 0 } )
|
|
310
|
+
|
|
311
|
+
/* Clean up */
|
|
312
|
+
await rtp1.destroy()
|
|
313
|
+
await rtp2.destroy()
|
|
314
|
+
|
|
315
|
+
prtp.proxy.clearnodes()
|
|
316
|
+
|
|
317
|
+
} )
|
|
318
|
+
|
|
319
|
+
it( "2 node 2 channel connect to same rtp server not broken", async function() {
|
|
320
|
+
|
|
321
|
+
/*
|
|
322
|
+
We need to check that the nodes are maintained when using the same rtp server.
|
|
323
|
+
*/
|
|
324
|
+
|
|
325
|
+
const actual = { "mix": 0, "open": 0, "unmix": 0, "close": 0, "remote": 0 }
|
|
326
|
+
|
|
327
|
+
const rtp1 = new mocknode()
|
|
328
|
+
|
|
329
|
+
const rtpreceveivedmessages = []
|
|
330
|
+
let ouruuid = 0
|
|
331
|
+
|
|
332
|
+
rtp1.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
333
|
+
msg.node = "rtp1"
|
|
334
|
+
rtpreceveivedmessages.push ( msg )
|
|
335
|
+
sendmessage( {
|
|
336
|
+
"action": "open",
|
|
337
|
+
"id": msg.id,
|
|
338
|
+
"uuid": ""+ouruuid++,
|
|
339
|
+
"local": {
|
|
340
|
+
"port": 10002,
|
|
341
|
+
"address": "192.168.0.141"
|
|
342
|
+
},
|
|
343
|
+
"status": rtp1.ourstats
|
|
344
|
+
} )
|
|
345
|
+
} )
|
|
346
|
+
|
|
347
|
+
rtp1.setmessagehandler( "mix", ( msg ) => {
|
|
348
|
+
msg.node = "rtp1"
|
|
349
|
+
rtpreceveivedmessages.push ( msg )
|
|
350
|
+
} )
|
|
351
|
+
|
|
352
|
+
rtp1.setmessagehandler( "unmix", ( msg, sendmessage ) => {
|
|
353
|
+
msg.node = "rtp1"
|
|
354
|
+
rtpreceveivedmessages.push ( msg )
|
|
355
|
+
sendmessage( {
|
|
356
|
+
"action": "unmix",
|
|
357
|
+
"id": msg.id,
|
|
358
|
+
"uuid": msg.uuid,
|
|
359
|
+
"local": {
|
|
360
|
+
"port": 10002,
|
|
361
|
+
"address": "192.168.0.141"
|
|
362
|
+
},
|
|
363
|
+
"status": rtp1.ourstats
|
|
364
|
+
} )
|
|
365
|
+
} )
|
|
366
|
+
|
|
367
|
+
rtp1.setmessagehandler( "remote", ( msg ) => {
|
|
368
|
+
msg.node = "rtp1"
|
|
369
|
+
rtpreceveivedmessages.push ( msg )
|
|
370
|
+
} )
|
|
371
|
+
|
|
372
|
+
rtp1.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
373
|
+
msg.node = "rtp1"
|
|
374
|
+
rtpreceveivedmessages.push ( msg )
|
|
375
|
+
sendmessage( {
|
|
376
|
+
"action": "close",
|
|
377
|
+
"id": msg.id,
|
|
378
|
+
"uuid": msg.uuid,
|
|
379
|
+
} )
|
|
380
|
+
} )
|
|
381
|
+
|
|
382
|
+
const listenport = await rtp1.listen( 0 )
|
|
383
|
+
prtp.proxy.addnode( { "host": "127.0.0.1", "port": listenport } )
|
|
384
|
+
|
|
385
|
+
const channel1 = await prtp.openchannel()
|
|
386
|
+
const channel2 = await prtp.openchannel()
|
|
387
|
+
|
|
388
|
+
await channel1.mix( channel2 )
|
|
389
|
+
await new Promise( ( resolve ) => { setTimeout( resolve, 1000 ) } )
|
|
390
|
+
channel1.unmix()
|
|
391
|
+
channel2.unmix()
|
|
392
|
+
|
|
393
|
+
channel1.close()
|
|
394
|
+
channel2.close()
|
|
395
|
+
|
|
396
|
+
await new Promise( ( resolve ) => { setTimeout( () => resolve(), 10 ) } )
|
|
397
|
+
|
|
398
|
+
for ( const msg of rtpreceveivedmessages ) actual[ msg.channel ] += 1
|
|
399
|
+
expect( actual ).to.deep.equal( { "mix": 1, "open": 2, "unmix": 2, "close": 2, "remote": 0 } )
|
|
400
|
+
|
|
401
|
+
/* Clean up */
|
|
402
|
+
await rtp1.destroy()
|
|
403
|
+
prtp.proxy.clearnodes()
|
|
175
404
|
} )
|
|
176
405
|
|
|
177
406
|
it( "2 node 1 channel on one, 2 channels other", async function() {
|
|
@@ -352,10 +581,9 @@ describe( "rtpproxy multi node", function() {
|
|
|
352
581
|
expect( actual ).to.deep.equal( { "mix": 3, "open": 5, "unmix": 5, "close": 5, "remote": 2 } )
|
|
353
582
|
|
|
354
583
|
/* Clean up */
|
|
355
|
-
rtp1.destroy()
|
|
356
|
-
rtp2.destroy()
|
|
357
|
-
p.destroy()
|
|
358
|
-
|
|
584
|
+
await rtp1.destroy()
|
|
585
|
+
await rtp2.destroy()
|
|
586
|
+
await p.destroy()
|
|
359
587
|
|
|
360
588
|
} )
|
|
361
589
|
|
|
@@ -598,9 +826,9 @@ describe( "rtpproxy multi node", function() {
|
|
|
598
826
|
|
|
599
827
|
|
|
600
828
|
/* Clean up */
|
|
601
|
-
rtp1.destroy()
|
|
602
|
-
rtp2.destroy()
|
|
603
|
-
p.destroy()
|
|
829
|
+
await rtp1.destroy()
|
|
830
|
+
await rtp2.destroy()
|
|
831
|
+
await p.destroy()
|
|
604
832
|
|
|
605
833
|
} )
|
|
606
834
|
} )
|
|
@@ -469,9 +469,9 @@ describe( "rtpproxy server", function() {
|
|
|
469
469
|
|
|
470
470
|
await n.listen( ourport )
|
|
471
471
|
|
|
472
|
-
n.setmessagehandler( "open", ( msg ) => {
|
|
472
|
+
n.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
473
473
|
openreceived = true
|
|
474
|
-
|
|
474
|
+
sendmessage( {
|
|
475
475
|
"action": "open",
|
|
476
476
|
"id": msg.id,
|
|
477
477
|
"uuid": "7dfc35d9-eafe-4d8b-8880-c48f528ec152",
|
|
@@ -484,8 +484,8 @@ describe( "rtpproxy server", function() {
|
|
|
484
484
|
|
|
485
485
|
let closeresolv
|
|
486
486
|
const closepromise = new Promise( ( r ) => closeresolv = r )
|
|
487
|
-
n.setmessagehandler( "close", ( msg ) => {
|
|
488
|
-
|
|
487
|
+
n.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
488
|
+
sendmessage( {
|
|
489
489
|
"action": "close",
|
|
490
490
|
"uuid": msg.uuid,
|
|
491
491
|
"id": msg.id
|
|
@@ -528,9 +528,9 @@ describe( "rtpproxy server", function() {
|
|
|
528
528
|
await n.listen( n1port )
|
|
529
529
|
await n2.listen( n2port )
|
|
530
530
|
|
|
531
|
-
n.setmessagehandler( "open", ( msg ) => {
|
|
531
|
+
n.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
532
532
|
openreceived = true
|
|
533
|
-
|
|
533
|
+
sendmessage( {
|
|
534
534
|
"action": "open",
|
|
535
535
|
"id": msg.id,
|
|
536
536
|
"uuid": ""+ouruuid++,
|
|
@@ -541,9 +541,9 @@ describe( "rtpproxy server", function() {
|
|
|
541
541
|
} )
|
|
542
542
|
} )
|
|
543
543
|
|
|
544
|
-
n2.setmessagehandler( "open", ( msg ) => {
|
|
544
|
+
n2.setmessagehandler( "open", ( msg, sendmessage ) => {
|
|
545
545
|
openreceived = true
|
|
546
|
-
|
|
546
|
+
sendmessage( {
|
|
547
547
|
"action": "open",
|
|
548
548
|
"id": msg.id,
|
|
549
549
|
"uuid": ""+ouruuid++,
|
|
@@ -556,8 +556,8 @@ describe( "rtpproxy server", function() {
|
|
|
556
556
|
|
|
557
557
|
let closeresolv
|
|
558
558
|
const closepromise = new Promise( ( r ) => closeresolv = r )
|
|
559
|
-
n.setmessagehandler( "close", ( msg ) => {
|
|
560
|
-
|
|
559
|
+
n.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
560
|
+
sendmessage( {
|
|
561
561
|
"action": "close",
|
|
562
562
|
"uuid": msg.uuid,
|
|
563
563
|
"id": msg.id
|
|
@@ -565,8 +565,8 @@ describe( "rtpproxy server", function() {
|
|
|
565
565
|
closeresolv()
|
|
566
566
|
} )
|
|
567
567
|
|
|
568
|
-
n2.setmessagehandler( "close", ( msg ) => {
|
|
569
|
-
|
|
568
|
+
n2.setmessagehandler( "close", ( msg, sendmessage ) => {
|
|
569
|
+
sendmessage( {
|
|
570
570
|
"action": "close",
|
|
571
571
|
"uuid": msg.uuid,
|
|
572
572
|
"id": msg.id
|
package/test/mock/mocknode.js
CHANGED
|
@@ -8,7 +8,6 @@ const { v4: uuidv4 } = require( "uuid" )
|
|
|
8
8
|
class mocknode {
|
|
9
9
|
|
|
10
10
|
constructor() {
|
|
11
|
-
this.mp = message.newstate()
|
|
12
11
|
this.ourstats = prtp.stats()
|
|
13
12
|
this.messagehandlers = {}
|
|
14
13
|
this.recevievedmessagecount = 0
|
|
@@ -32,34 +31,74 @@ class mocknode {
|
|
|
32
31
|
*/
|
|
33
32
|
async connect( port = 9002, address = "127.0.0.1" ) {
|
|
34
33
|
|
|
35
|
-
const connectpromise = new Promise(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const connectpromise = new Promise( resolve => this._newconnectresolve = resolve )
|
|
35
|
+
const connection = net.createConnection( port, address, () => {
|
|
36
|
+
|
|
37
|
+
this.connection = connection
|
|
38
|
+
/* Pretend to be a node: our server will pass out new connections only after a
|
|
39
|
+
stats message has been sent and it must have an instance id */
|
|
40
|
+
const msg = {}
|
|
41
|
+
msg.status = this.ourstats
|
|
42
|
+
msg.status.instance = this.id
|
|
43
|
+
this.connection.write( message.createmessage( msg ) )
|
|
44
|
+
|
|
45
|
+
this._newconnectresolve()
|
|
46
|
+
|
|
47
|
+
const mp = message.newstate()
|
|
48
|
+
connection.on( "data", ( data ) => {
|
|
49
|
+
message.parsemessage( mp, data, ( receivedmsg ) => {
|
|
50
|
+
this.recevievedmessagecount++
|
|
51
|
+
expect( receivedmsg ).to.have.property( "channel" ).that.is.a( "string" )
|
|
52
|
+
expect( receivedmsg ).to.have.property( "id" ).that.is.a( "string" )
|
|
53
|
+
this.messagehandlers[ receivedmsg.channel ]( receivedmsg, ( senddata ) => {
|
|
54
|
+
senddata.status = this.ourstats
|
|
55
|
+
connection.write( message.createmessage( senddata ) )
|
|
56
|
+
} )
|
|
57
|
+
} )
|
|
58
|
+
} )
|
|
59
|
+
} )
|
|
39
60
|
|
|
40
61
|
await connectpromise
|
|
41
62
|
}
|
|
42
63
|
|
|
43
64
|
/**
|
|
44
65
|
* Listen for connections to this mock node.
|
|
45
|
-
* @param { number } [ port ] - default 9002
|
|
66
|
+
* @param { number } [ port ] - default 9002, if 0 binnd to random
|
|
46
67
|
* @return { Promise }
|
|
47
68
|
*/
|
|
48
|
-
listen( port = 9002, host = "127.0.0.1" ) {
|
|
69
|
+
async listen( port = 9002, host = "127.0.0.1" ) {
|
|
49
70
|
let listenresolve
|
|
50
71
|
const listenpromise = new Promise( ( r ) => listenresolve = r )
|
|
51
72
|
this.port = port
|
|
52
73
|
this.host = host
|
|
53
74
|
this.server = net.createServer( ( connection ) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
75
|
+
connection.setKeepAlive( true )
|
|
76
|
+
const mp = message.newstate()
|
|
77
|
+
connection.on( "data", ( data ) => {
|
|
78
|
+
message.parsemessage( mp, data, ( receivedmsg ) => {
|
|
79
|
+
this.recevievedmessagecount++
|
|
80
|
+
expect( receivedmsg ).to.have.property( "channel" ).that.is.a( "string" )
|
|
81
|
+
expect( receivedmsg ).to.have.property( "id" ).that.is.a( "string" )
|
|
82
|
+
this.messagehandlers[ receivedmsg.channel ]( receivedmsg, ( senddata ) => {
|
|
83
|
+
senddata.status = this.ourstats
|
|
84
|
+
connection.write( message.createmessage( senddata ) )
|
|
85
|
+
} )
|
|
86
|
+
} )
|
|
87
|
+
} )
|
|
57
88
|
} )
|
|
58
89
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
90
|
+
if( 0 == port ) {
|
|
91
|
+
this.server.listen( () => {
|
|
92
|
+
// Port does exist?
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
this.port = this.server.address().port
|
|
95
|
+
listenresolve( this.port )
|
|
96
|
+
} )
|
|
97
|
+
} else {
|
|
98
|
+
this.server.listen( port, host, listenresolve )
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return await listenpromise
|
|
63
102
|
}
|
|
64
103
|
|
|
65
104
|
/**
|
|
@@ -73,45 +112,31 @@ class mocknode {
|
|
|
73
112
|
}
|
|
74
113
|
|
|
75
114
|
/**
|
|
76
|
-
* @return { void }
|
|
115
|
+
* @return { Promise< void > }
|
|
77
116
|
*/
|
|
78
|
-
destroy() {
|
|
79
|
-
if( this.connection )
|
|
80
|
-
|
|
117
|
+
async destroy() {
|
|
118
|
+
if( this.connection ) {
|
|
119
|
+
const p = new Promise( resolve => {
|
|
120
|
+
this.connection.on( "close", resolve )
|
|
121
|
+
} )
|
|
122
|
+
|
|
123
|
+
this.connection.destroy()
|
|
124
|
+
await p
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if( this.server ) {
|
|
128
|
+
const p = new Promise( resolve => {
|
|
129
|
+
this.server.on( "close", resolve )
|
|
130
|
+
} )
|
|
131
|
+
this.server.close()
|
|
132
|
+
await p
|
|
133
|
+
}
|
|
81
134
|
}
|
|
82
135
|
|
|
83
136
|
/**
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
|
|
87
|
-
_onsocketconnect() {
|
|
88
|
-
|
|
89
|
-
/* Pretend to be a node: our server will pass out new connections only after a
|
|
90
|
-
stats message has been sent and it must have an instance id */
|
|
91
|
-
const msg = {}
|
|
92
|
-
msg.status = this.ourstats
|
|
93
|
-
msg.status.instance = this.id
|
|
94
|
-
this.connection.write( message.createmessage( msg ) )
|
|
95
|
-
|
|
96
|
-
this._newconnectresolve()
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* @private
|
|
101
|
-
* @param { Buffer } data
|
|
102
|
-
* @return { void }
|
|
103
|
-
*/
|
|
104
|
-
_onsocketdata( data ) {
|
|
105
|
-
message.parsemessage( this.mp, data, ( receivedmsg ) => {
|
|
106
|
-
this.recevievedmessagecount++
|
|
107
|
-
expect( receivedmsg ).to.have.property( "channel" ).that.is.a( "string" )
|
|
108
|
-
expect( receivedmsg ).to.have.property( "id" ).that.is.a( "string" )
|
|
109
|
-
this.messagehandlers[ receivedmsg.channel ]( receivedmsg )
|
|
110
|
-
} )
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
*
|
|
137
|
+
* Will send a messag to the latst connection. If you expect multiple
|
|
138
|
+
* connections for a node then use the senddata function passed into the
|
|
139
|
+
* on data event.
|
|
115
140
|
* @param { object } obj
|
|
116
141
|
* @return { void }
|
|
117
142
|
*/
|