forked from onsip/SIP.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsip-core.js
11979 lines (11460 loc) · 514 KB
/
sip-core.js
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*!
*
* SIP version 0.15.3
* Copyright (c) 2014-2022 Junction Networks, Inc <http://www.onsip.com>
* Homepage: https://sipjs.com
* License: https://sipjs.com/license/
*
*
* ~~~SIP.js contains substantial portions of JsSIP under the following license~~~
* Homepage: http://jssip.net
* Copyright (c) 2012-2013 José Luis Millán - Versatica <http://www.versatica.com>
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* ~~~ end JsSIP license ~~~
*
*
*
*
*/
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define([], factory);
else if(typeof exports === 'object')
exports["SIP"] = factory();
else
root["SIP"] = factory();
})(this, function() {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
/******/ }
/******/ };
/******/
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/
/******/ // create a fake namespace object
/******/ // mode & 1: value is a module id, require it
/******/ // mode & 2: merge all properties of value into the ns
/******/ // mode & 4: return value when already ns object
/******/ // mode & 8|1: behave like require
/******/ __webpack_require__.t = function(value, mode) {
/******/ if(mode & 1) value = __webpack_require__(value);
/******/ if(mode & 8) return value;
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
/******/ var ns = Object.create(null);
/******/ __webpack_require__.r(ns);
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
/******/ return ns;
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 2);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */,
/* 1 */
/***/ (function(module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__extends", function() { return __extends; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__assign", function() { return __assign; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__rest", function() { return __rest; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__decorate", function() { return __decorate; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__param", function() { return __param; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__metadata", function() { return __metadata; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__awaiter", function() { return __awaiter; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__generator", function() { return __generator; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__exportStar", function() { return __exportStar; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__values", function() { return __values; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__read", function() { return __read; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spread", function() { return __spread; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__spreadArrays", function() { return __spreadArrays; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__await", function() { return __await; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncGenerator", function() { return __asyncGenerator; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncDelegator", function() { return __asyncDelegator; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__asyncValues", function() { return __asyncValues; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__makeTemplateObject", function() { return __makeTemplateObject; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importStar", function() { return __importStar; });
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "__importDefault", function() { return __importDefault; });
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
}
return __assign.apply(this, arguments);
}
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/***/ }),
/* 2 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* A core library implementing low level SIP protocol elements.
* @packageDocumentation
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = __webpack_require__(1);
// Directories
tslib_1.__exportStar(__webpack_require__(3), exports);
tslib_1.__exportStar(__webpack_require__(31), exports);
tslib_1.__exportStar(__webpack_require__(60), exports);
tslib_1.__exportStar(__webpack_require__(5), exports);
tslib_1.__exportStar(__webpack_require__(24), exports);
tslib_1.__exportStar(__webpack_require__(56), exports);
tslib_1.__exportStar(__webpack_require__(27), exports);
tslib_1.__exportStar(__webpack_require__(64), exports);
tslib_1.__exportStar(__webpack_require__(66), exports);
// Files
tslib_1.__exportStar(__webpack_require__(26), exports);
tslib_1.__exportStar(__webpack_require__(77), exports);
/***/ }),
/* 3 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = __webpack_require__(1);
tslib_1.__exportStar(__webpack_require__(4), exports);
tslib_1.__exportStar(__webpack_require__(23), exports);
tslib_1.__exportStar(__webpack_require__(55), exports);
/***/ }),
/* 4 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var messages_1 = __webpack_require__(5);
/**
* Dialog.
* @remarks
* A key concept for a user agent is that of a dialog. A dialog
* represents a peer-to-peer SIP relationship between two user agents
* that persists for some time. The dialog facilitates sequencing of
* messages between the user agents and proper routing of requests
* between both of them. The dialog represents a context in which to
* interpret SIP messages.
* https://tools.ietf.org/html/rfc3261#section-12
* @public
*/
var Dialog = /** @class */ (function () {
/**
* Dialog constructor.
* @param core - User agent core.
* @param dialogState - Initial dialog state.
*/
function Dialog(core, dialogState) {
this.core = core;
this.dialogState = dialogState;
this.core.dialogs.set(this.id, this);
}
/**
* When a UAC receives a response that establishes a dialog, it
* constructs the state of the dialog. This state MUST be maintained
* for the duration of the dialog.
* https://tools.ietf.org/html/rfc3261#section-12.1.2
* @param outgoingRequestMessage - Outgoing request message for dialog.
* @param incomingResponseMessage - Incoming response message creating dialog.
*/
Dialog.initialDialogStateForUserAgentClient = function (outgoingRequestMessage, incomingResponseMessage) {
// If the request was sent over TLS, and the Request-URI contained a
// SIPS URI, the "secure" flag is set to TRUE.
// https://tools.ietf.org/html/rfc3261#section-12.1.2
var secure = false; // FIXME: Currently no support for TLS.
// The route set MUST be set to the list of URIs in the Record-Route
// header field from the response, taken in reverse order and preserving
// all URI parameters. If no Record-Route header field is present in
// the response, the route set MUST be set to the empty set. This route
// set, even if empty, overrides any pre-existing route set for future
// requests in this dialog. The remote target MUST be set to the URI
// from the Contact header field of the response.
// https://tools.ietf.org/html/rfc3261#section-12.1.2
var routeSet = incomingResponseMessage.getHeaders("record-route").reverse();
var contact = incomingResponseMessage.parseHeader("contact");
if (!contact) { // TODO: Review to make sure this will never happen
throw new Error("Contact undefined.");
}
if (!(contact instanceof messages_1.NameAddrHeader)) {
throw new Error("Contact not instance of NameAddrHeader.");
}
var remoteTarget = contact.uri;
// The local sequence number MUST be set to the value of the sequence
// number in the CSeq header field of the request. The remote sequence
// number MUST be empty (it is established when the remote UA sends a
// request within the dialog). The call identifier component of the
// dialog ID MUST be set to the value of the Call-ID in the request.
// The local tag component of the dialog ID MUST be set to the tag in
// the From field in the request, and the remote tag component of the
// dialog ID MUST be set to the tag in the To field of the response. A
// UAC MUST be prepared to receive a response without a tag in the To
// field, in which case the tag is considered to have a value of null.
//
// This is to maintain backwards compatibility with RFC 2543, which
// did not mandate To tags.
//
// https://tools.ietf.org/html/rfc3261#section-12.1.2
var localSequenceNumber = outgoingRequestMessage.cseq;
var remoteSequenceNumber = undefined;
var callId = outgoingRequestMessage.callId;
var localTag = outgoingRequestMessage.fromTag;
var remoteTag = incomingResponseMessage.toTag;
if (!callId) { // TODO: Review to make sure this will never happen
throw new Error("Call id undefined.");
}
if (!localTag) { // TODO: Review to make sure this will never happen
throw new Error("From tag undefined.");
}
if (!remoteTag) { // TODO: Review to make sure this will never happen
throw new Error("To tag undefined."); // FIXME: No backwards compatibility with RFC 2543
}
// The remote URI MUST be set to the URI in the To field, and the local
// URI MUST be set to the URI in the From field.
// https://tools.ietf.org/html/rfc3261#section-12.1.2
if (!outgoingRequestMessage.from) { // TODO: Review to make sure this will never happen
throw new Error("From undefined.");
}
if (!outgoingRequestMessage.to) { // TODO: Review to make sure this will never happen
throw new Error("To undefined.");
}
var localURI = outgoingRequestMessage.from.uri;
var remoteURI = outgoingRequestMessage.to.uri;
// A dialog can also be in the "early" state, which occurs when it is
// created with a provisional response, and then transition to the
// "confirmed" state when a 2xx final response arrives.
// https://tools.ietf.org/html/rfc3261#section-12
if (!incomingResponseMessage.statusCode) {
throw new Error("Incoming response status code undefined.");
}
var early = incomingResponseMessage.statusCode < 200 ? true : false;
var dialogState = {
id: callId + localTag + remoteTag,
early: early,
callId: callId,
localTag: localTag,
remoteTag: remoteTag,
localSequenceNumber: localSequenceNumber,
remoteSequenceNumber: remoteSequenceNumber,
localURI: localURI,
remoteURI: remoteURI,
remoteTarget: remoteTarget,
routeSet: routeSet,
secure: secure
};
return dialogState;
};
/**
* The UAS then constructs the state of the dialog. This state MUST be
* maintained for the duration of the dialog.
* https://tools.ietf.org/html/rfc3261#section-12.1.1
* @param incomingRequestMessage - Incoming request message creating dialog.
* @param toTag - Tag in the To field in the response to the incoming request.
*/
Dialog.initialDialogStateForUserAgentServer = function (incomingRequestMessage, toTag, early) {
if (early === void 0) { early = false; }
// If the request arrived over TLS, and the Request-URI contained a SIPS
// URI, the "secure" flag is set to TRUE.
// https://tools.ietf.org/html/rfc3261#section-12.1.1
var secure = false; // FIXME: Currently no support for TLS.
// The route set MUST be set to the list of URIs in the Record-Route
// header field from the request, taken in order and preserving all URI
// parameters. If no Record-Route header field is present in the
// request, the route set MUST be set to the empty set. This route set,
// even if empty, overrides any pre-existing route set for future
// requests in this dialog. The remote target MUST be set to the URI
// from the Contact header field of the request.
// https://tools.ietf.org/html/rfc3261#section-12.1.1
var routeSet = incomingRequestMessage.getHeaders("record-route");
var contact = incomingRequestMessage.parseHeader("contact");
if (!contact) { // TODO: Review to make sure this will never happen
throw new Error("Contact undefined.");
}
if (!(contact instanceof messages_1.NameAddrHeader)) {
throw new Error("Contact not instance of NameAddrHeader.");
}
var remoteTarget = contact.uri;
// The remote sequence number MUST be set to the value of the sequence
// number in the CSeq header field of the request. The local sequence
// number MUST be empty. The call identifier component of the dialog ID
// MUST be set to the value of the Call-ID in the request. The local
// tag component of the dialog ID MUST be set to the tag in the To field
// in the response to the request (which always includes a tag), and the
// remote tag component of the dialog ID MUST be set to the tag from the
// From field in the request. A UAS MUST be prepared to receive a
// request without a tag in the From field, in which case the tag is
// considered to have a value of null.
//
// This is to maintain backwards compatibility with RFC 2543, which
// did not mandate From tags.
//
// https://tools.ietf.org/html/rfc3261#section-12.1.1
var remoteSequenceNumber = incomingRequestMessage.cseq;
var localSequenceNumber = undefined;
var callId = incomingRequestMessage.callId;
var localTag = toTag;
var remoteTag = incomingRequestMessage.fromTag;
// The remote URI MUST be set to the URI in the From field, and the
// local URI MUST be set to the URI in the To field.
// https://tools.ietf.org/html/rfc3261#section-12.1.1
var remoteURI = incomingRequestMessage.from.uri;
var localURI = incomingRequestMessage.to.uri;
var dialogState = {
id: callId + localTag + remoteTag,
early: early,
callId: callId,
localTag: localTag,
remoteTag: remoteTag,
localSequenceNumber: localSequenceNumber,
remoteSequenceNumber: remoteSequenceNumber,
localURI: localURI,
remoteURI: remoteURI,
remoteTarget: remoteTarget,
routeSet: routeSet,
secure: secure
};
return dialogState;
};
/** Destructor. */
Dialog.prototype.dispose = function () {
this.core.dialogs.delete(this.id);
};
Object.defineProperty(Dialog.prototype, "id", {
/**
* A dialog is identified at each UA with a dialog ID, which consists of
* a Call-ID value, a local tag and a remote tag. The dialog ID at each
* UA involved in the dialog is not the same. Specifically, the local
* tag at one UA is identical to the remote tag at the peer UA. The
* tags are opaque tokens that facilitate the generation of unique
* dialog IDs.
* https://tools.ietf.org/html/rfc3261#section-12
*/
get: function () {
return this.dialogState.id;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "early", {
/**
* A dialog can also be in the "early" state, which occurs when it is
* created with a provisional response, and then it transition to the
* "confirmed" state when a 2xx final response received or is sent.
*
* Note: RFC 3261 is concise on when a dialog is "confirmed", but it
* can be a point of confusion if an INVITE dialog is "confirmed" after
* a 2xx is sent or after receiving the ACK for the 2xx response.
* With careful reading it can be inferred a dialog is always is
* "confirmed" when the 2xx is sent (regardless of type of dialog).
* However a INVITE dialog does have additional considerations
* when it is confirmed but an ACK has not yet been received (in
* particular with regard to a callee sending BYE requests).
*/
get: function () {
return this.dialogState.early;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "callId", {
/** Call identifier component of the dialog id. */
get: function () {
return this.dialogState.callId;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "localTag", {
/** Local tag component of the dialog id. */
get: function () {
return this.dialogState.localTag;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "remoteTag", {
/** Remote tag component of the dialog id. */
get: function () {
return this.dialogState.remoteTag;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "localSequenceNumber", {
/** Local sequence number (used to order requests from the UA to its peer). */
get: function () {
return this.dialogState.localSequenceNumber;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "remoteSequenceNumber", {
/** Remote sequence number (used to order requests from its peer to the UA). */
get: function () {
return this.dialogState.remoteSequenceNumber;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "localURI", {
/** Local URI. */
get: function () {
return this.dialogState.localURI;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "remoteURI", {
/** Remote URI. */
get: function () {
return this.dialogState.remoteURI;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "remoteTarget", {
/** Remote target. */
get: function () {
return this.dialogState.remoteTarget;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "routeSet", {
/**
* Route set, which is an ordered list of URIs. The route set is the
* list of servers that need to be traversed to send a request to the peer.
*/
get: function () {
return this.dialogState.routeSet;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "secure", {
/**
* If the request was sent over TLS, and the Request-URI contained
* a SIPS URI, the "secure" flag is set to true. *NOT IMPLEMENTED*
*/
get: function () {
return this.dialogState.secure;
},
enumerable: true,
configurable: true
});
Object.defineProperty(Dialog.prototype, "userAgentCore", {
/** The user agent core servicing this dialog. */
get: function () {
return this.core;
},
enumerable: true,
configurable: true
});
/** Confirm the dialog. Only matters if dialog is currently early. */
Dialog.prototype.confirm = function () {
this.dialogState.early = false;
};
/**
* Requests sent within a dialog, as any other requests, are atomic. If
* a particular request is accepted by the UAS, all the state changes
* associated with it are performed. If the request is rejected, none
* of the state changes are performed.
*
* Note that some requests, such as INVITEs, affect several pieces of
* state.
*
* https://tools.ietf.org/html/rfc3261#section-12.2.2
* @param message - Incoming request message within this dialog.
*/
Dialog.prototype.receiveRequest = function (message) {
// ACK guard.
// By convention, the handling of ACKs is the responsibility
// the particular dialog implementation. For example, see SessionDialog.
// Furthermore, ACKs have same sequence number as the associated INVITE.
if (message.method === messages_1.C.ACK) {
return;
}
// If the remote sequence number was not empty, but the sequence number
// of the request is lower than the remote sequence number, the request
// is out of order and MUST be rejected with a 500 (Server Internal
// Error) response. If the remote sequence number was not empty, and
// the sequence number of the request is greater than the remote
// sequence number, the request is in order. It is possible for the
// CSeq sequence number to be higher than the remote sequence number by
// more than one. This is not an error condition, and a UAS SHOULD be
// prepared to receive and process requests with CSeq values more than
// one higher than the previous received request. The UAS MUST then set
// the remote sequence number to the value of the sequence number in the
// CSeq header field value in the request.
//
// If a proxy challenges a request generated by the UAC, the UAC has
// to resubmit the request with credentials. The resubmitted request
// will have a new CSeq number. The UAS will never see the first
// request, and thus, it will notice a gap in the CSeq number space.
// Such a gap does not represent any error condition.
//
// https://tools.ietf.org/html/rfc3261#section-12.2.2
if (this.remoteSequenceNumber) {
if (message.cseq <= this.remoteSequenceNumber) {
throw new Error("Out of sequence in dialog request. Did you forget to call sequenceGuard()?");
}
this.dialogState.remoteSequenceNumber = message.cseq;
}
// If the remote sequence number is empty, it MUST be set to the value
// of the sequence number in the CSeq header field value in the request.
// https://tools.ietf.org/html/rfc3261#section-12.2.2
if (!this.remoteSequenceNumber) {
this.dialogState.remoteSequenceNumber = message.cseq;
}
// When a UAS receives a target refresh request, it MUST replace the
// dialog's remote target URI with the URI from the Contact header field
// in that request, if present.
// https://tools.ietf.org/html/rfc3261#section-12.2.2
// Note: "target refresh request" processing delegated to sub-class.
};
/**
* If the dialog identifier in the 2xx response matches the dialog
* identifier of an existing dialog, the dialog MUST be transitioned to
* the "confirmed" state, and the route set for the dialog MUST be
* recomputed based on the 2xx response using the procedures of Section
* 12.2.1.2. Otherwise, a new dialog in the "confirmed" state MUST be
* constructed using the procedures of Section 12.1.2.
*
* Note that the only piece of state that is recomputed is the route
* set. Other pieces of state such as the highest sequence numbers
* (remote and local) sent within the dialog are not recomputed. The
* route set only is recomputed for backwards compatibility. RFC
* 2543 did not mandate mirroring of the Record-Route header field in
* a 1xx, only 2xx. However, we cannot update the entire state of
* the dialog, since mid-dialog requests may have been sent within
* the early dialog, modifying the sequence numbers, for example.
*
* https://tools.ietf.org/html/rfc3261#section-13.2.2.4
*/
Dialog.prototype.recomputeRouteSet = function (message) {
this.dialogState.routeSet = message.getHeaders("record-route").reverse();
};
/**
* A request within a dialog is constructed by using many of the
* components of the state stored as part of the dialog.
* https://tools.ietf.org/html/rfc3261#section-12.2.1.1
* @param method - Outgoing request method.
*/
Dialog.prototype.createOutgoingRequestMessage = function (method, options) {
// The URI in the To field of the request MUST be set to the remote URI
// from the dialog state. The tag in the To header field of the request
// MUST be set to the remote tag of the dialog ID. The From URI of the
// request MUST be set to the local URI from the dialog state. The tag
// in the From header field of the request MUST be set to the local tag
// of the dialog ID. If the value of the remote or local tags is null,
// the tag parameter MUST be omitted from the To or From header fields,
// respectively.
//
// Usage of the URI from the To and From fields in the original
// request within subsequent requests is done for backwards
// compatibility with RFC 2543, which used the URI for dialog
// identification. In this specification, only the tags are used for
// dialog identification. It is expected that mandatory reflection
// of the original To and From URI in mid-dialog requests will be
// deprecated in a subsequent revision of this specification.
// https://tools.ietf.org/html/rfc3261#section-12.2.1.1
var toUri = this.remoteURI;
var toTag = this.remoteTag;
var fromUri = this.localURI;
var fromTag = this.localTag;
// The Call-ID of the request MUST be set to the Call-ID of the dialog.
// Requests within a dialog MUST contain strictly monotonically
// increasing and contiguous CSeq sequence numbers (increasing-by-one)
// in each direction (excepting ACK and CANCEL of course, whose numbers
// equal the requests being acknowledged or cancelled). Therefore, if
// the local sequence number is not empty, the value of the local
// sequence number MUST be incremented by one, and this value MUST be
// placed into the CSeq header field. If the local sequence number is
// empty, an initial value MUST be chosen using the guidelines of
// Section 8.1.1.5. The method field in the CSeq header field value
// MUST match the method of the request.
// https://tools.ietf.org/html/rfc3261#section-12.2.1.1
var callId = this.callId;
var cseq;
if (options && options.cseq) {
cseq = options.cseq;
}
else if (!this.dialogState.localSequenceNumber) {
cseq = this.dialogState.localSequenceNumber = 1; // https://tools.ietf.org/html/rfc3261#section-8.1.1.5
}
else {
cseq = this.dialogState.localSequenceNumber += 1;
}
// The UAC uses the remote target and route set to build the Request-URI
// and Route header field of the request.
//
// If the route set is empty, the UAC MUST place the remote target URI
// into the Request-URI. The UAC MUST NOT add a Route header field to
// the request.
//
// If the route set is not empty, and the first URI in the route set
// contains the lr parameter (see Section 19.1.1), the UAC MUST place
// the remote target URI into the Request-URI and MUST include a Route
// header field containing the route set values in order, including all
// parameters.
//
// If the route set is not empty, and its first URI does not contain the
// lr parameter, the UAC MUST place the first URI from the route set
// into the Request-URI, stripping any parameters that are not allowed
// in a Request-URI. The UAC MUST add a Route header field containing
// the remainder of the route set values in order, including all
// parameters. The UAC MUST then place the remote target URI into the
// Route header field as the last value.
// https://tools.ietf.org/html/rfc3261#section-12.2.1.1
// The lr parameter, when present, indicates that the element
// responsible for this resource implements the routing mechanisms
// specified in this document. This parameter will be used in the
// URIs proxies place into Record-Route header field values, and
// may appear in the URIs in a pre-existing route set.
//
// This parameter is used to achieve backwards compatibility with
// systems implementing the strict-routing mechanisms of RFC 2543
// and the rfc2543bis drafts up to bis-05. An element preparing
// to send a request based on a URI not containing this parameter
// can assume the receiving element implements strict-routing and
// reformat the message to preserve the information in the
// Request-URI.
// https://tools.ietf.org/html/rfc3261#section-19.1.1
// NOTE: Not backwards compatible with RFC 2543 (no support for strict-routing).
var ruri = this.remoteTarget;
var routeSet = this.routeSet;
var extraHeaders = options && options.extraHeaders;
var body = options && options.body;
// The relative order of header fields with different field names is not
// significant. However, it is RECOMMENDED that header fields which are
// needed for proxy processing (Via, Route, Record-Route, Proxy-Require,
// Max-Forwards, and Proxy-Authorization, for example) appear towards
// the top of the message to facilitate rapid parsing.
// https://tools.ietf.org/html/rfc3261#section-7.3.1
var message = this.userAgentCore.makeOutgoingRequestMessage(method, ruri, fromUri, toUri, {
callId: callId,
cseq: cseq,
fromTag: fromTag,
toTag: toTag,
routeSet: routeSet
}, extraHeaders, body);
return message;
};
/**
* If the remote sequence number was not empty, but the sequence number
* of the request is lower than the remote sequence number, the request
* is out of order and MUST be rejected with a 500 (Server Internal
* Error) response.
* https://tools.ietf.org/html/rfc3261#section-12.2.2
* @param request - Incoming request to guard.
* @returns True if the program execution is to continue in the branch in question.
* Otherwise a 500 Server Internal Error was stateless sent and request processing must stop.
*/
Dialog.prototype.sequenceGuard = function (message) {
// ACK guard.
// By convention, handling of unexpected ACKs is responsibility
// the particular dialog implementation. For example, see SessionDialog.
// Furthermore, we cannot reply to an "out of sequence" ACK.
if (message.method === messages_1.C.ACK) {
return true;
}
// Note: We are rejecting on "less than or equal to" the remote
// sequence number (excepting ACK whose numbers equal the requests
// being acknowledged or cancelled), which is the correct thing to
// do in our case. The only time a request with the same sequence number
// will show up here if is a) it is a very late retransmission of a
// request we already handled or b) it is a different request with the
// same sequence number which would be violation of the standard.
// Request retransmissions are absorbed by the transaction layer,
// so any request with a duplicate sequence number getting here
// would have to be a retransmission after the transaction terminated
// or a broken request (with unique via branch value).
// Requests within a dialog MUST contain strictly monotonically
// increasing and contiguous CSeq sequence numbers (increasing-by-one)
// in each direction (excepting ACK and CANCEL of course, whose numbers
// equal the requests being acknowledged or cancelled). Therefore, if
// the local sequence number is not empty, the value of the local
// sequence number MUST be incremented by one, and this value MUST be
// placed into the CSeq header field.
// https://tools.ietf.org/html/rfc3261#section-12.2.1.1
if (this.remoteSequenceNumber && message.cseq <= this.remoteSequenceNumber) {
this.core.replyStateless(message, { statusCode: 500 });
return false;
}
return true;
};
return Dialog;
}());
exports.Dialog = Dialog;
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = __webpack_require__(1);
// Directories
tslib_1.__exportStar(__webpack_require__(6), exports);
// Files
tslib_1.__exportStar(__webpack_require__(8), exports);
tslib_1.__exportStar(__webpack_require__(19), exports);
tslib_1.__exportStar(__webpack_require__(11), exports);
tslib_1.__exportStar(__webpack_require__(10), exports);
tslib_1.__exportStar(__webpack_require__(9), exports);
tslib_1.__exportStar(__webpack_require__(17), exports);
tslib_1.__exportStar(__webpack_require__(13), exports);
tslib_1.__exportStar(__webpack_require__(18), exports);
tslib_1.__exportStar(__webpack_require__(22), exports);
tslib_1.__exportStar(__webpack_require__(14), exports);
tslib_1.__exportStar(__webpack_require__(15), exports);
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = __webpack_require__(1);
tslib_1.__exportStar(__webpack_require__(7), exports);