sip-lab 1.40.1 → 1.41.2

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/DEV.md CHANGED
@@ -8,10 +8,11 @@ Basic tasks for development:
8
8
  ```
9
9
  sudo apt install build-essential automake autoconf libtool libspeex-dev libopus-dev libsdl2-dev libavdevice-dev libswscale-dev libv4l-dev libopencore-amrnb-dev libopencore-amrwb-dev libvo-amrwbenc-dev libvo-amrwbenc-dev libboost-dev libtiff-dev libpcap-dev libssl-dev uuid-dev cmake flite-dev
10
10
 
11
+ nvm use v16.13.1 # other versions might work.
11
12
  npm install
12
13
  ```
13
14
 
14
- Thne confirm it is working:
15
+ Then confirm it is working:
15
16
  ```
16
17
  node samples/simple.js
17
18
  ```
@@ -44,15 +45,8 @@ npm install
44
45
  Then perform code changes and tests. When you are satisfied with them, update build_deps.sh with the new commit IDs.
45
46
 
46
47
  #### prebuild binaries
47
- Previously we would do:
48
48
 
49
- ```
50
- nvm use v16.13.1 # if we try with v17 it will fail to build for -t 15.0.0
51
- npx prebuildify --strip -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 19.0.0 20.0.0 21.0.0
52
- ```
53
- However the above will build the addon to run on the current OS.
54
-
55
- Instead we will force the build on debian11 (using docker) using prebuildify-cross. So do this instead:
49
+ We will use prebuildify-cross to generate the images for different architectures.
56
50
 
57
51
  Make sure you have the docker image built (the image must be rebuilt whenever we update build_deps.sh)
58
52
 
@@ -73,10 +67,10 @@ If it fails due to proxy problems, check if you have proxy configured in ~/.dock
73
67
 
74
68
  ```
75
69
 
76
- After the image is built you can pass them to prebuildify-cross:
70
+ The to prebuild the addon versions:
77
71
  ```
78
72
  nvm use v16.13.1
79
- npx prebuildify-cross -i mayamatakeshi/sip-lab-debian11:latest -t 15.0.0 -t 16.0.0 -t 17.0.0 -t 18.0.0 -t 19.0.0 -t 20.0.0 -t 21.0.0 --strip
73
+ ./gen_prebuilds.sh
80
74
  ```
81
75
  Obs: however the above will fail if you are behind proxy (solution pending).
82
76
 
@@ -187,5 +181,19 @@ Then do the actual publish:
187
181
  ```
188
182
  npm publish
189
183
  ```
184
+ If you get something like
185
+ ```
186
+ npm timing command:publish Completed in 8775ms
187
+ npm ERR! code E404
188
+ npm ERR! 404 Not Found - PUT https://registry.npmjs.org/sip-lab - Not found
189
+ npm ERR! 404
190
+ npm ERR! 404 'sip-lab@1.41.0' is not in this registry.
191
+
192
+ ```
193
+ it means you are not logged in.
194
+ So first do:
195
+ ```
196
+ npm login
197
+ ```
190
198
 
191
199
 
package/README.md CHANGED
@@ -11,31 +11,24 @@ See [Documentation](https://github.com/MayamaTakeshi/sip-lab/blob/master/DOC.md)
11
11
 
12
12
  ## Installation
13
13
 
14
- The npm package is built for Debian 11 and this is the recommended distro.
15
-
16
- You can use other debian/ubuntu version but they will require a build of dependencies that will take time (something like 7 minutes but this was measured on my slow PC).
14
+ The npm package is built for Ubuntu/Debian and might work with other linux distros.
17
15
 
18
16
  First install apt packages:
19
17
 
20
18
  ```
21
- apt install build-essential automake autoconf libtool libspeex-dev libopus-dev libsdl2-dev libavdevice-dev libswscale-dev libv4l-dev libopencore-amrnb-dev libopencore-amrwb-dev libvo-amrwbenc-dev libvo-amrwbenc-dev libboost-dev libtiff-dev libpcap-dev libssl-dev uuid-dev flite-dev cmake git wget
19
+ apt install build-essential automake autoconf libtool libspeex-dev libopus-dev libsdl2-dev libavdevice-dev libswscale-dev libv4l-dev libopencore-amrnb-dev libopencore-amrwb-dev libvo-amrwbenc-dev libvo-amrwbenc-dev libboost-dev libtiff-dev libpcap-dev libssl-dev uuid-dev flite-dev cmake git wget bc
22
20
 
