@siphon-project/control 0.8.0 → 0.10.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 +6 -6
- package/dist/index.cjs +261 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +376 -25
- package/dist/index.d.ts +376 -25
- package/dist/index.js +260 -56
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -71,6 +71,8 @@ var RESYNC = "resync";
|
|
|
71
71
|
var DESCRIBE = "describe";
|
|
72
72
|
var SET_VAR = "set_var";
|
|
73
73
|
var GET_VAR = "get_var";
|
|
74
|
+
var REGISTRATIONS = "registrations";
|
|
75
|
+
var OUTBOUND_REGISTRATIONS = "outbound_registrations";
|
|
74
76
|
function encodeCommand(id, module, verb, target, args) {
|
|
75
77
|
const frame = { id, type: "command" };
|
|
76
78
|
if (module != null) {
|
|
@@ -81,10 +83,10 @@ function encodeCommand(id, module, verb, target, args) {
|
|
|
81
83
|
frame.args = args ?? null;
|
|
82
84
|
return JSON.stringify(frame);
|
|
83
85
|
}
|
|
84
|
-
function parseInboundFrame(
|
|
86
|
+
function parseInboundFrame(text2) {
|
|
85
87
|
let value;
|
|
86
88
|
try {
|
|
87
|
-
value = JSON.parse(
|
|
89
|
+
value = JSON.parse(text2);
|
|
88
90
|
} catch {
|
|
89
91
|
return null;
|
|
90
92
|
}
|
|
@@ -257,7 +259,7 @@ var Session = class {
|
|
|
257
259
|
return Promise.reject(ControlError.closed());
|
|
258
260
|
}
|
|
259
261
|
const id = `c-${this.nextId.value++}`;
|
|
260
|
-
const
|
|
262
|
+
const text2 = encodeCommand(id, module, verb, target, args);
|
|
261
263
|
return new Promise((resolve, reject) => {
|
|
262
264
|
const timer = setTimeout(() => {
|
|
263
265
|
this.pending.delete(id);
|
|
@@ -265,7 +267,7 @@ var Session = class {
|
|
|
265
267
|
}, this.replyTimeoutMs);
|
|
266
268
|
this.pending.set(id, { resolve, reject, timer });
|
|
267
269
|
try {
|
|
268
|
-
this.socket.send(
|
|
270
|
+
this.socket.send(text2);
|
|
269
271
|
} catch (error) {
|
|
270
272
|
this.pending.delete(id);
|
|
271
273
|
clearTimeout(timer);
|
|
@@ -273,8 +275,8 @@ var Session = class {
|
|
|
273
275
|
}
|
|
274
276
|
});
|
|
275
277
|
}
|
|
276
|
-
onMessage(
|
|
277
|
-
const frame = parseInboundFrame(
|
|
278
|
+
onMessage(text2) {
|
|
279
|
+
const frame = parseInboundFrame(text2);
|
|
278
280
|
if (frame === null) {
|
|
279
281
|
return;
|
|
280
282
|
}
|
|
@@ -643,6 +645,12 @@ function responseArgs(options) {
|
|
|
643
645
|
if (options.contentType !== void 0) {
|
|
644
646
|
args.content_type = options.contentType;
|
|
645
647
|
}
|
|
648
|
+
if (options.contactHost !== void 0) {
|
|
649
|
+
args.contact_host = options.contactHost;
|
|
650
|
+
}
|
|
651
|
+
if (options.contactUser !== void 0) {
|
|
652
|
+
args.contact_user = options.contactUser;
|
|
653
|
+
}
|
|
646
654
|
return args;
|
|
647
655
|
}
|
|
648
656
|
function insertTransferIdentity(args, identity) {
|
|
@@ -656,10 +664,42 @@ function insertTransferIdentity(args, identity) {
|
|
|
656
664
|
if (identity?.format !== void 0) args.format = identity.format;
|
|
657
665
|
if (identity?.headers !== void 0) args.headers = identity.headers;
|
|
658
666
|
}
|
|
667
|
+
function verifyServerToWire(verifyServer) {
|
|
668
|
+
if (verifyServer === void 0 || verifyServer === null) return void 0;
|
|
669
|
+
if (typeof verifyServer !== "boolean") {
|
|
670
|
+
throw new TypeError(`a target's "verifyServer" is a boolean`);
|
|
671
|
+
}
|
|
672
|
+
return verifyServer;
|
|
673
|
+
}
|
|
674
|
+
function contactHostToWire(contactHost) {
|
|
675
|
+
if (contactHost === void 0 || contactHost === null) return void 0;
|
|
676
|
+
if (typeof contactHost !== "string") {
|
|
677
|
+
throw new TypeError(`a target's "contactHost" is a hostname or IP address string`);
|
|
678
|
+
}
|
|
679
|
+
return contactHost;
|
|
680
|
+
}
|
|
681
|
+
function contactUserToWire(contactUser) {
|
|
682
|
+
if (contactUser === void 0 || contactUser === null) return void 0;
|
|
683
|
+
if (typeof contactUser !== "string") {
|
|
684
|
+
throw new TypeError(`a target's "contactUser" is a SIP URI user string`);
|
|
685
|
+
}
|
|
686
|
+
return contactUser;
|
|
687
|
+
}
|
|
688
|
+
function routeSetToWire(route) {
|
|
689
|
+
if (route === void 0 || route === null) return void 0;
|
|
690
|
+
if (!Array.isArray(route) || route.some((entry) => typeof entry !== "string")) {
|
|
691
|
+
throw new TypeError(`a target's "route" is an array of Route entry strings`);
|
|
692
|
+
}
|
|
693
|
+
return route.length === 0 ? void 0 : [...route];
|
|
694
|
+
}
|
|
659
695
|
function routeTargetToWire(target) {
|
|
660
696
|
if (typeof target === "string") {
|
|
661
697
|
return target;
|
|
662
698
|
}
|
|
699
|
+
const route = routeSetToWire(target.route);
|
|
700
|
+
const contactHost = contactHostToWire(target.contactHost);
|
|
701
|
+
const contactUser = contactUserToWire(target.contactUser);
|
|
702
|
+
const verifyServer = verifyServerToWire(target.verifyServer);
|
|
663
703
|
const object = { uri: target.uri };
|
|
664
704
|
if (target.nextHop !== void 0) {
|
|
665
705
|
object.next_hop = target.nextHop;
|
|
@@ -673,6 +713,18 @@ function routeTargetToWire(target) {
|
|
|
673
713
|
if (target.rerouteAfterProgress === true) {
|
|
674
714
|
object.reroute_after_progress = true;
|
|
675
715
|
}
|
|
716
|
+
if (route !== void 0) {
|
|
717
|
+
object.route = route;
|
|
718
|
+
}
|
|
719
|
+
if (contactHost !== void 0) {
|
|
720
|
+
object.contact_host = contactHost;
|
|
721
|
+
}
|
|
722
|
+
if (contactUser !== void 0) {
|
|
723
|
+
object.contact_user = contactUser;
|
|
724
|
+
}
|
|
725
|
+
if (verifyServer !== void 0) {
|
|
726
|
+
object.verify_server = verifyServer;
|
|
727
|
+
}
|
|
676
728
|
return object;
|
|
677
729
|
}
|
|
678
730
|
function stringValue(result) {
|
|
@@ -684,6 +736,10 @@ function stringValue(result) {
|
|
|
684
736
|
}
|
|
685
737
|
return null;
|
|
686
738
|
}
|
|
739
|
+
function text(result, name) {
|
|
740
|
+
const value = result?.[name];
|
|
741
|
+
return typeof value === "string" ? value : void 0;
|
|
742
|
+
}
|
|
687
743
|
function originateArgs(channel, to, media, options) {
|
|
688
744
|
return originateCommonArgs({ channel, to }, media, options);
|
|
689
745
|
}
|
|
@@ -717,6 +773,8 @@ function originateCommonArgs(args, media, options) {
|
|
|
717
773
|
if (options.timeout !== void 0) args.timeout = options.timeout;
|
|
718
774
|
if (options.onLost !== void 0) args.on_lost = options.onLost;
|
|
719
775
|
if (options.vars !== void 0) args.vars = options.vars;
|
|
776
|
+
if (options.contactHost !== void 0) args.contact_host = options.contactHost;
|
|
777
|
+
if (options.contactUser !== void 0) args.contact_user = options.contactUser;
|
|
720
778
|
if (options.sessionTimer !== void 0) {
|
|
721
779
|
const timer = {};
|
|
722
780
|
const { expires, minSe, refresher } = options.sessionTimer;
|
|
@@ -733,6 +791,22 @@ function dialTargetToWire(target) {
|
|
|
733
791
|
const nextHop = target.nextHop;
|
|
734
792
|
const headers = target.headers;
|
|
735
793
|
const to = target.to;
|
|
794
|
+
const route = routeSetToWire(target.route);
|
|
795
|
+
const contactHost = contactHostToWire(target.contactHost);
|
|
796
|
+
const contactUser = contactUserToWire(target.contactUser);
|
|
797
|
+
const rerouteAfterProgress = target.rerouteAfterProgress;
|
|
798
|
+
if (rerouteAfterProgress !== void 0 && typeof rerouteAfterProgress !== "boolean") {
|
|
799
|
+
throw new TypeError(`a dial target's "rerouteAfterProgress" is a boolean`);
|
|
800
|
+
}
|
|
801
|
+
const profile = target.profile ?? void 0;
|
|
802
|
+
if (profile !== void 0 && typeof profile !== "string") {
|
|
803
|
+
throw new TypeError(`a dial target's "profile" is a media profile name string`);
|
|
804
|
+
}
|
|
805
|
+
const offer = target.offer ?? void 0;
|
|
806
|
+
if (offer !== void 0 && offer !== "early" && offer !== "delayed") {
|
|
807
|
+
throw new TypeError(`a dial target's "offer" is "early" or "delayed"`);
|
|
808
|
+
}
|
|
809
|
+
const verifyServer = verifyServerToWire(target.verifyServer);
|
|
736
810
|
if (to !== void 0 && typeof to !== "string") {
|
|
737
811
|
throw new TypeError(`a dial target's "to" is a SIP URI string`);
|
|
738
812
|
}
|
|
@@ -747,23 +821,58 @@ function dialTargetToWire(target) {
|
|
|
747
821
|
`an aor target takes no "nextHop": each of its branches routes over its own contact's captured flow`
|
|
748
822
|
);
|
|
749
823
|
}
|
|
824
|
+
if (route !== void 0) {
|
|
825
|
+
throw new TypeError(
|
|
826
|
+
`an aor target takes no "route": each of its branches follows its own contact's Path`
|
|
827
|
+
);
|
|
828
|
+
}
|
|
750
829
|
const object2 = { aor };
|
|
751
830
|
if (headers !== void 0) object2.headers = headers;
|
|
752
831
|
if (to !== void 0) object2.to = to;
|
|
832
|
+
if (contactHost !== void 0) object2.contact_host = contactHost;
|
|
833
|
+
if (contactUser !== void 0) object2.contact_user = contactUser;
|
|
834
|
+
if (rerouteAfterProgress !== void 0) {
|
|
835
|
+
object2.reroute_after_progress = rerouteAfterProgress;
|
|
836
|
+
}
|
|
837
|
+
if (profile !== void 0) object2.profile = profile;
|
|
838
|
+
if (offer !== void 0) object2.offer = offer;
|
|
839
|
+
if (verifyServer !== void 0) object2.verify_server = verifyServer;
|
|
753
840
|
return object2;
|
|
754
841
|
}
|
|
755
842
|
if (typeof uri !== "string") {
|
|
756
843
|
throw new TypeError('a dial target requires a string "uri" or "aor"');
|
|
757
844
|
}
|
|
758
|
-
if (nextHop === void 0 && headers === void 0 && to === void 0)
|
|
845
|
+
if (nextHop === void 0 && headers === void 0 && to === void 0 && route === void 0 && contactHost === void 0 && contactUser === void 0 && rerouteAfterProgress === void 0 && profile === void 0 && offer === void 0 && verifyServer === void 0) {
|
|
846
|
+
return uri;
|
|
847
|
+
}
|
|
759
848
|
const object = { uri };
|
|
760
849
|
if (nextHop !== void 0) object.next_hop = nextHop;
|
|
761
850
|
if (headers !== void 0) object.headers = headers;
|
|
762
851
|
if (to !== void 0) object.to = to;
|
|
852
|
+
if (route !== void 0) object.route = route;
|
|
853
|
+
if (contactHost !== void 0) object.contact_host = contactHost;
|
|
854
|
+
if (contactUser !== void 0) object.contact_user = contactUser;
|
|
855
|
+
if (rerouteAfterProgress !== void 0) {
|
|
856
|
+
object.reroute_after_progress = rerouteAfterProgress;
|
|
857
|
+
}
|
|
858
|
+
if (profile !== void 0) object.profile = profile;
|
|
859
|
+
if (offer !== void 0) object.offer = offer;
|
|
860
|
+
if (verifyServer !== void 0) object.verify_server = verifyServer;
|
|
763
861
|
return object;
|
|
764
862
|
}
|
|
765
863
|
function dialArgs(targets, options) {
|
|
766
864
|
const args = { targets: targets.map(dialTargetToWire) };
|
|
865
|
+
const targetOffer = targets.some(
|
|
866
|
+
(target) => target.offer !== void 0
|
|
867
|
+
);
|
|
868
|
+
if ((options?.offer !== void 0 || targetOffer) && options?.onAnswer !== "bridge") {
|
|
869
|
+
throw new TypeError(
|
|
870
|
+
`dial "offer" requires onAnswer: "bridge" \u2014 a connecting dial's branches carry the caller's own offer, and siphon refuses it there`
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
if (options?.offer !== void 0 && options.offer !== "early" && options.offer !== "delayed") {
|
|
874
|
+
throw new TypeError('dial "offer" is "early" or "delayed"');
|
|
875
|
+
}
|
|
767
876
|
if (!options) return args;
|
|
768
877
|
if (options.strategy !== void 0) args.strategy = options.strategy;
|
|
769
878
|
if (options.timeout !== void 0) args.timeout = options.timeout;
|
|
@@ -782,6 +891,13 @@ function dialArgs(targets, options) {
|
|
|
782
891
|
}
|
|
783
892
|
if (options.onAnswer !== void 0) args.on_answer = options.onAnswer;
|
|
784
893
|
if (options.ringback !== void 0) args.ringback = options.ringback;
|
|
894
|
+
if (options.offer !== void 0) args.offer = options.offer;
|
|
895
|
+
if (options.callerContactHost !== void 0) {
|
|
896
|
+
args.caller_contact_host = options.callerContactHost;
|
|
897
|
+
}
|
|
898
|
+
if (options.callerContactUser !== void 0) {
|
|
899
|
+
args.caller_contact_user = options.callerContactUser;
|
|
900
|
+
}
|
|
785
901
|
return args;
|
|
786
902
|
}
|
|
787
903
|
function branchList(value) {
|
|
@@ -924,6 +1040,12 @@ var Call = class {
|
|
|
924
1040
|
if (options?.wsUri !== void 0) {
|
|
925
1041
|
args.ws_uri = options.wsUri;
|
|
926
1042
|
}
|
|
1043
|
+
if (options?.contactHost !== void 0) {
|
|
1044
|
+
args.contact_host = options.contactHost;
|
|
1045
|
+
}
|
|
1046
|
+
if (options?.contactUser !== void 0) {
|
|
1047
|
+
args.contact_user = options.contactUser;
|
|
1048
|
+
}
|
|
927
1049
|
await this.sip(SipVerb.Answer, args);
|
|
928
1050
|
}
|
|
929
1051
|
/**
|
|
@@ -935,8 +1057,15 @@ var Call = class {
|
|
|
935
1057
|
* then {@link Call.answer}; open an early-media path with
|
|
936
1058
|
* {@link Call.progress}.
|
|
937
1059
|
*/
|
|
938
|
-
async ring(reason) {
|
|
939
|
-
|
|
1060
|
+
async ring(reason, options) {
|
|
1061
|
+
const args = reason !== void 0 ? { reason } : {};
|
|
1062
|
+
if (options?.contactHost !== void 0) {
|
|
1063
|
+
args.contact_host = options.contactHost;
|
|
1064
|
+
}
|
|
1065
|
+
if (options?.contactUser !== void 0) {
|
|
1066
|
+
args.contact_user = options.contactUser;
|
|
1067
|
+
}
|
|
1068
|
+
await this.sip(SipVerb.Ring, args);
|
|
940
1069
|
}
|
|
941
1070
|
/**
|
|
942
1071
|
* Send a UAS 1xx, optionally opening an early-media path with SDP (default
|
|
@@ -1068,7 +1197,7 @@ var Call = class {
|
|
|
1068
1197
|
*
|
|
1069
1198
|
* `targets` is a non-empty list of carriers tried cheapest-first: each entry
|
|
1070
1199
|
* is a bare URI string or a {@link RouteTargetObject}
|
|
1071
|
-
* (`{uri, nextHop?, headers?, timeout?, rerouteAfterProgress?}`). A target
|
|
1200
|
+
* (`{uri, nextHop?, headers?, timeout?, rerouteAfterProgress?, route?, contactHost?, contactUser?}`). A target
|
|
1072
1201
|
* that has shown progress keeps the call past its `timeout` unless it sets
|
|
1073
1202
|
* `rerouteAfterProgress`. `strategy` defaults to
|
|
1074
1203
|
* `"sequential"` (v1 supports only sequential/single — anything else rejects
|
|
@@ -1079,7 +1208,7 @@ var Call = class {
|
|
|
1079
1208
|
* empty / invalid `targets` list rejects with `code === "bad_request"`; a call
|
|
1080
1209
|
* that is already gone rejects with `code === "not_found"`.
|
|
1081
1210
|
*/
|
|
1082
|
-
async route(targets, strategy = "sequential", headers) {
|
|
1211
|
+
async route(targets, strategy = "sequential", headers, options) {
|
|
1083
1212
|
const args = {
|
|
1084
1213
|
targets: targets.map(routeTargetToWire),
|
|
1085
1214
|
strategy
|
|
@@ -1087,6 +1216,12 @@ var Call = class {
|
|
|
1087
1216
|
if (headers !== void 0) {
|
|
1088
1217
|
args.headers = headers;
|
|
1089
1218
|
}
|
|
1219
|
+
if (options?.callerContactHost !== void 0) {
|
|
1220
|
+
args.caller_contact_host = options.callerContactHost;
|
|
1221
|
+
}
|
|
1222
|
+
if (options?.callerContactUser !== void 0) {
|
|
1223
|
+
args.caller_contact_user = options.callerContactUser;
|
|
1224
|
+
}
|
|
1090
1225
|
return this.sip(SipVerb.Route, args);
|
|
1091
1226
|
}
|
|
1092
1227
|
/**
|
|
@@ -1145,7 +1280,7 @@ var Call = class {
|
|
|
1145
1280
|
*/
|
|
1146
1281
|
async dial(targets, options) {
|
|
1147
1282
|
const result = await this.sip(SipVerb.Dial, dialArgs(targets, options));
|
|
1148
|
-
const
|
|
1283
|
+
const text2 = (name) => {
|
|
1149
1284
|
const value = result?.[name];
|
|
1150
1285
|
return typeof value === "string" ? value : void 0;
|
|
1151
1286
|
};
|
|
@@ -1156,17 +1291,21 @@ var Call = class {
|
|
|
1156
1291
|
return {
|
|
1157
1292
|
// The server echoes the channel back; fall back to the one addressed
|
|
1158
1293
|
// rather than returning an empty id.
|
|
1159
|
-
channel:
|
|
1294
|
+
channel: text2("channel") ?? this.channelId,
|
|
1160
1295
|
targets: count("targets"),
|
|
1161
|
-
strategy:
|
|
1296
|
+
strategy: text2("strategy"),
|
|
1162
1297
|
timeout: count("timeout"),
|
|
1163
|
-
onAnswer:
|
|
1164
|
-
groupId:
|
|
1298
|
+
onAnswer: text2("on_answer"),
|
|
1299
|
+
groupId: text2("group_id"),
|
|
1165
1300
|
totalTimeout: count("total_timeout"),
|
|
1166
1301
|
ringback: (() => {
|
|
1167
1302
|
const value = result?.ringback;
|
|
1168
1303
|
return typeof value === "string" || typeof value === "boolean" ? value : void 0;
|
|
1169
1304
|
})(),
|
|
1305
|
+
offer: (() => {
|
|
1306
|
+
const value = result?.offer;
|
|
1307
|
+
return value === "early" || value === "delayed" ? value : void 0;
|
|
1308
|
+
})(),
|
|
1170
1309
|
branches: branchList(result?.branches)
|
|
1171
1310
|
};
|
|
1172
1311
|
}
|
|
@@ -1466,13 +1605,13 @@ var Call = class {
|
|
|
1466
1605
|
SipVerb.RecordStart,
|
|
1467
1606
|
recordStartArgs(options)
|
|
1468
1607
|
);
|
|
1469
|
-
const
|
|
1608
|
+
const text2 = (name) => {
|
|
1470
1609
|
const value = result?.[name];
|
|
1471
1610
|
return typeof value === "string" ? value : void 0;
|
|
1472
1611
|
};
|
|
1473
1612
|
return {
|
|
1474
|
-
channel:
|
|
1475
|
-
recordingId:
|
|
1613
|
+
channel: text2("channel") ?? this.channelId,
|
|
1614
|
+
recordingId: text2("recording_id")
|
|
1476
1615
|
};
|
|
1477
1616
|
}
|
|
1478
1617
|
/**
|
|
@@ -1591,6 +1730,25 @@ var SipFacade = class {
|
|
|
1591
1730
|
);
|
|
1592
1731
|
this.dispatch(call);
|
|
1593
1732
|
}
|
|
1733
|
+
/**
|
|
1734
|
+
* Open the event queue of a call this client is placing, before its
|
|
1735
|
+
* `originate` goes out: siphon sends no `StasisStart` for it, and its first
|
|
1736
|
+
* event can overtake the reply. `null` when the channel is already live here,
|
|
1737
|
+
* which must not be taken over.
|
|
1738
|
+
*/
|
|
1739
|
+
openChannel(channel) {
|
|
1740
|
+
if (this.channels.has(channel)) {
|
|
1741
|
+
return null;
|
|
1742
|
+
}
|
|
1743
|
+
const queue = new AsyncQueue();
|
|
1744
|
+
this.channels.set(channel, queue);
|
|
1745
|
+
return queue;
|
|
1746
|
+
}
|
|
1747
|
+
/** Close a channel {@link SipFacade.openChannel} opened for a refused originate. */
|
|
1748
|
+
closeChannel(channel) {
|
|
1749
|
+
this.channels.get(channel)?.close();
|
|
1750
|
+
this.channels.delete(channel);
|
|
1751
|
+
}
|
|
1594
1752
|
route(channel, event) {
|
|
1595
1753
|
this.channels.get(channel)?.push(event);
|
|
1596
1754
|
}
|
|
@@ -1658,13 +1816,52 @@ var SipClient = class _SipClient {
|
|
|
1658
1816
|
describe() {
|
|
1659
1817
|
return this.client.describe();
|
|
1660
1818
|
}
|
|
1819
|
+
/**
|
|
1820
|
+
* Everything the registrar holds now and the `seq` it is current to
|
|
1821
|
+
* (`registrations`; the app must subscribe to `registration`). Fetches every
|
|
1822
|
+
* page and merges them, keeping the first page's `seq`. Ask on connecting
|
|
1823
|
+
* and whenever a `RegistrationChanged` `seq` skips a number: replace your
|
|
1824
|
+
* copy with the reply and apply only events numbered above it.
|
|
1825
|
+
*/
|
|
1826
|
+
async registrations() {
|
|
1827
|
+
return this.everyPage(REGISTRATIONS);
|
|
1828
|
+
}
|
|
1829
|
+
/**
|
|
1830
|
+
* Every outbound registration's state and its `seq`
|
|
1831
|
+
* (`outbound_registrations`; the app must subscribe to `outbound_registration`).
|
|
1832
|
+
* Fetches every page, as {@link SipClient.registrations} does.
|
|
1833
|
+
*/
|
|
1834
|
+
async outboundRegistrations() {
|
|
1835
|
+
return this.everyPage(OUTBOUND_REGISTRATIONS);
|
|
1836
|
+
}
|
|
1837
|
+
async everyPage(verb) {
|
|
1838
|
+
const whole = await this.client.command(null, verb, null, null);
|
|
1839
|
+
let after = whole.next ?? null;
|
|
1840
|
+
while (after !== null) {
|
|
1841
|
+
const page = await this.client.command(null, verb, null, { after });
|
|
1842
|
+
whole.registrations.push(...page.registrations);
|
|
1843
|
+
const next = page.next ?? null;
|
|
1844
|
+
if (next !== null && next <= after) {
|
|
1845
|
+
throw new Error(`${verb}: the page after ${after} named ${next} as the next`);
|
|
1846
|
+
}
|
|
1847
|
+
after = next;
|
|
1848
|
+
}
|
|
1849
|
+
whole.next = null;
|
|
1850
|
+
return whole;
|
|
1851
|
+
}
|
|
1661
1852
|
/**
|
|
1662
1853
|
* Place an outbound call under a caller-supplied channel id.
|
|
1663
1854
|
*
|
|
1664
1855
|
* The one verb that *creates* a channel rather than addressing one, which is
|
|
1665
1856
|
* why it lives here and not on {@link Call}. It resolves as soon as the
|
|
1666
|
-
* INVITE is on the wire — the call is `calling
|
|
1667
|
-
*
|
|
1857
|
+
* INVITE is on the wire — the call is `calling` — to the {@link Call} it
|
|
1858
|
+
* placed: the answer, failure or timeout arrives on {@link Call.nextEvent},
|
|
1859
|
+
* exactly as a handed-over call's does, and `hangup` CANCELs or BYEs it.
|
|
1860
|
+
*
|
|
1861
|
+
* siphon sends no `StasisStart` for a channel its controller created, so the
|
|
1862
|
+
* channel is opened here before the command goes out (a fast 180 can
|
|
1863
|
+
* overtake the reply). An id still live on this client rejects with
|
|
1864
|
+
* `code === "conflict"` before anything is sent.
|
|
1668
1865
|
*
|
|
1669
1866
|
* ```ts
|
|
1670
1867
|
* const call = await client.originate(
|
|
@@ -1676,23 +1873,8 @@ var SipClient = class _SipClient {
|
|
|
1676
1873
|
* ```
|
|
1677
1874
|
*/
|
|
1678
1875
|
async originate(channel, to, media, options) {
|
|
1679
|
-
const result = await this.
|
|
1680
|
-
|
|
1681
|
-
"originate",
|
|
1682
|
-
null,
|
|
1683
|
-
originateArgs(channel, to, media, options)
|
|
1684
|
-
);
|
|
1685
|
-
const text = (name) => {
|
|
1686
|
-
const value = result?.[name];
|
|
1687
|
-
return typeof value === "string" ? value : void 0;
|
|
1688
|
-
};
|
|
1689
|
-
return {
|
|
1690
|
-
// The server echoes the id back; fall back to the one we asked for
|
|
1691
|
-
// rather than returning an empty channel a caller cannot address.
|
|
1692
|
-
channel: text("channel") ?? channel,
|
|
1693
|
-
callId: text("call_id"),
|
|
1694
|
-
sipCallId: text("sip_call_id")
|
|
1695
|
-
};
|
|
1876
|
+
const { result, queue } = await this.place(channel, originateArgs(channel, to, media, options));
|
|
1877
|
+
return this.placedCall(channel, text(result, "call_id"), text(result, "sip_call_id"), result, queue);
|
|
1696
1878
|
}
|
|
1697
1879
|
/**
|
|
1698
1880
|
* Ring every phone registered at `aor` under a caller-supplied channel id —
|
|
@@ -1727,29 +1909,51 @@ var SipClient = class _SipClient {
|
|
|
1727
1909
|
* ```
|
|
1728
1910
|
*/
|
|
1729
1911
|
async originateAor(channel, aor, media, options, ring) {
|
|
1730
|
-
const result = await this.
|
|
1731
|
-
|
|
1732
|
-
"originate",
|
|
1733
|
-
null,
|
|
1912
|
+
const { result, queue } = await this.place(
|
|
1913
|
+
channel,
|
|
1734
1914
|
originateAorArgs(channel, aor, media, options, ring)
|
|
1735
1915
|
);
|
|
1736
|
-
const
|
|
1737
|
-
|
|
1738
|
-
return typeof value === "string" ? value : void 0;
|
|
1739
|
-
};
|
|
1740
|
-
const count = (name) => {
|
|
1741
|
-
const value = result?.[name];
|
|
1742
|
-
return typeof value === "number" ? value : void 0;
|
|
1743
|
-
};
|
|
1916
|
+
const groupId = text(result, "group_id");
|
|
1917
|
+
const totalTimeout = result?.total_timeout;
|
|
1744
1918
|
return {
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1919
|
+
// The server echoes the id back; fall back to the one we asked for
|
|
1920
|
+
// rather than returning an empty channel a caller cannot address.
|
|
1921
|
+
channel: text(result, "channel") ?? channel,
|
|
1922
|
+
// Until a phone answers, the group stands in for the call, as its events say.
|
|
1923
|
+
call: this.placedCall(channel, groupId, groupId, result, queue),
|
|
1924
|
+
groupId,
|
|
1925
|
+
aor: text(result, "aor"),
|
|
1926
|
+
strategy: text(result, "strategy"),
|
|
1927
|
+
totalTimeout: typeof totalTimeout === "number" ? totalTimeout : void 0,
|
|
1750
1928
|
branches: branchList(result?.branches) ?? []
|
|
1751
1929
|
};
|
|
1752
1930
|
}
|
|
1931
|
+
/** Open `channel`, send the originate, and close it again if the server refuses. */
|
|
1932
|
+
async place(channel, args) {
|
|
1933
|
+
const queue = this.facade.openChannel(channel);
|
|
1934
|
+
if (queue === null) {
|
|
1935
|
+
throw ControlError.command("conflict", `channel ${channel} is already live on this client`);
|
|
1936
|
+
}
|
|
1937
|
+
try {
|
|
1938
|
+
const result = await this.client.command(MODULE_SIP, "originate", null, args);
|
|
1939
|
+
return { result, queue };
|
|
1940
|
+
} catch (error) {
|
|
1941
|
+
this.facade.closeChannel(channel);
|
|
1942
|
+
throw error;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
placedCall(channel, callId, sipCallId, reply, queue) {
|
|
1946
|
+
return new Call(
|
|
1947
|
+
this.client.commander(),
|
|
1948
|
+
channel,
|
|
1949
|
+
callId ?? null,
|
|
1950
|
+
sipCallId ?? null,
|
|
1951
|
+
null,
|
|
1952
|
+
reply,
|
|
1953
|
+
false,
|
|
1954
|
+
queue
|
|
1955
|
+
);
|
|
1956
|
+
}
|
|
1753
1957
|
/** Send a raw command on any module (the generic escape hatch). */
|
|
1754
1958
|
command(module, verb, target, args) {
|
|
1755
1959
|
return this.client.command(module, verb, target, args);
|
|
@@ -1798,6 +2002,6 @@ var SipServer = class _SipServer {
|
|
|
1798
2002
|
}
|
|
1799
2003
|
};
|
|
1800
2004
|
|
|
1801
|
-
export { Call, CallStream, ControlClient, ControlError, ControlServer, DESCRIBE, EventStream, GET_VAR, HELLO, MODULE_SIP, MODULE_SMPP, MODULE_SS7, PROTOCOL_VERSION, RESYNC, SET_VAR, SUBPROTOCOL, SipClient, SipServer, SipVerb, dialArgs, encodeCommand, isBridgeFinal, isDialFinal, isTransferFinal, originateAorArgs, originateArgs, parseInboundFrame, recordStartArgs, recordStopArgs, sipEventKind, transferOutcome };
|
|
2005
|
+
export { Call, CallStream, ControlClient, ControlError, ControlServer, DESCRIBE, EventStream, GET_VAR, HELLO, MODULE_SIP, MODULE_SMPP, MODULE_SS7, OUTBOUND_REGISTRATIONS, PROTOCOL_VERSION, REGISTRATIONS, RESYNC, SET_VAR, SUBPROTOCOL, SipClient, SipServer, SipVerb, dialArgs, encodeCommand, isBridgeFinal, isDialFinal, isTransferFinal, originateAorArgs, originateArgs, parseInboundFrame, recordStartArgs, recordStopArgs, sipEventKind, transferOutcome };
|
|
1802
2006
|
//# sourceMappingURL=index.js.map
|
|
1803
2007
|
//# sourceMappingURL=index.js.map
|