sip-lab 1.11.4 → 1.12.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.
- package/README.md +8 -3
- package/binding.gyp +1 -0
- package/index.js +23 -13
- package/install.sh +12 -1
- package/package.json +2 -1
- package/samples/{late_negotiation.js → delayed_media.js} +22 -25
- package/samples/g729.js +11 -11
- package/samples/register_subscribe.js +24 -7
- package/samples/reinvite_and_dtmf.js +22 -24
- package/samples/send_and_receive_fax.js +7 -11
- package/samples/simple.js +10 -12
- package/samples/sip_cancel.js +10 -12
- package/src/addon.cpp +107 -498
- package/src/event_templates.cpp +22 -22
- package/src/event_templates.hpp +10 -10
- package/src/sip.cpp +1121 -498
- package/src/sip.hpp +58 -17
package/src/addon.cpp
CHANGED
|
@@ -48,41 +48,22 @@ void poll()
|
|
|
48
48
|
Napi::Value transport_create(const Napi::CallbackInfo& info) {
|
|
49
49
|
Napi::Env env = info.Env();
|
|
50
50
|
|
|
51
|
-
if (info.Length()
|
|
52
|
-
Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
|
|
51
|
+
if (info.Length() != 1) {
|
|
52
|
+
Napi::TypeError::New(env, "Wrong number of arguments. Expected params").ThrowAsJavaScriptException();
|
|
53
53
|
return env.Null();
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
if (!info[0].IsString()) {
|
|
57
|
-
Napi::TypeError::New(env, "Wrong argument type:
|
|
57
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
58
58
|
return env.Null();
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
const string
|
|
62
|
-
|
|
63
|
-
int port = 0;
|
|
64
|
-
|
|
65
|
-
if (info.Length() > 1) {
|
|
66
|
-
if(!info[1].IsNumber()) {
|
|
67
|
-
Napi::TypeError::New(env, "Wrong argument type: port must be number").ThrowAsJavaScriptException();
|
|
68
|
-
return env.Null();
|
|
69
|
-
}
|
|
70
|
-
port = info[1].As<Napi::Number>().Int32Value();
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
int type = PJSIP_TRANSPORT_UDP;
|
|
74
|
-
|
|
75
|
-
if (info.Length() > 2) {
|
|
76
|
-
if(!info[2].IsNumber()) {
|
|
77
|
-
Napi::TypeError::New(env, "Wrong argument type: transport type must be number").ThrowAsJavaScriptException();
|
|
78
|
-
return env.Null();
|
|
79
|
-
}
|
|
80
|
-
type = info[2].As<Napi::Number>().Int32Value();
|
|
81
|
-
}
|
|
61
|
+
const string json = info[0].As<Napi::String>().Utf8Value();
|
|
82
62
|
|
|
83
63
|
int out_t_id;
|
|
64
|
+
char out_t_address[256];
|
|
84
65
|
int out_t_port;
|
|
85
|
-
int res = pjw_transport_create(
|
|
66
|
+
int res = pjw_transport_create(json.c_str(), &out_t_id, out_t_address, &out_t_port);
|
|
86
67
|
|
|
87
68
|
if(res != 0) {
|
|
88
69
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -91,7 +72,7 @@ Napi::Value transport_create(const Napi::CallbackInfo& info) {
|
|
|
91
72
|
|
|
92
73
|
Napi::Object obj = Napi::Object::New(env);
|
|
93
74
|
obj.Set(Napi::String::New(env, "id"), Napi::Number::New(env, out_t_id));
|
|
94
|
-
obj.Set(Napi::String::New(env, "
|
|
75
|
+
obj.Set(Napi::String::New(env, "address"), Napi::String::New(env, out_t_address));
|
|
95
76
|
obj.Set(Napi::String::New(env, "port"), Napi::Number::New(env, out_t_port));
|
|
96
77
|
|
|
97
78
|
return obj;
|
|
@@ -101,8 +82,8 @@ Napi::Value transport_create(const Napi::CallbackInfo& info) {
|
|
|
101
82
|
Napi::Value account_create(const Napi::CallbackInfo& info) {
|
|
102
83
|
Napi::Env env = info.Env();
|
|
103
84
|
|
|
104
|
-
if (info.Length()
|
|
105
|
-
Napi::TypeError::New(env, "Wrong number of arguments. Expected: transport_id,
|
|
85
|
+
if (info.Length() != 2) {
|
|
86
|
+
Napi::TypeError::New(env, "Wrong number of arguments. Expected: transport_id, params.").ThrowAsJavaScriptException();
|
|
106
87
|
return env.Null();
|
|
107
88
|
}
|
|
108
89
|
|
|
@@ -113,61 +94,13 @@ Napi::Value account_create(const Napi::CallbackInfo& info) {
|
|
|
113
94
|
int transport_id = info[0].As<Napi::Number>().Int32Value();
|
|
114
95
|
|
|
115
96
|
if (!info[1].IsString()) {
|
|
116
|
-
Napi::TypeError::New(env, "Wrong argument type:
|
|
117
|
-
return env.Null();
|
|
118
|
-
}
|
|
119
|
-
const string domain = info[1].As<Napi::String>().Utf8Value();
|
|
120
|
-
|
|
121
|
-
if (!info[2].IsString()) {
|
|
122
|
-
Napi::TypeError::New(env, "Wrong argument type: server must be string.").ThrowAsJavaScriptException();
|
|
97
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
123
98
|
return env.Null();
|
|
124
99
|
}
|
|
125
|
-
const string
|
|
126
|
-
|
|
127
|
-
if (!info[3].IsString()) {
|
|
128
|
-
Napi::TypeError::New(env, "Wrong argument type: user must be string.").ThrowAsJavaScriptException();
|
|
129
|
-
return env.Null();
|
|
130
|
-
}
|
|
131
|
-
const string user = info[3].As<Napi::String>().Utf8Value();
|
|
132
|
-
|
|
133
|
-
if (!info[4].IsString()) {
|
|
134
|
-
Napi::TypeError::New(env, "Wrong argument type: password must be string.").ThrowAsJavaScriptException();
|
|
135
|
-
return env.Null();
|
|
136
|
-
}
|
|
137
|
-
const string pass = info[4].As<Napi::String>().Utf8Value();
|
|
138
|
-
|
|
139
|
-
string additional_headers = string("");
|
|
140
|
-
|
|
141
|
-
if (info.Length() > 5) {
|
|
142
|
-
if (!info[5].IsString()) {
|
|
143
|
-
Napi::TypeError::New(env, "Wrong argument type: additional_headers must be string.").ThrowAsJavaScriptException();
|
|
144
|
-
return env.Null();
|
|
145
|
-
}
|
|
146
|
-
additional_headers = info[5].As<Napi::String>().Utf8Value();
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
string c_to_url = string("");
|
|
150
|
-
|
|
151
|
-
if (info.Length() > 6) {
|
|
152
|
-
if (!info[6].IsString()) {
|
|
153
|
-
Napi::TypeError::New(env, "Wrong argument type: c_to_url must be string.").ThrowAsJavaScriptException();
|
|
154
|
-
return env.Null();
|
|
155
|
-
}
|
|
156
|
-
c_to_url = info[6].As<Napi::String>().Utf8Value().c_str();
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
int expires = 60;
|
|
160
|
-
|
|
161
|
-
if (info.Length() > 7) {
|
|
162
|
-
if (!info[7].IsNumber()) {
|
|
163
|
-
Napi::TypeError::New(env, "Wrong argument type: expires must be number.").ThrowAsJavaScriptException();
|
|
164
|
-
return env.Null();
|
|
165
|
-
}
|
|
166
|
-
expires = info[7].As<Napi::Number>().Int32Value();
|
|
167
|
-
}
|
|
100
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
168
101
|
|
|
169
102
|
int out_a_id;
|
|
170
|
-
int res = pjw_account_create(transport_id,
|
|
103
|
+
int res = pjw_account_create(transport_id, json.c_str(), &out_a_id);
|
|
171
104
|
|
|
172
105
|
if(res != 0) {
|
|
173
106
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -181,8 +114,8 @@ Napi::Value account_create(const Napi::CallbackInfo& info) {
|
|
|
181
114
|
Napi::Value account_register(const Napi::CallbackInfo& info) {
|
|
182
115
|
Napi::Env env = info.Env();
|
|
183
116
|
|
|
184
|
-
if (info.Length()
|
|
185
|
-
Napi::TypeError::New(env, "Wrong number of arguments. Expected: account_id
|
|
117
|
+
if (info.Length() != 2) {
|
|
118
|
+
Napi::TypeError::New(env, "Wrong number of arguments. Expected: account_id, params.").ThrowAsJavaScriptException();
|
|
186
119
|
return env.Null();
|
|
187
120
|
}
|
|
188
121
|
|
|
@@ -192,17 +125,13 @@ Napi::Value account_register(const Napi::CallbackInfo& info) {
|
|
|
192
125
|
}
|
|
193
126
|
int account_id = info[0].As<Napi::Number>().Int32Value();
|
|
194
127
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if(!info[1].IsBoolean()) {
|
|
199
|
-
Napi::TypeError::New(env, "Wrong argument type: auto_register must be boolean").ThrowAsJavaScriptException();
|
|
200
|
-
return env.Null();
|
|
201
|
-
}
|
|
202
|
-
auto_register = info[1].As<Napi::Boolean>().Value();
|
|
128
|
+
if (!info[1].IsString()) {
|
|
129
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
130
|
+
return env.Null();
|
|
203
131
|
}
|
|
132
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
204
133
|
|
|
205
|
-
int res = pjw_account_register(account_id,
|
|
134
|
+
int res = pjw_account_register(account_id, json.c_str());
|
|
206
135
|
|
|
207
136
|
if(res != 0) {
|
|
208
137
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -240,8 +169,8 @@ Napi::Value account_unregister(const Napi::CallbackInfo& info) {
|
|
|
240
169
|
Napi::Value call_create(const Napi::CallbackInfo& info) {
|
|
241
170
|
Napi::Env env = info.Env();
|
|
242
171
|
|
|
243
|
-
if (info.Length()
|
|
244
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: transport_id,
|
|
172
|
+
if (info.Length() != 2) {
|
|
173
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: transport_id, params.").ThrowAsJavaScriptException();
|
|
245
174
|
return env.Null();
|
|
246
175
|
}
|
|
247
176
|
|
|
@@ -251,91 +180,16 @@ Napi::Value call_create(const Napi::CallbackInfo& info) {
|
|
|
251
180
|
}
|
|
252
181
|
int transport_id = info[0].As<Napi::Number>().Int32Value();
|
|
253
182
|
|
|
254
|
-
if (!info[
|
|
255
|
-
Napi::TypeError::New(env, "
|
|
256
|
-
return env.Null();
|
|
257
|
-
}
|
|
258
|
-
unsigned flags = info[1].As<Napi::Number>().Uint32Value();
|
|
259
|
-
|
|
260
|
-
if (!info[2].IsString()) {
|
|
261
|
-
Napi::TypeError::New(env, "from_uri must be string.").ThrowAsJavaScriptException();
|
|
262
|
-
return env.Null();
|
|
263
|
-
}
|
|
264
|
-
const string from_uri = info[2].As<Napi::String>().Utf8Value();
|
|
265
|
-
|
|
266
|
-
if (!info[3].IsString()) {
|
|
267
|
-
Napi::TypeError::New(env, "to_uri must be string.").ThrowAsJavaScriptException();
|
|
183
|
+
if (!info[1].IsString()) {
|
|
184
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
268
185
|
return env.Null();
|
|
269
186
|
}
|
|
270
|
-
const string
|
|
271
|
-
|
|
272
|
-
string request_uri = string("");
|
|
273
|
-
|
|
274
|
-
if (info.Length() > 4) {
|
|
275
|
-
if (!info[3].IsString()) {
|
|
276
|
-
Napi::TypeError::New(env, "request_uri must be string.").ThrowAsJavaScriptException();
|
|
277
|
-
return env.Null();
|
|
278
|
-
}
|
|
279
|
-
request_uri = info[4].As<Napi::String>().Utf8Value();
|
|
280
|
-
} else {
|
|
281
|
-
request_uri = to_uri; // TODO: remove angle brackets if present
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
string proxy_uri = string("");
|
|
285
|
-
|
|
286
|
-
if (info.Length() > 5) {
|
|
287
|
-
if (!info[5].IsString()) {
|
|
288
|
-
Napi::TypeError::New(env, "proxy_uri must be string.").ThrowAsJavaScriptException();
|
|
289
|
-
return env.Null();
|
|
290
|
-
}
|
|
291
|
-
proxy_uri = info[5].As<Napi::String>().Utf8Value();
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
string additional_headers = string("");
|
|
295
|
-
|
|
296
|
-
if (info.Length() > 6) {
|
|
297
|
-
if (!info[5].IsString()) {
|
|
298
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
299
|
-
return env.Null();
|
|
300
|
-
}
|
|
301
|
-
additional_headers = info[5].As<Napi::String>().Utf8Value();
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
string c_to_url = string("");
|
|
305
|
-
|
|
306
|
-
string realm = string("");
|
|
307
|
-
string user = string("");
|
|
308
|
-
string pass = string("");
|
|
309
|
-
|
|
310
|
-
if (info.Length() > 7) {
|
|
311
|
-
if(info.Length() < 10) {
|
|
312
|
-
Napi::Error::New(env, "incomplete credentials arguments: you must provide realm, user and pass").ThrowAsJavaScriptException();
|
|
313
|
-
return env.Null();
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (!info[7].IsString()) {
|
|
317
|
-
Napi::TypeError::New(env, "realm must be string.").ThrowAsJavaScriptException();
|
|
318
|
-
return env.Null();
|
|
319
|
-
}
|
|
320
|
-
realm = info[7].As<Napi::String>().Utf8Value().c_str();
|
|
321
|
-
|
|
322
|
-
if (!info[8].IsString()) {
|
|
323
|
-
Napi::TypeError::New(env, "user must be string.").ThrowAsJavaScriptException();
|
|
324
|
-
return env.Null();
|
|
325
|
-
}
|
|
326
|
-
user = info[8].As<Napi::String>().Utf8Value().c_str();
|
|
327
|
-
|
|
328
|
-
if (!info[9].IsString()) {
|
|
329
|
-
Napi::TypeError::New(env, "pass must be string.").ThrowAsJavaScriptException();
|
|
330
|
-
return env.Null();
|
|
331
|
-
}
|
|
332
|
-
pass = info[9].As<Napi::String>().Utf8Value().c_str();
|
|
333
|
-
}
|
|
187
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
334
188
|
|
|
335
189
|
long int out_call_id;
|
|
336
190
|
char out_sip_call_id[256];
|
|
337
191
|
|
|
338
|
-
int res = pjw_call_create(transport_id,
|
|
192
|
+
int res = pjw_call_create(transport_id, json.c_str(), &out_call_id, out_sip_call_id);
|
|
339
193
|
|
|
340
194
|
if(res != 0) {
|
|
341
195
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -352,8 +206,8 @@ Napi::Value call_create(const Napi::CallbackInfo& info) {
|
|
|
352
206
|
Napi::Value call_respond(const Napi::CallbackInfo& info) {
|
|
353
207
|
Napi::Env env = info.Env();
|
|
354
208
|
|
|
355
|
-
if (info.Length()
|
|
356
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
209
|
+
if (info.Length() != 2) {
|
|
210
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params").ThrowAsJavaScriptException();
|
|
357
211
|
return env.Null();
|
|
358
212
|
}
|
|
359
213
|
|
|
@@ -363,29 +217,13 @@ Napi::Value call_respond(const Napi::CallbackInfo& info) {
|
|
|
363
217
|
}
|
|
364
218
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
365
219
|
|
|
366
|
-
if (!info[1].
|
|
367
|
-
Napi::TypeError::New(env, "
|
|
368
|
-
return env.Null();
|
|
369
|
-
}
|
|
370
|
-
int code = info[1].As<Napi::Number>().Int32Value();
|
|
371
|
-
|
|
372
|
-
if (!info[2].IsString()) {
|
|
373
|
-
Napi::TypeError::New(env, "reason must be string.").ThrowAsJavaScriptException();
|
|
220
|
+
if (!info[1].IsString()) {
|
|
221
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
374
222
|
return env.Null();
|
|
375
223
|
}
|
|
376
|
-
const string
|
|
224
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
377
225
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
if (info.Length() > 3) {
|
|
381
|
-
if (!info[3].IsString()) {
|
|
382
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
383
|
-
return env.Null();
|
|
384
|
-
}
|
|
385
|
-
additional_headers = info[3].As<Napi::String>().Utf8Value();
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
int res = pjw_call_respond(call_id, code, reason.c_str(), additional_headers[0] ? additional_headers.c_str() : NULL);
|
|
226
|
+
int res = pjw_call_respond(call_id, json.c_str());
|
|
389
227
|
|
|
390
228
|
if(res != 0) {
|
|
391
229
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -398,8 +236,8 @@ Napi::Value call_respond(const Napi::CallbackInfo& info) {
|
|
|
398
236
|
Napi::Value call_terminate(const Napi::CallbackInfo& info) {
|
|
399
237
|
Napi::Env env = info.Env();
|
|
400
238
|
|
|
401
|
-
if (info.Length()
|
|
402
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id
|
|
239
|
+
if (info.Length() != 2) {
|
|
240
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params").ThrowAsJavaScriptException();
|
|
403
241
|
return env.Null();
|
|
404
242
|
}
|
|
405
243
|
|
|
@@ -408,37 +246,14 @@ Napi::Value call_terminate(const Napi::CallbackInfo& info) {
|
|
|
408
246
|
return env.Null();
|
|
409
247
|
}
|
|
410
248
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
Napi::TypeError::New(env, "code must be number.").ThrowAsJavaScriptException();
|
|
416
|
-
return env.Null();
|
|
417
|
-
}
|
|
418
|
-
code = info[1].As<Napi::Number>().Int32Value();
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
string reason = string("");
|
|
422
|
-
|
|
423
|
-
if (info.Length() > 2) {
|
|
424
|
-
if (!info[2].IsString()) {
|
|
425
|
-
Napi::TypeError::New(env, "reason must be string.").ThrowAsJavaScriptException();
|
|
426
|
-
return env.Null();
|
|
427
|
-
}
|
|
428
|
-
reason = info[2].As<Napi::String>().Utf8Value();
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
string additional_headers = string("");
|
|
432
|
-
|
|
433
|
-
if (info.Length() > 3) {
|
|
434
|
-
if (!info[3].IsString()) {
|
|
435
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
436
|
-
return env.Null();
|
|
437
|
-
}
|
|
438
|
-
additional_headers = info[3].As<Napi::String>().Utf8Value();
|
|
249
|
+
|
|
250
|
+
if (!info[1].IsString()) {
|
|
251
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
252
|
+
return env.Null();
|
|
439
253
|
}
|
|
254
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
440
255
|
|
|
441
|
-
int res = pjw_call_terminate(call_id,
|
|
256
|
+
int res = pjw_call_terminate(call_id, json.c_str());
|
|
442
257
|
|
|
443
258
|
if(res != 0) {
|
|
444
259
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -451,8 +266,8 @@ Napi::Value call_terminate(const Napi::CallbackInfo& info) {
|
|
|
451
266
|
Napi::Value call_send_dtmf(const Napi::CallbackInfo& info) {
|
|
452
267
|
Napi::Env env = info.Env();
|
|
453
268
|
|
|
454
|
-
if (info.Length() !=
|
|
455
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
269
|
+
if (info.Length() != 2) {
|
|
270
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
456
271
|
return env.Null();
|
|
457
272
|
}
|
|
458
273
|
|
|
@@ -461,32 +276,14 @@ Napi::Value call_send_dtmf(const Napi::CallbackInfo& info) {
|
|
|
461
276
|
return env.Null();
|
|
462
277
|
}
|
|
463
278
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
464
|
-
|
|
465
|
-
string digits = string("");
|
|
279
|
+
|
|
466
280
|
if (!info[1].IsString()) {
|
|
467
|
-
Napi::TypeError::New(env, "
|
|
281
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
468
282
|
return env.Null();
|
|
469
283
|
}
|
|
470
|
-
|
|
284
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
471
285
|
|
|
472
|
-
|
|
473
|
-
Napi::Error::New(env, "digits is empty string").ThrowAsJavaScriptException();
|
|
474
|
-
return env.Null();
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
int mode = 0;
|
|
478
|
-
if (!info[2].IsNumber()) {
|
|
479
|
-
Napi::TypeError::New(env, "mode must be number.").ThrowAsJavaScriptException();
|
|
480
|
-
return env.Null();
|
|
481
|
-
}
|
|
482
|
-
mode = info[2].As<Napi::Number>().Int32Value();
|
|
483
|
-
|
|
484
|
-
if(mode != 0 && mode != 1) {
|
|
485
|
-
Napi::TypeError::New(env, "mode must be 0 (RFC2833) or 1 (in-band)").ThrowAsJavaScriptException();
|
|
486
|
-
return env.Null();
|
|
487
|
-
}
|
|
488
|
-
|
|
489
|
-
int res = pjw_call_send_dtmf(call_id, digits.c_str(), mode);
|
|
286
|
+
int res = pjw_call_send_dtmf(call_id, json.c_str());
|
|
490
287
|
|
|
491
288
|
if(res != 0) {
|
|
492
289
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -499,8 +296,8 @@ Napi::Value call_send_dtmf(const Napi::CallbackInfo& info) {
|
|
|
499
296
|
Napi::Value call_reinvite(const Napi::CallbackInfo& info) {
|
|
500
297
|
Napi::Env env = info.Env();
|
|
501
298
|
|
|
502
|
-
if (info.Length() !=
|
|
503
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
299
|
+
if (info.Length() != 2) {
|
|
300
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
504
301
|
return env.Null();
|
|
505
302
|
}
|
|
506
303
|
|
|
@@ -510,19 +307,13 @@ Napi::Value call_reinvite(const Napi::CallbackInfo& info) {
|
|
|
510
307
|
}
|
|
511
308
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
512
309
|
|
|
513
|
-
if(!info[1].
|
|
514
|
-
Napi::TypeError::New(env, "
|
|
515
|
-
return env.Null();
|
|
516
|
-
}
|
|
517
|
-
bool hold = info[1].As<Napi::Boolean>().Value();
|
|
518
|
-
|
|
519
|
-
if (!info[2].IsNumber()) {
|
|
520
|
-
Napi::TypeError::New(env, "flags must be number.").ThrowAsJavaScriptException();
|
|
310
|
+
if (!info[1].IsString()) {
|
|
311
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
521
312
|
return env.Null();
|
|
522
313
|
}
|
|
523
|
-
|
|
314
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
524
315
|
|
|
525
|
-
int res = pjw_call_reinvite(call_id,
|
|
316
|
+
int res = pjw_call_reinvite(call_id, json.c_str());
|
|
526
317
|
|
|
527
318
|
if(res != 0) {
|
|
528
319
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -535,8 +326,8 @@ Napi::Value call_reinvite(const Napi::CallbackInfo& info) {
|
|
|
535
326
|
Napi::Value call_send_request(const Napi::CallbackInfo& info) {
|
|
536
327
|
Napi::Env env = info.Env();
|
|
537
328
|
|
|
538
|
-
if (info.Length()
|
|
539
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
329
|
+
if (info.Length() != 2) {
|
|
330
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
540
331
|
return env.Null();
|
|
541
332
|
}
|
|
542
333
|
|
|
@@ -545,51 +336,14 @@ Napi::Value call_send_request(const Napi::CallbackInfo& info) {
|
|
|
545
336
|
return env.Null();
|
|
546
337
|
}
|
|
547
338
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
548
|
-
|
|
549
|
-
string method = string("");
|
|
339
|
+
|
|
550
340
|
if (!info[1].IsString()) {
|
|
551
|
-
Napi::TypeError::New(env, "
|
|
341
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
552
342
|
return env.Null();
|
|
553
343
|
}
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
string additional_headers = string("");
|
|
557
|
-
if (info.Length() > 2) {
|
|
558
|
-
if (!info[2].IsString()) {
|
|
559
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
560
|
-
return env.Null();
|
|
561
|
-
}
|
|
562
|
-
additional_headers = info[2].As<Napi::String>().Utf8Value();
|
|
563
|
-
}
|
|
564
|
-
|
|
565
|
-
string body = string("");
|
|
566
|
-
if (info.Length() > 3) {
|
|
567
|
-
if (!info[3].IsString()) {
|
|
568
|
-
Napi::TypeError::New(env, "body must be string.").ThrowAsJavaScriptException();
|
|
569
|
-
return env.Null();
|
|
570
|
-
}
|
|
571
|
-
body = info[3].As<Napi::String>().Utf8Value();
|
|
572
|
-
}
|
|
573
|
-
|
|
574
|
-
string ct_type = string("");
|
|
575
|
-
if (info.Length() > 4) {
|
|
576
|
-
if (!info[4].IsString()) {
|
|
577
|
-
Napi::TypeError::New(env, "ct_type must be string.").ThrowAsJavaScriptException();
|
|
578
|
-
return env.Null();
|
|
579
|
-
}
|
|
580
|
-
ct_type = info[4].As<Napi::String>().Utf8Value();
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
string ct_subtype = string("");
|
|
584
|
-
if (info.Length() > 5) {
|
|
585
|
-
if (!info[5].IsString()) {
|
|
586
|
-
Napi::TypeError::New(env, "ct_subtype must be string.").ThrowAsJavaScriptException();
|
|
587
|
-
return env.Null();
|
|
588
|
-
}
|
|
589
|
-
ct_subtype = info[5].As<Napi::String>().Utf8Value();
|
|
590
|
-
}
|
|
344
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
591
345
|
|
|
592
|
-
int res = pjw_call_send_request(call_id,
|
|
346
|
+
int res = pjw_call_send_request(call_id, json.c_str());
|
|
593
347
|
|
|
594
348
|
if(res != 0) {
|
|
595
349
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -603,7 +357,7 @@ Napi::Value call_start_record_wav(const Napi::CallbackInfo& info) {
|
|
|
603
357
|
Napi::Env env = info.Env();
|
|
604
358
|
|
|
605
359
|
if (info.Length() != 2) {
|
|
606
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
360
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
607
361
|
return env.Null();
|
|
608
362
|
}
|
|
609
363
|
|
|
@@ -612,19 +366,14 @@ Napi::Value call_start_record_wav(const Napi::CallbackInfo& info) {
|
|
|
612
366
|
return env.Null();
|
|
613
367
|
}
|
|
614
368
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
615
|
-
|
|
369
|
+
|
|
616
370
|
if (!info[1].IsString()) {
|
|
617
|
-
Napi::TypeError::New(env, "
|
|
371
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
618
372
|
return env.Null();
|
|
619
373
|
}
|
|
620
|
-
string
|
|
374
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
621
375
|
|
|
622
|
-
|
|
623
|
-
Napi::Error::New(env, "output_file is invalid (blank string)").ThrowAsJavaScriptException();
|
|
624
|
-
return env.Null();
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
int res = pjw_call_start_record_wav(call_id, output_file.c_str());
|
|
376
|
+
int res = pjw_call_start_record_wav(call_id, json.c_str());
|
|
628
377
|
|
|
629
378
|
if(res != 0) {
|
|
630
379
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -638,7 +387,7 @@ Napi::Value call_start_play_wav(const Napi::CallbackInfo& info) {
|
|
|
638
387
|
Napi::Env env = info.Env();
|
|
639
388
|
|
|
640
389
|
if (info.Length() != 2) {
|
|
641
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
390
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
642
391
|
return env.Null();
|
|
643
392
|
}
|
|
644
393
|
|
|
@@ -647,19 +396,14 @@ Napi::Value call_start_play_wav(const Napi::CallbackInfo& info) {
|
|
|
647
396
|
return env.Null();
|
|
648
397
|
}
|
|
649
398
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
650
|
-
|
|
399
|
+
|
|
651
400
|
if (!info[1].IsString()) {
|
|
652
|
-
Napi::TypeError::New(env, "
|
|
653
|
-
return env.Null();
|
|
654
|
-
}
|
|
655
|
-
string input_file = info[1].As<Napi::String>().Utf8Value();
|
|
656
|
-
|
|
657
|
-
if (input_file.length() == 0) {
|
|
658
|
-
Napi::Error::New(env, "input_file is invalid (blank string)").ThrowAsJavaScriptException();
|
|
401
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
659
402
|
return env.Null();
|
|
660
403
|
}
|
|
404
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
661
405
|
|
|
662
|
-
int res = pjw_call_start_play_wav(call_id,
|
|
406
|
+
int res = pjw_call_start_play_wav(call_id, json.c_str());
|
|
663
407
|
|
|
664
408
|
if(res != 0) {
|
|
665
409
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -672,8 +416,8 @@ Napi::Value call_start_play_wav(const Napi::CallbackInfo& info) {
|
|
|
672
416
|
Napi::Value call_start_fax(const Napi::CallbackInfo& info) {
|
|
673
417
|
Napi::Env env = info.Env();
|
|
674
418
|
|
|
675
|
-
if (info.Length() !=
|
|
676
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
419
|
+
if (info.Length() != 2) {
|
|
420
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
677
421
|
return env.Null();
|
|
678
422
|
}
|
|
679
423
|
|
|
@@ -682,25 +426,14 @@ Napi::Value call_start_fax(const Napi::CallbackInfo& info) {
|
|
|
682
426
|
return env.Null();
|
|
683
427
|
}
|
|
684
428
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
685
|
-
|
|
686
|
-
if (!info[1].
|
|
687
|
-
Napi::TypeError::New(env, "
|
|
688
|
-
return env.Null();
|
|
689
|
-
}
|
|
690
|
-
bool is_sender = info[1].As<Napi::Boolean>().Value();
|
|
691
|
-
|
|
692
|
-
if (!info[2].IsString()) {
|
|
693
|
-
Napi::TypeError::New(env, "file must be string.").ThrowAsJavaScriptException();
|
|
694
|
-
return env.Null();
|
|
695
|
-
}
|
|
696
|
-
string file = info[2].As<Napi::String>().Utf8Value();
|
|
697
|
-
|
|
698
|
-
if (file.length() == 0) {
|
|
699
|
-
Napi::Error::New(env, "input_file is invalid (blank string)").ThrowAsJavaScriptException();
|
|
429
|
+
|
|
430
|
+
if (!info[1].IsString()) {
|
|
431
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
700
432
|
return env.Null();
|
|
701
433
|
}
|
|
434
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
702
435
|
|
|
703
|
-
int res = pjw_call_start_fax(call_id,
|
|
436
|
+
int res = pjw_call_start_fax(call_id, json.c_str());
|
|
704
437
|
|
|
705
438
|
if(res != 0) {
|
|
706
439
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -810,8 +543,8 @@ Napi::Value call_get_stream_stat(const Napi::CallbackInfo& info) {
|
|
|
810
543
|
Napi::Value call_refer(const Napi::CallbackInfo& info) {
|
|
811
544
|
Napi::Env env = info.Env();
|
|
812
545
|
|
|
813
|
-
if (info.Length()
|
|
814
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id,
|
|
546
|
+
if (info.Length() != 2) {
|
|
547
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: call_id, params.").ThrowAsJavaScriptException();
|
|
815
548
|
return env.Null();
|
|
816
549
|
}
|
|
817
550
|
|
|
@@ -820,25 +553,16 @@ Napi::Value call_refer(const Napi::CallbackInfo& info) {
|
|
|
820
553
|
return env.Null();
|
|
821
554
|
}
|
|
822
555
|
int call_id = info[0].As<Napi::Number>().Int32Value();
|
|
823
|
-
|
|
556
|
+
|
|
824
557
|
if (!info[1].IsString()) {
|
|
825
|
-
Napi::TypeError::New(env, "
|
|
558
|
+
Napi::TypeError::New(env, "params must be a JSON string.").ThrowAsJavaScriptException();
|
|
826
559
|
return env.Null();
|
|
827
560
|
}
|
|
828
|
-
const string
|
|
829
|
-
|
|
830
|
-
string additional_headers = string("");
|
|
831
|
-
if (info.Length() > 2) {
|
|
832
|
-
if (!info[2].IsString()) {
|
|
833
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
834
|
-
return env.Null();
|
|
835
|
-
}
|
|
836
|
-
additional_headers = info[2].As<Napi::String>().Utf8Value();
|
|
837
|
-
}
|
|
561
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
838
562
|
|
|
839
563
|
long out_subscription_id;
|
|
840
564
|
|
|
841
|
-
int res = pjw_call_refer(call_id,
|
|
565
|
+
int res = pjw_call_refer(call_id, json.c_str(), &out_subscription_id);
|
|
842
566
|
|
|
843
567
|
if(res != 0) {
|
|
844
568
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -1046,8 +770,8 @@ Napi::Value set_codecs(const Napi::CallbackInfo& info) {
|
|
|
1046
770
|
Napi::Value notify(const Napi::CallbackInfo& info) {
|
|
1047
771
|
Napi::Env env = info.Env();
|
|
1048
772
|
|
|
1049
|
-
if (info.Length()
|
|
1050
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: subscriber_id,
|
|
773
|
+
if (info.Length() != 2) {
|
|
774
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: subscriber_id, params.").ThrowAsJavaScriptException();
|
|
1051
775
|
return env.Null();
|
|
1052
776
|
}
|
|
1053
777
|
|
|
@@ -1056,41 +780,14 @@ Napi::Value notify(const Napi::CallbackInfo& info) {
|
|
|
1056
780
|
return env.Null();
|
|
1057
781
|
}
|
|
1058
782
|
int subscriber_id = info[0].As<Napi::Number>().Int32Value();
|
|
1059
|
-
|
|
783
|
+
|
|
1060
784
|
if (!info[1].IsString()) {
|
|
1061
|
-
Napi::TypeError::New(env, "
|
|
1062
|
-
return env.Null();
|
|
1063
|
-
}
|
|
1064
|
-
string content_type = info[1].As<Napi::String>().Utf8Value();
|
|
1065
|
-
|
|
1066
|
-
if (!info[2].IsString()) {
|
|
1067
|
-
Napi::TypeError::New(env, "body must be string.").ThrowAsJavaScriptException();
|
|
1068
|
-
return env.Null();
|
|
1069
|
-
}
|
|
1070
|
-
string body = info[2].As<Napi::String>().Utf8Value();
|
|
1071
|
-
|
|
1072
|
-
if (!info[3].IsNumber()) {
|
|
1073
|
-
Napi::TypeError::New(env, "subscription_state must be number.").ThrowAsJavaScriptException();
|
|
1074
|
-
return env.Null();
|
|
1075
|
-
}
|
|
1076
|
-
int subscription_state = info[3].As<Napi::Number>().Int32Value();
|
|
1077
|
-
|
|
1078
|
-
if (!info[4].IsString()) {
|
|
1079
|
-
Napi::TypeError::New(env, "reason must be string.").ThrowAsJavaScriptException();
|
|
785
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
1080
786
|
return env.Null();
|
|
1081
787
|
}
|
|
1082
|
-
string
|
|
788
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
1083
789
|
|
|
1084
|
-
|
|
1085
|
-
if (info.Length() > 5) {
|
|
1086
|
-
if (!info[5].IsString()) {
|
|
1087
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
1088
|
-
return env.Null();
|
|
1089
|
-
}
|
|
1090
|
-
additional_headers = info[5].As<Napi::String>().Utf8Value();
|
|
1091
|
-
}
|
|
1092
|
-
|
|
1093
|
-
int res = pjw_notify(subscriber_id, content_type.c_str(), body.c_str(), subscription_state, reason.c_str(), additional_headers[0] ? additional_headers.c_str() : NULL);
|
|
790
|
+
int res = pjw_notify(subscriber_id, json.c_str());
|
|
1094
791
|
|
|
1095
792
|
if(res != 0) {
|
|
1096
793
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -1103,8 +800,8 @@ Napi::Value notify(const Napi::CallbackInfo& info) {
|
|
|
1103
800
|
Napi::Value notify_xfer(const Napi::CallbackInfo& info) {
|
|
1104
801
|
Napi::Env env = info.Env();
|
|
1105
802
|
|
|
1106
|
-
if (info.Length() !=
|
|
1107
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: subscriber_id,
|
|
803
|
+
if (info.Length() != 2) {
|
|
804
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: subscriber_id, params").ThrowAsJavaScriptException();
|
|
1108
805
|
return env.Null();
|
|
1109
806
|
}
|
|
1110
807
|
|
|
@@ -1113,26 +810,14 @@ Napi::Value notify_xfer(const Napi::CallbackInfo& info) {
|
|
|
1113
810
|
return env.Null();
|
|
1114
811
|
}
|
|
1115
812
|
int subscriber_id = info[0].As<Napi::Number>().Int32Value();
|
|
1116
|
-
|
|
1117
|
-
if (!info[1].
|
|
1118
|
-
Napi::TypeError::New(env, "
|
|
1119
|
-
return env.Null();
|
|
1120
|
-
}
|
|
1121
|
-
int subscription_state = info[1].As<Napi::Number>().Int32Value();
|
|
1122
|
-
|
|
1123
|
-
if (!info[2].IsNumber()) {
|
|
1124
|
-
Napi::TypeError::New(env, "xfer_status_code must be number.").ThrowAsJavaScriptException();
|
|
1125
|
-
return env.Null();
|
|
1126
|
-
}
|
|
1127
|
-
int xfer_status_code = info[2].As<Napi::Number>().Int32Value();
|
|
1128
|
-
|
|
1129
|
-
if (!info[3].IsString()) {
|
|
1130
|
-
Napi::TypeError::New(env, "xfer_status_text must be string.").ThrowAsJavaScriptException();
|
|
813
|
+
|
|
814
|
+
if (!info[1].IsString()) {
|
|
815
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
1131
816
|
return env.Null();
|
|
1132
817
|
}
|
|
1133
|
-
string
|
|
818
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
1134
819
|
|
|
1135
|
-
int res = pjw_notify_xfer(subscriber_id,
|
|
820
|
+
int res = pjw_notify_xfer(subscriber_id, json.c_str());
|
|
1136
821
|
|
|
1137
822
|
if(res != 0) {
|
|
1138
823
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -1175,8 +860,8 @@ Napi::Value register_pkg(const Napi::CallbackInfo& info) {
|
|
|
1175
860
|
Napi::Value subscription_create(const Napi::CallbackInfo& info) {
|
|
1176
861
|
Napi::Env env = info.Env();
|
|
1177
862
|
|
|
1178
|
-
if (info.Length()
|
|
1179
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: transport_id,
|
|
863
|
+
if (info.Length() != 2) {
|
|
864
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: transport_id, params.").ThrowAsJavaScriptException();
|
|
1180
865
|
return env.Null();
|
|
1181
866
|
}
|
|
1182
867
|
|
|
@@ -1185,83 +870,16 @@ Napi::Value subscription_create(const Napi::CallbackInfo& info) {
|
|
|
1185
870
|
return env.Null();
|
|
1186
871
|
}
|
|
1187
872
|
int transport_id = info[0].As<Napi::Number>().Int32Value();
|
|
1188
|
-
|
|
873
|
+
|
|
1189
874
|
if (!info[1].IsString()) {
|
|
1190
|
-
Napi::TypeError::New(env, "
|
|
1191
|
-
return env.Null();
|
|
1192
|
-
}
|
|
1193
|
-
string event = info[1].As<Napi::String>().Utf8Value();
|
|
1194
|
-
|
|
1195
|
-
if (!info[2].IsString()) {
|
|
1196
|
-
Napi::TypeError::New(env, "accept must be string.").ThrowAsJavaScriptException();
|
|
1197
|
-
return env.Null();
|
|
1198
|
-
}
|
|
1199
|
-
string accept = info[2].As<Napi::String>().Utf8Value();
|
|
1200
|
-
|
|
1201
|
-
if (!info[3].IsString()) {
|
|
1202
|
-
Napi::TypeError::New(env, "from_uri must be string.").ThrowAsJavaScriptException();
|
|
875
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
1203
876
|
return env.Null();
|
|
1204
877
|
}
|
|
1205
|
-
string
|
|
1206
|
-
|
|
1207
|
-
if (!info[4].IsString()) {
|
|
1208
|
-
Napi::TypeError::New(env, "to_uri must be string.").ThrowAsJavaScriptException();
|
|
1209
|
-
return env.Null();
|
|
1210
|
-
}
|
|
1211
|
-
string to_uri = info[4].As<Napi::String>().Utf8Value();
|
|
1212
|
-
|
|
1213
|
-
if (!info[5].IsString()) {
|
|
1214
|
-
Napi::TypeError::New(env, "request_uri must be string.").ThrowAsJavaScriptException();
|
|
1215
|
-
return env.Null();
|
|
1216
|
-
}
|
|
1217
|
-
string request_uri = info[5].As<Napi::String>().Utf8Value();
|
|
1218
|
-
|
|
1219
|
-
string proxy_uri = string("");
|
|
1220
|
-
if (info.Length() > 6) {
|
|
1221
|
-
if (!info[6].IsString()) {
|
|
1222
|
-
Napi::TypeError::New(env, "proxy_uri must be string.").ThrowAsJavaScriptException();
|
|
1223
|
-
return env.Null();
|
|
1224
|
-
}
|
|
1225
|
-
proxy_uri = info[6].As<Napi::String>().Utf8Value();
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
string realm = string("");
|
|
1229
|
-
string user = string("");
|
|
1230
|
-
string pass = string("");
|
|
1231
|
-
|
|
1232
|
-
if (info.Length() > 7) {
|
|
1233
|
-
if(info.Length() < 10) {
|
|
1234
|
-
Napi::TypeError::New(env, "missing credentials. you must provide realm, user, pass.").ThrowAsJavaScriptException();
|
|
1235
|
-
return env.Null();
|
|
1236
|
-
}
|
|
1237
|
-
|
|
1238
|
-
if (!info[7].IsString()) {
|
|
1239
|
-
Napi::TypeError::New(env, "realm must be string").ThrowAsJavaScriptException();
|
|
1240
|
-
return env.Null();
|
|
1241
|
-
}
|
|
1242
|
-
realm = info[7].As<Napi::String>().Utf8Value();
|
|
1243
|
-
|
|
1244
|
-
if (!info[8].IsString()) {
|
|
1245
|
-
Napi::TypeError::New(env, "user must be string").ThrowAsJavaScriptException();
|
|
1246
|
-
return env.Null();
|
|
1247
|
-
}
|
|
1248
|
-
user = info[8].As<Napi::String>().Utf8Value();
|
|
1249
|
-
|
|
1250
|
-
if (!info[9].IsString()) {
|
|
1251
|
-
Napi::TypeError::New(env, "pass must be string").ThrowAsJavaScriptException();
|
|
1252
|
-
return env.Null();
|
|
1253
|
-
}
|
|
1254
|
-
pass = info[9].As<Napi::String>().Utf8Value();
|
|
1255
|
-
}
|
|
878
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
1256
879
|
|
|
1257
880
|
long out_subscription_id;
|
|
1258
881
|
|
|
1259
|
-
int res = pjw_subscription_create(transport_id,
|
|
1260
|
-
proxy_uri[0] ? proxy_uri.c_str() : NULL,
|
|
1261
|
-
realm[0] ? realm.c_str() : NULL,
|
|
1262
|
-
user[0] ? user.c_str() : NULL,
|
|
1263
|
-
pass[0] ? pass.c_str() : NULL,
|
|
1264
|
-
&out_subscription_id);
|
|
882
|
+
int res = pjw_subscription_create(transport_id, json.c_str(), &out_subscription_id);
|
|
1265
883
|
|
|
1266
884
|
if(res != 0) {
|
|
1267
885
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -1274,8 +892,8 @@ Napi::Value subscription_create(const Napi::CallbackInfo& info) {
|
|
|
1274
892
|
Napi::Value subscription_subscribe(const Napi::CallbackInfo& info) {
|
|
1275
893
|
Napi::Env env = info.Env();
|
|
1276
894
|
|
|
1277
|
-
if (info.Length()
|
|
1278
|
-
Napi::Error::New(env, "Wrong number of arguments. Expected: subscription_id,
|
|
895
|
+
if (info.Length() != 2) {
|
|
896
|
+
Napi::Error::New(env, "Wrong number of arguments. Expected: subscription_id, params").ThrowAsJavaScriptException();
|
|
1279
897
|
return env.Null();
|
|
1280
898
|
}
|
|
1281
899
|
|
|
@@ -1284,23 +902,14 @@ Napi::Value subscription_subscribe(const Napi::CallbackInfo& info) {
|
|
|
1284
902
|
return env.Null();
|
|
1285
903
|
}
|
|
1286
904
|
int subscription_id = info[0].As<Napi::Number>().Int32Value();
|
|
1287
|
-
|
|
1288
|
-
if (!info[1].
|
|
1289
|
-
Napi::TypeError::New(env, "
|
|
905
|
+
|
|
906
|
+
if (!info[1].IsString()) {
|
|
907
|
+
Napi::TypeError::New(env, "Wrong argument type: params must be a JSON string.").ThrowAsJavaScriptException();
|
|
1290
908
|
return env.Null();
|
|
1291
909
|
}
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
string additional_headers = string("");
|
|
1295
|
-
if (info.Length() > 2) {
|
|
1296
|
-
if (!info[2].IsString()) {
|
|
1297
|
-
Napi::TypeError::New(env, "additional_headers must be string.").ThrowAsJavaScriptException();
|
|
1298
|
-
return env.Null();
|
|
1299
|
-
}
|
|
1300
|
-
additional_headers = info[2].As<Napi::String>().Utf8Value();
|
|
1301
|
-
}
|
|
910
|
+
const string json = info[1].As<Napi::String>().Utf8Value();
|
|
1302
911
|
|
|
1303
|
-
int res = pjw_subscription_subscribe(subscription_id,
|
|
912
|
+
int res = pjw_subscription_subscribe(subscription_id, json.c_str());
|
|
1304
913
|
|
|
1305
914
|
if(res != 0) {
|
|
1306
915
|
Napi::Error::New(env, pjw_get_error()).ThrowAsJavaScriptException();
|
|
@@ -1428,7 +1037,7 @@ Napi::Value shutdown_(const Napi::CallbackInfo& info) {
|
|
|
1428
1037
|
|
|
1429
1038
|
Napi::Object init(Napi::Env env, Napi::Object exports) {
|
|
1430
1039
|
int i = __pjw_init();
|
|
1431
|
-
|
|
1040
|
+
printf("__pjw_init res=%i\n", i);
|
|
1432
1041
|
|
|
1433
1042
|
exports.Set("start", Napi::Function::New(env, start));
|
|
1434
1043
|
|