23
21
  ```
22
+ Obs: in ubuntu you might also need to install libssl1.1
24
23
 
25
- Then switch to node v19, switch to your node project folder and install sip-lab:
26
-
24
+ Then:
27
25
  ```
28
- nvm install 19
29
- nvm use 19
30
- cd YOUR_NODE_PROJECT_FOLDER
31
26
  npm i sip-lab
32
27
  ```
33
- Obs: once you install sip-lab, you can switch to other node versions like v20, v21.
34
-
35
-
36
28
  Then run some sample script from subfolder samples:
37
29
  ```
38
- node node_modules/sip-lab/samples/simple.js
30
+ cd node_modules/sip-lab
31
+ node ./samples/simple.js
39
32
  ```
40
33
 
41
34
  The above script has detailed comments.
package/binding.gyp CHANGED
@@ -25,13 +25,14 @@
25
25
  ],
26
26
  'conditions': [
27
27
  [ 'OS!="win"', {
28
- 'cflags': ['-g', '-DPJ_HAS_SSL_SOCK=1'],
28
+ 'cflags': ['-g', '-DPJ_HAS_SSL_SOCK=1', '-DNAPI_VERSION=6'],
29
29
  'cflags_cc': [
30
30
  '-g',
31
31
  '-DPJ_HAS_SSL_SOCK=1',
32
32
  '-fexceptions',
33
33
  '-Wno-maybe-uninitialized',
34
34
  '-fPIC',
35
+ '-DNAPI_VERSION=6',
35
36
  ],
36
37
  'ldflags_cc': [
37
38
  '-all-static',
package/index.js CHANGED
@@ -74,7 +74,7 @@ addon.call = {
74
74
  stop_inband_dtmf_detection: (c_id, params) => { return addon.call_stop_inband_dtmf_detection(c_id, JSON.stringify(params ? params : {})) },
75
75
 
76
76
  start_bfsk_detection: (c_id, params) => { return addon.call_start_bfsk_detection(c_id, JSON.stringify(params ? params : {})) },
77
- stop_bfsk_dtmf_detection: (c_id, params) => { return addon.call_stop_bfsk_detection(c_id, JSON.stringify(params ? params : {})) },
77
+ stop_bfsk_detection: (c_id, params) => { return addon.call_stop_bfsk_detection(c_id, JSON.stringify(params ? params : {})) },
78
78
 
79
79
  start_speech_recog: (c_id, params) => {
80
80
  var ps = {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sip-lab",
3
- "version": "1.40.1",
3
+ "version": "1.41.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "engines": {
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "devDependencies": {
36
36
  "prebuildify": "^5.0.1",
37
- "prebuildify-cross": "github:MayamaTakeshi/prebuildify-cross#use_existing_images"
37
+ "prebuildify-cross": "github:MayamaTakeshi/prebuildify-cross#820133ce7fdbc92525b5b0d7149ed6497860a11b"
38
38
  },
39
39
  "files": [
40
40
  "index.js",
@@ -49,5 +49,10 @@
49
49
  "prebuilds",
50
50
  "pocketsphinx",
51
51
  "runtests"
52
- ]
52
+ ],
53
+ "binary": {
54
+ "napi_versions": [
55
+ 6
56
+ ]
57
+ }
53
58
  }
package/runtests CHANGED
@@ -45,13 +45,24 @@ while getopts "gef:a:h" o; do
45
45
  done
46
46
  shift $((OPTIND-1))
47
47
 
48
- successful_tests=()
48
+ passed_on_first_try=()
49
+ passed_on_retry=()
49
50
  failed_tests=()
50
51
 
51
- function output_successful_tests() {
52
- if [ ${#successful_tests[@]} -ne 0 ]; then
53
- echo "Successful tests:"
54
- for t in "${successful_tests[@]}"
52
+ function output_passed_on_first_try_tests() {
53
+ if [ ${#passed_on_first_try[@]} -ne 0 ]; then
54
+ echo "Passed on first try:"
55
+ for t in "${passed_on_first_try[@]}"
56
+ do
57
+ echo " - $t"
58
+ done
59
+ fi
60
+ }
61
+
62
+ function output_passed_on_retry_tests() {
63
+ if [ ${#passed_on_retry[@]} -ne 0 ]; then
64
+ echo "Passed on retry (flaky tests):"
65
+ for t in "${passed_on_retry[@]}"
55
66
  do
56
67
  echo " - $t"
57
68
  done
@@ -127,11 +138,12 @@ do
127
138
  formatted_duration=$(printf "%.2f seconds" $duration)
128
139
 
129
140
  success_message="$i: duration=$formatted_duration"
130
- # The variable c comes from the retry loop
131
141
  if [[ $c -gt 1 ]]; then
132
142
  success_message+=" (succeeded after $c attempts)"
143
+ passed_on_retry+=("$success_message")
144
+ else
145
+ passed_on_first_try+=("$success_message")
133
146
  fi
134
- successful_tests+=("$success_message")
135
147
  fi
136
148
  echo
137
149
  done
@@ -139,7 +151,9 @@ done
139
151
  echo
140
152
 
141
153
  if [ ${#failed_tests[@]} -ne 0 ]; then
142
- output_successful_tests
154
+ output_passed_on_first_try_tests
155
+ echo
156
+ output_passed_on_retry_tests
143
157
  echo
144
158
  output_failed_tests
145
159
  echo
@@ -149,7 +163,9 @@ if [ ${#failed_tests[@]} -ne 0 ]; then
149
163
  else
150
164
  echo "Success. All tests passed"
151
165
  echo
152
- output_successful_tests
166
+ output_passed_on_first_try_tests
167
+ echo
168
+ output_passed_on_retry_tests
153
169
  echo
154
170
  echo "Everything OK"
155
171
  echo
@@ -0,0 +1,278 @@
1
+ // This test creates 2 UDP SIP endpoints, makes a call between them and disconeects.
2
+
3
+ const sip = require ('../index.js')
4
+ const Zeq = require('@mayama/zeq')
5
+ const m = require('data-matching')
6
+ const sip_msg = require('sip-matching')
7
+
8
+ const crypto = require('crypto');
9
+
10
+ function generateDigestResponse({
11
+ username, password, realm, nonce, uri,
12
+ method = 'INVITE', qop = 'auth', nc = '00000001',
13
+ cnonce
14
+ }) {
15
+ const md5 = (str) => crypto.createHash('md5').update(str).digest('hex');
16
+
17
+ // Fallback to random ONLY if one isn't provided (for tests)
18
+ const finalCnonce = cnonce || crypto.randomBytes(8).toString('hex');
19
+
20
+ const ha1 = md5(`${username}:${realm}:${password}`);
21
+ const ha2 = md5(`${method}:${uri}`);
22
+ const response = md5(`${ha1}:${nonce}:${nc}:${finalCnonce}:${qop}:${ha2}`);
23
+
24
+ return { response, cnonce: finalCnonce };
25
+ }
26
+
27
+ // here we create our Zeq instance
28
+ var z = new Zeq()
29
+
30
+
31
+ async function test() {
32
+ // here we set DTMF aggregation mode to 500 ms
33
+ sip.dtmf_aggregation_on(500)
34
+
35
+ // here we set our Zeq instance to trap events generated by sip-lab event_source
36
+ z.trap_events(sip.event_source, 'event', (evt) => {
37
+ var e = evt.args[0]
38
+ return e
39
+ })
40
+
41
+ sip.set_codecs("pcmu/8000/1:128,pcma/8000/1:128,gsm/8000/1:128")
42
+
43
+ // here we start sip-lab
44
+ console.log(sip.start((data) => { console.log(data)} ))
45
+
46
+ // Here we create the SIP endpoints (transports).
47
+ // Since we don't specify the port, an available port will be allocated.
48
+ // Since we don't specify the type ('udp' or 'tcp' or 'tls'), 'udp' will be used by default.
49
+ const t1 = sip.transport.create({address: "127.0.0.1"})
50
+ const t2 = sip.transport.create({address: "127.0.0.1"})
51
+
52
+ // here we just print the transports
53
+ console.log("t1", t1)
54
+ console.log("t2", t2)
55
+
56
+ max_forwards = '18'
57
+
58
+ var username = 'alice'
59
+ var password = 'secret'
60
+ var realm = 'test.com'
61
+
62
+ // make the call from t1 to t2 with some custom heaaders
63
+ const oc = sip.call.create(t1.id, {
64
+ from_uri: 'sip:alice@test.com',
65
+ to_uri: `sip:bob@${t2.address}:${t2.port}`,
66
+ auth: {
67
+ username,
68
+ password,
69
+ realm,
70
+ },
71
+ })
72
+
73
+ // Here we will wait for the call to arrive at t2
74
+ // We will also get a '100 Trying' that is sent by sip-lab automatically
75
+ // We will wait for at most 1000ms. If all events don't arrive within 1000ms, an exception will be thrown and the test will fail due to timeout.
76
+ await z.wait([
77
+ {
78
+ event: "incoming_call",
79
+ call_id: m.collect("call_id"),
80
+ transport_id: t2.id,
81
+ msg: sip_msg({
82
+ $rU: 'bob',
83
+ $fU: 'alice',
84
+ $tU: 'bob',
85
+ $fd: 'test.com',
86
+ $ru: m.collect('ruri'),
87
+ hds_call_id: m.collect('sip_call_id'),
88
+ })
89
+ },
90
+ {
91
+ event: 'response',
92
+ call_id: oc.id,
93
+ method: 'INVITE',
94
+ msg: sip_msg({
95
+ $rs: '100',
96
+ $rr: 'Trying',
97
+ }),
98
+ },
99
+ ], 1000)
100
+
101
+ // Here we store data for the incoming call
102
+ // just to organize our code (not really needed)
103
+ var ic = {
104
+ id: z.$call_id,
105
+ sip_call_id: z.$sip_call_id,
106
+ }
107
+
108
+ // Now we challenge the caller.
109
+ var nonce = "dcd98b7102dd2f0e8b11d0f600bfb0c093"
110
+ var qop = 'auth'
111
+ var algorithm = 'MD5'
112
+ var uri = z.$ruri
113
+ sip.call.respond(ic.id, {
114
+ code: 407,
115
+ reason: 'Proxy Authentication Required',
116
+ headers: {
117
+ 'Proxy-Authenticate': `Digest realm="${realm}", nonce="${nonce}", algorithm=${algorithm}, qop="${qop}"`,
118
+ },
119
+ })
120
+
121
+ // the caller gets the challenge and the call ends at t2.
122
+ await z.wait([
123
+ {
124
+ event: 'response',
125
+ call_id: oc.id,
126
+ method: 'INVITE',
127
+ msg: sip_msg({
128
+ $rs: '407',
129
+ $rr: 'Proxy Authentication Required',
130
+ hdr_proxy_authenticate: `Digest realm="${realm}",nonce="${nonce}",algorithm=${algorithm},qop="${qop}"`,
131
+ }),
132
+ },
133
+ {
134
+ event: 'call_ended',
135
+ call_id: ic.id,
136
+ }
137
+ ], 1000)
138
+
139
+ z.store.call_id = null
140
+ z.store.sip_call_id = null
141
+
142
+ // Then we wait for INVITE with header Authorization
143
+ await z.wait([
144
+ {
145
+ event: "incoming_call",
146
+ call_id: m.collect("call_id"),
147
+ transport_id: t2.id,
148
+ msg: sip_msg({
149
+ $rU: 'bob',
150
+ $fU: 'alice',
151
+ $tU: 'bob',
152
+ $fd: 'test.com',
153
+ hdr_proxy_authorization: 'Digest username="!{username}", realm="!{realm}", nonce="!{nonce}", uri="!{uri}", response="!{response}", algorithm=!{algorithm}, cnonce="!{cnonce}", qop=!{qop}, nc=!{nc}',
154
+ hdr_call_id: m.collect('sip_call_id'),
155
+ })
156
+ },
157
+ {
158
+ event: 'response',
159
+ call_id: oc.id,
160
+ method: 'INVITE',
161
+ msg: sip_msg({
162
+ $rs: '100',
163
+ $rr: 'Trying',
164
+ }),
165
+ },
166
+ ], 1000)
167
+
168
+ var expectedResponse = generateDigestResponse({
169
+ username,
170
+ password,
171
+ realm,
172
+ nonce,
173
+ uri,
174
+ method: 'INVITE',
175
+ qop,
176
+ nc: z.$nc,
177
+ cnonce: z.$cnonce,
178
+ })
179
+
180
+ if(z.$response != expectedResponse.response) {
181
+ throw new Error(`Incorrect digest response. Expected ${expectedResponse.response} but got ${z.$response}`)
182
+ }
183
+
184
+ ic = {
185
+ id: z.$call_id,
186
+ sip_call_id: z.$sip_call_id,
187
+ }
188
+
189
+ // now we answer the call
190
+ sip.call.respond(ic.id, {
191
+ code: 200,
192
+ reason: 'OK',
193
+ })
194
+
195
+ // Then we wait for the '200 OK' at the t1 side
196
+ // We will also get event 'media_update' for both sides indicating media streams (RTP) were set up successfully
197
+ await z.wait([
198
+ {
199
+ event: 'response',
200
+ call_id: oc.id,
201
+ method: 'INVITE',
202
+ msg: sip_msg({
203
+ $rs: '200',
204
+ $rr: 'OK',
205
+ }),
206
+ },
207
+ {
208
+ event: 'media_update',
209
+ call_id: oc.id,
210
+ status: 'ok',
211
+ },
212
+ {
213
+ event: 'media_update',
214
+ call_id: ic.id,
215
+ status: 'ok',
216
+ },
217
+ ], 1000)
218
+
219
+ sip.call.start_inband_dtmf_detection(oc.id)
220
+ sip.call.start_inband_dtmf_detection(ic.id)
221
+
222
+ sip.call.send_dtmf(oc.id, {digits: '1234', mode: 1})
223
+ sip.call.send_dtmf(ic.id, {digits: '1234', mode: 1})
224
+
225
+ await z.wait([
226
+ {
227
+ event: 'dtmf',
228
+ call_id: ic.id,
229
+ digits: '1234',
230
+ mode: 1,
231
+ media_id: 0,
232
+ },
233
+ {
234
+ event: 'dtmf',
235
+ call_id: oc.id,
236
+ digits: '1234',
237
+ mode: 1,
238
+ media_id: 0,
239
+ },
240
+ ], 2000)
241
+
242
+ // now we terminate the call from t1 side
243
+ sip.call.terminate(oc.id)
244
+
245
+ // and wait for termination events
246
+ await z.wait([
247
+ {
248
+ event: 'response',
249
+ call_id: oc.id,
250
+ method: 'BYE',
251
+ msg: sip_msg({
252
+ $rs: '200',
253
+ $rr: 'OK',
254
+ }),
255
+ },
256
+ {
257
+ event: 'call_ended',
258
+ call_id: oc.id,
259
+ },
260
+ {
261
+ event: 'call_ended',
262
+ call_id: ic.id,
263
+ },
264
+ ], 1000)
265
+
266
+ console.log("Success")
267
+
268
+ sip.stop()
269
+ process.exit(0)
270
+ }
271
+
272
+
273
+ test()
274
+ .catch(e => {
275
+ console.error(e)
276
+ process.exit(1)
277
+ })
278
+
@@ -24,8 +24,9 @@ async function test() {
24
24
  console.log("t1", t1)
25
25
  console.log("t2", t2)
26
26
 
27
- console.log(sip.get_codecs())
28
- sip.set_codecs("opus/48000/2:128")
27
+ assert(sip.get_codecs().indexOf("speex/8000/1") > 0)
28
+
29
+ sip.set_codecs("speex/8000/1:128")
29
30
 
30
31
  flags = 0
31
32
 
@@ -188,18 +189,8 @@ async function test() {
188
189
  oc_stat = JSON.parse(oc_stat)
189
190
  ic_stat = JSON.parse(ic_stat)
190
191
 
191
- assert(oc_stat.CodecInfo == 'opus/8000/1')
192
- assert(ic_stat.CodecInfo == 'opus/8000/1')
193
-
194
- await z.sleep(100)
195
-
196
- sip.call.start_inband_dtmf_detection(oc.id)
197
- sip.call.start_inband_dtmf_detection(ic.id)
198
-
199
- sip.call.send_dtmf(oc.id, {digits: '12', mode: 1})
200
- sip.call.send_dtmf(ic.id, {digits: '21', mode: 1})
201
-
202
- await z.sleep(1000)
192
+ assert(oc_stat.CodecInfo == 'speex/8000/1')
193
+ assert(ic_stat.CodecInfo == 'speex/8000/1')
203
194
 
204
195
  sip.call.stop_record_wav(oc.id)
205
196
  sip.call.stop_record_wav(ic.id)