sip-lab 1.3.0 → 1.7.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.
@@ -1,111 +1,123 @@
1
1
  var sip = require ('../index.js')
2
- var z = require('zester')
2
+ var Zester = require('zester')
3
+ var z = new Zester()
3
4
  var m = require('data-matching')
4
5
  var sip_msg = require('sip-matching')
5
6
 
6
- //sip.set_log_level(6)
7
- sip.dtmf_aggregation_on(500)
7
+ async function test() {
8
+ //sip.set_log_level(6)
9
+ sip.dtmf_aggregation_on(500)
8
10
 
9
- z.trap_events(sip.event_source, 'event', (evt) => {
10
- var e = evt.args[0]
11
- return e
12
- })
11
+ z.trap_events(sip.event_source, 'event', (evt) => {
12
+ var e = evt.args[0]
13
+ return e
14
+ })
15
+
16
+ console.log(sip.start((data) => { console.log(data)} ))
17
+
18
+ t1 = sip.transport.create("127.0.0.1", 5090, 1)
19
+ t2 = sip.transport.create("127.0.0.1", 5092, 1)
20
+
21
+ console.log("t1", t1)
22
+ console.log("t2", t2)
23
+
24
+ flags = 0
25
+
26
+ oc = sip.call.create(t1.id, flags, 'sip:a@t', 'sip:b@127.0.0.1:5092')
27
+
28
+ await z.wait([
29
+ {
30
+ event: "incoming_call",
31
+ call_id: m.collect("call_id"),
32
+ },
33
+ {
34
+ event: 'response',
35
+ call_id: oc.id,
36
+ method: 'INVITE',
37
+ msg: sip_msg({
38
+ $rs: '100',
39
+ $rr: 'Trying',
40
+ '$(hdrcnt(via))': 1,
41
+ '$hdr(call-id)': m.collect('sip_call_id'),
42
+ $fU: 'a',
43
+ $fd: 't',
44
+ $tU: 'b',
45
+ '$hdr(l)': '0',
46
+ }),
47
+ },
48
+ ], 1000)
49
+
50
+ ic = {
51
+ id: z.store.call_id,
52
+ sip_call_id: z.store.sip_call_id,
53
+ }
13
54
 
14
- console.log(sip.start((data) => { console.log(data)} ))
15
-
16
- t1 = sip.transport.create("127.0.0.1", 5090, 1)
17
- t2 = sip.transport.create("127.0.0.1", 5092, 1)
18
-
19
- console.log("t1", t1)
20
- console.log("t2", t2)
21
-
22
- flags = 0
23
-
24
- oc = sip.call.create(t1.id, flags, 'sip:a@t', 'sip:b@127.0.0.1:5092')
25
-
26
- z.wait([
27
- {
28
- event: "incoming_call",
29
- call_id: m.collect("call_id"),
30
- },
31
- {
32
- event: 'response',
33
- call_id: oc.id,
34
- method: 'INVITE',
35
- msg: sip_msg({
36
- $rs: '100',
37
- $rr: 'Trying',
38
- '$(hdrcnt(via))': 1,
39
- '$hdr(call-id)': m.collect('sip_call_id'),
40
- $fU: 'a',
41
- $fd: 't',
42
- $tU: 'b',
43
- '$hdr(l)': '0',
44
- }),
45
- },
46
- ], 1000)
47
-
48
- ic = {
49
- id: z.store.call_id,
50
- sip_call_id: z.store.sip_call_id,
55
+ sip.call.respond(ic.id, 180, 'Ringing')
56
+
57
+ await z.wait([
58
+ {
59
+ event: 'response',
60
+ call_id: oc.id,
61
+ method: 'INVITE',
62
+ msg: sip_msg({
63
+ $rs: '180',
64
+ $rr: 'Ringing',
65
+ '$(hdrcnt(VIA))': 1,
66
+ $fU: 'a',
67
+ $fd: 't',
68
+ $tU: 'b',
69
+ }),
70
+ },
71
+ ], 1000)
72
+
73
+ sip.call.terminate(oc.id)
74
+
75
+ await z.wait([
76
+ {
77
+ event: 'request',
78
+ call_id: ic.id,
79
+ msg: sip_msg({
80
+ $rm: 'CANCEL',
81
+ }),
82
+ },
83
+ {
84
+ event: 'response',
85
+ call_id: oc.id,
86
+ method: 'CANCEL',
87
+ msg: sip_msg({
88
+ $rs: '200',
89
+ $rr: 'OK',
90
+ }),
91
+ },
92
+ {
93
+ event: 'response',
94
+ call_id: oc.id,
95
+ method: 'INVITE',
96
+ msg: sip_msg({
97
+ $rs: '487',
98
+ $rr: 'Request Terminated',
99
+ })
100
+ },
101
+ {
102
+ event: 'call_ended',
103
+ call_id: oc.id,
104
+ },
105
+ {
106
+ event: 'call_ended',
107
+ call_id: ic.id,
108
+ },
109
+ ], 1000)
110
+
111
+ await z.sleep(1000)
112
+
113
+ console.log("Success")
114
+
115
+ sip.stop()
51
116
  }
52
117
 
53
- sip.call.respond(ic.id, 180, 'Ringing')
54
-
55
- z.wait([
56
- {
57
- event: 'response',
58
- call_id: oc.id,
59
- method: 'INVITE',
60
- msg: sip_msg({
61
- $rs: '180',
62
- $rr: 'Ringing',
63
- '$(hdrcnt(VIA))': 1,
64
- $fU: 'a',
65
- $fd: 't',
66
- $tU: 'b',
67
- }),
68
- },
69
- ], 1000)
70
-
71
- sip.call.terminate(oc.id)
72
-
73
- z.wait([
74
- {
75
- event: 'request',
76
- call_id: ic.id,
77
- msg: sip_msg({
78
- $rm: 'CANCEL',
79
- }),
80
- },
81
- {
82
- event: 'response',
83
- call_id: oc.id,
84
- method: 'CANCEL',
85
- msg: sip_msg({
86
- $rs: '200',
87
- $rr: 'OK',
88
- }),
89
- },
90
- {
91
- event: 'response',
92
- call_id: oc.id,
93
- method: 'INVITE',
94
- msg: sip_msg({
95
- $rs: '487',
96
- $rr: 'Request Terminated',
97
- })
98
- },
99
- {
100
- event: 'call_ended',
101
- call_id: oc.id,
102
- },
103
- {
104
- event: 'call_ended',
105
- call_id: ic.id,
106
- },
107
- ], 1000)
108
-
109
- z.sleep(1000)
110
-
111
- sip.stop()
118
+ test()
119
+ .catch(e => {
120
+ console.error(e)
121
+ process.exit(1)
122
+ })
123
+