sip-lab 1.29.0 → 1.31.0

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.
@@ -128,11 +128,9 @@ async function test() {
128
128
  {
129
129
  type: 'audio',
130
130
  local: {
131
- port: 10000,
132
131
  mode: 'recvonly'
133
132
  },
134
133
  remote: {
135
- port: 10002,
136
134
  mode: 'sendonly'
137
135
  }
138
136
  }
@@ -155,11 +153,9 @@ async function test() {
155
153
  {
156
154
  type: 'audio',
157
155
  local: {
158
- port: 10002,
159
156
  mode: 'sendonly'
160
157
  },
161
158
  remote: {
162
- port: 10000,
163
159
  mode: 'recvonly'
164
160
  }
165
161
  }
@@ -273,11 +269,9 @@ async function test() {
273
269
  {
274
270
  type: 'audio',
275
271
  local: {
276
- port: 10000,
277
272
  mode: 'recvonly'
278
273
  },
279
274
  remote: {
280
- port: 10002,
281
275
  mode: 'sendonly'
282
276
  }
283
277
  }
@@ -300,11 +294,9 @@ async function test() {
300
294
  {
301
295
  type: 'audio',
302
296
  local: {
303
- port: 10002,
304
297
  mode: 'sendonly'
305
298
  },
306
299
  remote: {
307
- port: 10000,
308
300
  mode: 'recvonly'
309
301
  }
310
302
  }
@@ -359,11 +351,9 @@ async function test() {
359
351
  {
360
352
  type: 'audio',
361
353
  local: {
362
- port: 10000,
363
354
  mode: 'recvonly'
364
355
  },
365
356
  remote: {
366
- port: 10002,
367
357
  mode: 'sendonly'
368
358
  }
369
359
  }
@@ -386,11 +376,9 @@ async function test() {
386
376
  {
387
377
  type: 'audio',
388
378
  local: {
389
- port: 10002,
390
379
  mode: 'sendonly'
391
380
  },
392
381
  remote: {
393
- port: 10000,
394
382
  mode: 'recvonly'
395
383
  }
396
384
  }
@@ -0,0 +1,171 @@
1
+ var sip = require ('../index.js')
2
+ var Zeq = require('@mayama/zeq')
3
+ var z = new Zeq()
4
+ var m = require('data-matching')
5
+ var sip_msg = require('sip-matching')
6
+ var sdp = require('sdp-matching')
7
+
8
+ async function test() {
9
+ //sip.set_log_level(9)
10
+
11
+ //sip.set_log_level(6)
12
+ sip.dtmf_aggregation_on(500)
13
+
14
+ z.trap_events(sip.event_source, 'event', (evt) => {
15
+ var e = evt.args[0]
16
+ return e
17
+ })
18
+
19
+ //sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
20
+ sip.set_codecs("pcma/8000/1:128")
21
+
22
+ console.log(sip.start((data) => { console.log(data)} ))
23
+
24
+ t1 = sip.transport.create({address: "127.0.0.1", type: 'udp'})
25
+ t2 = sip.transport.create({address: "127.0.0.1", type: 'udp'})
26
+
27
+ console.log("t1", t1)
28
+ console.log("t2", t2)
29
+
30
+ oc = sip.call.create(t1.id, {from_uri: 'sip:alice@test.com', to_uri: `sip:bob@${t2.address}:${t2.port}`})
31
+
32
+ await z.wait([
33
+ {
34
+ event: "incoming_call",
35
+ call_id: m.collect("call_id"),
36
+ },
37
+ {
38
+ event: 'response',
39
+ call_id: oc.id,
40
+ method: 'INVITE',
41
+ msg: sip_msg({
42
+ $rs: '100',
43
+ $rr: 'Trying',
44
+ '$hdr(call-id)': m.collect('sip_call_id'),
45
+ }),
46
+ },
47
+ ], 1000)
48
+
49
+ ic = {
50
+ id: z.store.call_id,
51
+ sip_call_id: z.store.sip_call_id,
52
+ }
53
+
54
+ sip.call.respond(ic.id, {code: 200, reason: 'OK'})
55
+
56
+ await z.wait([
57
+ {
58
+ event: 'response',
59
+ call_id: oc.id,
60
+ method: 'INVITE',
61
+ msg: sip_msg({
62
+ $rs: '200',
63
+ $rr: 'OK',
64
+ }),
65
+ },
66
+ {
67
+ event: 'media_update',
68
+ call_id: oc.id,
69
+ status: 'ok',
70
+ media: [
71
+ {
72
+ type: 'audio',
73
+ local: {
74
+ port: 10000,
75
+ mode: 'sendrecv'
76
+ },
77
+ remote: {
78
+ port: 10002,
79
+ mode: 'sendrecv'
80
+ },
81
+ },
82
+ ],
83
+ },
84
+ {
85
+ event: 'media_update',
86
+ call_id: ic.id,
87
+ status: 'ok',
88
+ media: [
89
+ {
90
+ type: 'audio',
91
+ local: {
92
+ port: 10002,
93
+ mode: 'sendrecv'
94
+ },
95
+ remote: {
96
+ port: 10000,
97
+ mode: 'sendrecv'
98
+ },
99
+ }
100
+ ],
101
+ },
102
+ ], 1000)
103
+
104
+ sip.call.start_record_wav(oc.id, {file: 'oc.wav'})
105
+ sip.call.start_record_wav(ic.id, {file: 'ic.wav'})
106
+
107
+ await z.sleep(100)
108
+
109
+ sip.call.start_bfsk_detection(oc.id, {freq_zero: 880, freq_one: 1280})
110
+ //sip.call.start_bfsk_detection(ic.id, {freq_zero: 880, freq_one: 1280})
111
+
112
+ oc_bits = '1010'
113
+ ic_bits = '1100'
114
+
115
+ sip.call.send_bfsk(ic.id, {bits: ic_bits, freq_zero: 880, freq_one: 1280})
116
+ //sip.call.send_bfsk(oc.id, {bits: oc_bits, freq_zero: 880, freq_one: 1280})
117
+
118
+ await z.wait([
119
+ {
120
+ event: 'bfsk',
121
+ call_id: ic.id,
122
+ bits: oc_bits,
123
+ media_id: 0
124
+ },
125
+ {
126
+ event: 'bfsk',
127
+ call_id: oc.id,
128
+ bits: ic_bits,
129
+ media_id: 0
130
+ },
131
+ ], 10000)
132
+
133
+ await z.sleep(1000)
134
+
135
+ sip.call.stop_record_wav(oc.id)
136
+ sip.call.stop_record_wav(ic.id)
137
+
138
+ sip.call.terminate(oc.id)
139
+
140
+ await z.wait([
141
+ {
142
+ event: 'call_ended',
143
+ call_id: oc.id,
144
+ },
145
+ {
146
+ event: 'call_ended',
147
+ call_id: ic.id,
148
+ },
149
+ {
150
+ event: 'response',
151
+ call_id: oc.id,
152
+ method: 'BYE',
153
+ msg: sip_msg({
154
+ $rs: '200',
155
+ $rr: 'OK',
156
+ }),
157
+ },
158
+ ], 1000)
159
+
160
+ console.log("Success")
161
+
162
+ sip.stop()
163
+ }
164
+
165
+
166
+ test()
167
+ .catch(e => {
168
+ console.error(e)
169
+ process.exit(1)
170
+ })
171
+
@@ -0,0 +1,268 @@
1
+ const sip = require ('../index.js')
2
+ const Zeq = require('@mayama/zeq')
3
+ const m = require('data-matching')
4
+ const sip_msg = require('sip-matching')
5
+ const uuid = require('uuid')
6
+
7
+ // here we create our Zeq instance
8
+ var z = new Zeq()
9
+
10
+
11
+ async function test() {
12
+ z.trap_events(sip.event_source, 'event', (evt) => {
13
+ var e = evt.args[0]
14
+ return e
15
+ })
16
+
17
+ sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
18
+
19
+ console.log(sip.start((data) => { console.log(data)} ))
20
+
21
+ const t1 = sip.transport.create({address: "127.0.0.1"})
22
+ const t2 = sip.transport.create({address: "127.0.0.1"})
23
+
24
+ console.log("t1", t1)
25
+ console.log("t2", t2)
26
+
27
+ const call_id = uuid.v4()
28
+
29
+ var oc = sip.call.create(t1.id, {
30
+ from_uri: 'sip:alice@test.com',
31
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
32
+ headers: {
33
+ 'Call-ID': call_id,
34
+ 'Supported': 'timer',
35
+ 'Min-SE': '180',
36
+ 'Session-Expires': '180',
37
+ },
38
+ })
39
+
40
+ await z.wait([
41
+ {
42
+ event: "incoming_call",
43
+ call_id: m.collect("call_id"),
44
+ transport_id: t2.id,
45
+ msg: sip_msg({
46
+ $rU: 'bob',
47
+ $fU: 'alice',
48
+ $tU: 'bob',
49
+ $fd: 'test.com',
50
+ $ci: call_id,
51
+ hdr_supported: 'timer',
52
+ hdr_min_se: '180',
53
+ hdr_session_expires: '180',
54
+ })
55
+ },
56
+ {
57
+ event: 'response',
58
+ call_id: oc.id,
59
+ method: 'INVITE',
60
+ msg: sip_msg({
61
+ $rs: '100',
62
+ $rr: 'Trying',
63
+ }),
64
+ },
65
+ ], 1000)
66
+
67
+
68
+ var ic = {
69
+ id: z.store.call_id,
70
+ sip_call_id: z.store.sip_call_id,
71
+ }
72
+
73
+ sip.call.respond(ic.id, {
74
+ code: 422,
75
+ reason: 'Session Timer Too Small',
76
+ headers: {
77
+ 'Supported': 'timer',
78
+ 'Min-SE': '300',
79
+ 'Session-Expires': '300;refresher=uac',
80
+ },
81
+ })
82
+
83
+ await z.wait([
84
+ {
85
+ event: 'call_ended',
86
+ call_id: ic.id,
87
+ },
88
+ {
89
+ event: 'call_ended',
90
+ call_id: oc.id,
91
+ },
92
+ {
93
+ event: 'response',
94
+ call_id: 0,
95
+ method: 'INVITE',
96
+ msg: sip_msg({
97
+ $rs: '422',
98
+ $rr: 'Session Timer Too Small',
99
+ hdr_supported: 'timer',
100
+ hdr_min_se: '300',
101
+ hdr_session_expires: '300;refresher=uac',
102
+ }),
103
+ },
104
+ ], 1000)
105
+
106
+ oc = sip.call.create(t1.id, {
107
+ from_uri: 'sip:alice@test.com',
108
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
109
+ headers: {
110
+ 'Call-ID': call_id,
111
+ 'Supported': 'timer',
112
+ 'Min-SE': '300',
113
+ 'Session-Expires': '300',
114
+ },
115
+ })
116
+
117
+ delete z.store.call_id
118
+
119
+ await z.wait([
120
+ {
121
+ event: "incoming_call",
122
+ call_id: m.collect("call_id"),
123
+ transport_id: t2.id,
124
+ msg: sip_msg({
125
+ $rU: 'bob',
126
+ $fU: 'alice',
127
+ $tU: 'bob',
128
+ $fd: 'test.com',
129
+ $ci: call_id,
130
+ hdr_supported: 'timer',
131
+ hdr_min_se: '300',
132
+ hdr_session_expires: '300',
133
+ })
134
+ },
135
+ {
136
+ event: 'response',
137
+ call_id: oc.id,
138
+ method: 'INVITE',
139
+ msg: sip_msg({
140
+ $rs: '100',
141
+ $rr: 'Trying',
142
+ }),
143
+ },
144
+ ], 1000)
145
+
146
+ ic = {
147
+ id: z.store.call_id,
148
+ sip_call_id: z.store.sip_call_id,
149
+ }
150
+
151
+ sip.call.respond(ic.id, {
152
+ code: 200,
153
+ reason: 'OK',
154
+ headers: {
155
+ 'Supported': 'timer',
156
+ 'Min-SE': '300',
157
+ 'Session-Expires': '300;refresher=uac',
158
+ },
159
+ })
160
+
161
+ await z.wait([
162
+ {
163
+ event: 'response',
164
+ call_id: oc.id,
165
+ method: 'INVITE',
166
+ msg: sip_msg({
167
+ $rs: '200',
168
+ $rr: 'OK',
169
+ hdr_supported: 'timer',
170
+ hdr_min_se: '300',
171
+ hdr_session_expires: '300;refresher=uac',
172
+ }),
173
+ },
174
+ {
175
+ event: 'media_update',
176
+ call_id: oc.id,
177
+ status: 'ok',
178
+ },
179
+ {
180
+ event: 'media_update',
181
+ call_id: ic.id,
182
+ status: 'ok',
183
+ },
184
+ ], 1000)
185
+
186
+ await z.sleep(1000)
187
+
188
+ sip.call.update(oc.id, {
189
+ headers: {
190
+ 'Supported': 'timer',
191
+ 'Min-SE': '300',
192
+ 'Session-Expires': '300',
193
+ },
194
+ })
195
+
196
+ await z.wait([
197
+ {
198
+ event: 'request',
199
+ call_id: ic.id,
200
+ msg: sip_msg({
201
+ $rm: 'UPDATE',
202
+ hdr_supported: 'timer',
203
+ hdr_min_se: '300',
204
+ hdr_session_expires: '300',
205
+ }),
206
+ },
207
+ ], 1000)
208
+
209
+ sip.call.respond(ic.id, {
210
+ code: 200,
211
+ reason: 'OK',
212
+ headers: {
213
+ 'Supported': 'timer',
214
+ 'Min-SE': '300',
215
+ 'Session-Expires': '300;refresher=uac',
216
+ },
217
+ })
218
+
219
+ await z.wait([
220
+ {
221
+ event: 'response',
222
+ call_id: oc.id,
223
+ msg: sip_msg({
224
+ $rm: 'UPDATE',
225
+ $rs: '200',
226
+ $rr: 'OK',
227
+ hdr_supported: 'timer',
228
+ hdr_min_se: '300',
229
+ hdr_session_expires: '300;refresher=uac',
230
+ }),
231
+ },
232
+ ], 1000)
233
+
234
+ sip.call.terminate(oc.id)
235
+
236
+ // and wait for termination events
237
+ await z.wait([
238
+ {
239
+ event: 'response',
240
+ call_id: oc.id,
241
+ method: 'BYE',
242
+ msg: sip_msg({
243
+ $rs: '200',
244
+ $rr: 'OK',
245
+ }),
246
+ },
247
+ {
248
+ event: 'call_ended',
249
+ call_id: oc.id,
250
+ },
251
+ {
252
+ event: 'call_ended',
253
+ call_id: ic.id,
254
+ },
255
+ ], 1000)
256
+
257
+ console.log("Success")
258
+
259
+ sip.stop()
260
+ }
261
+
262
+
263
+ test()
264
+ .catch(e => {
265
+ console.error(e)
266
+ process.exit(1)
267
+ })
268
+