-
Notifications
You must be signed in to change notification settings - Fork 3
/
devjournal
155 lines (122 loc) · 4.81 KB
/
devjournal
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---------------------------------------
2021/09/30 takeshi:
Draft:
Expected usage:
1) starting a sip_mrcp stack:
const sm_stack = sip_mrcp.create(sip_options, rtp_options, mrcp_options, function new_session_callback(session) {
if(session.resource_type != "speechsynth") {
session.refuse(400, "Only speechsynth allowed")
return
}
if(!session.offered_payloads.includes("pcmu")) {
session.refuse(400, "Only pcmu allowed")
return
}
session.accept("pcmu")
session.on('SOME_EVENT', msg => {
// do something
})
})
// sip_options: see kirm/sip.js
// mrcp_options: {local_port} // local_ip should be the same as sip_options.local_ip (as the mrcp server must be reachable)
// rtp_options: {local_ip, ports}
2) creating a sip_mrcp client session (function create_client_session will add an entry to sessions dictonary)
sm_stack.create_client_session(options, function new_session_callback(error, session) {
if(error) {
console.error(`failed to create session. error: ${error}`)
return
}
session.on('SOME_EVENT', msg => {
// do something
})
//session.payload will contain the accepted payload
session.send_request(MRCP_REQUEST)
})
/* options: {
server_ip: 'XXXXXX',
server_port: YYYY
payloads: LIST_OF_ACCEPTABLE_PAYLOADS
}
*/
3) refuse incoming session:
session.refuse(sip_reply_status, sip_reply_reason)
4) accept incoming session:
session.accept(accepted_payload)
// the stack should instantiate an rtp_session and answer the SIP call
5) session events:
- mrcp_msg
- error
- data
Implementation:
We will use an actor library and will process events from 3 sources this way:
sip_stack (actor. Will keep a session dictonary):
server-side:
- INVITE:
- parse and validate SDP (if not valid, refuse the request at this point)
- create new session_actor and call new_session_callback if set
- BYE:
- notify sip_session_terminated
client-side:
- INVITE Response:
- 200 OK:
- parse SDP and confirm it is OK (if not call create_session_callback(error))
- create rtp_session. on 'error' notify create_session_callback(error) and termiante other entities)
- create mrcp_socket. on 'error' notify create_session_callback(error) and terminate other_entities)
- call create_session_callback(null, session)
- XXX SIP ERROR:
- call create_session_callback(error)
- BYE:
- notify sip_session_terminated
mrcp_socket (:
- error: notify mrcp_error
- close: notify mrcp_closed
- data: notify mrcp_msg
rtp_session:
- error: notify rtp_error
- data: notify rtp_data
The events above will be notified to the session actor that will handle the events this way:
session_actor:
- mrcp_closed:
- notify on('end') subscribers
- start timer to shutdown
- mrcp_error:
- notify on('error') subscribers
- start timer to shutdown
- sip_session_terminated:
- notify on('end') subscribers
- start timer to shutdown
- mrcp_msg:
- notify on('mrcp_msg') subscribers
- rtp_error:
- notify on('error') subscribers
- start timer to shutdown
- rtp_data:
- notify on('rtp_data') subscribers
---------------------------------------
2021/10/03 takeshi:
Thinking about adding pluggable logger to my modules.
But we might think in something generic like middleware:
https://thecodebarbarian.com/write-your-own-express-from-scratch
Let's follow this:
https://stackoverflow.com/questions/22335644/best-practice-to-let-users-inject-a-logger-into-nodejs-modules
---------------------------------------
2021/10/03 takeshi:
We are getting this error when trying to use magic-globals:
takeshi:sip-mrcp$ node tests/a.js
/mnt/ssd/work/src/git/MayamaTakeshi/sip-mrcp/node_modules/magic-globals/magic-globals.js:7
Object.defineProperty(global, '__stack', {
^
TypeError: Cannot redefine property: __stack
at Function.defineProperty (<anonymous>)
at Object.<anonymous> (/mnt/ssd/work/src/git/MayamaTakeshi/sip-mrcp/node_modules/magic-globals/magic-globals.js:7:8)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/mnt/ssd/work/src/git/MayamaTakeshi/sip-mrcp/lib/sip_mrcp_stack.js:1:1)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
See: https://github.com/gavinengel/magic-globals/pull/7
The PR was not merged yet so I forked the repo and will use it instead or original magic-globals:
https://github.com/MayamaTakeshi/magic-globals-MODS