@siphon-project/control 0.9.0 → 0.10.1
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 +5 -5
- package/dist/index.cjs +155 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +337 -6
- package/dist/index.d.ts +337 -6
- package/dist/index.js +154 -6
- 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) {
|
|
@@ -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,6 +664,27 @@ 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
|
+
}
|
|
659
688
|
function routeSetToWire(route) {
|
|
660
689
|
if (route === void 0 || route === null) return void 0;
|
|
661
690
|
if (!Array.isArray(route) || route.some((entry) => typeof entry !== "string")) {
|
|
@@ -668,6 +697,9 @@ function routeTargetToWire(target) {
|
|
|
668
697
|
return target;
|
|
669
698
|
}
|
|
670
699
|
const route = routeSetToWire(target.route);
|
|
700
|
+
const contactHost = contactHostToWire(target.contactHost);
|
|
701
|
+
const contactUser = contactUserToWire(target.contactUser);
|
|
702
|
+
const verifyServer = verifyServerToWire(target.verifyServer);
|
|
671
703
|
const object = { uri: target.uri };
|
|
672
704
|
if (target.nextHop !== void 0) {
|
|
673
705
|
object.next_hop = target.nextHop;
|
|
@@ -684,6 +716,15 @@ function routeTargetToWire(target) {
|
|
|
684
716
|
if (route !== void 0) {
|
|
685
717
|
object.route = route;
|
|
686
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
|
+
}
|
|
687
728
|
return object;
|
|
688
729
|
}
|
|
689
730
|
function stringValue(result) {
|
|
@@ -732,6 +773,8 @@ function originateCommonArgs(args, media, options) {
|
|
|
732
773
|
if (options.timeout !== void 0) args.timeout = options.timeout;
|
|
733
774
|
if (options.onLost !== void 0) args.on_lost = options.onLost;
|
|
734
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;
|
|
735
778
|
if (options.sessionTimer !== void 0) {
|
|
736
779
|
const timer = {};
|
|
737
780
|
const { expires, minSe, refresher } = options.sessionTimer;
|
|
@@ -749,6 +792,21 @@ function dialTargetToWire(target) {
|
|
|
749
792
|
const headers = target.headers;
|
|
750
793
|
const to = target.to;
|
|
751
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);
|
|
752
810
|
if (to !== void 0 && typeof to !== "string") {
|
|
753
811
|
throw new TypeError(`a dial target's "to" is a SIP URI string`);
|
|
754
812
|
}
|
|
@@ -771,12 +829,20 @@ function dialTargetToWire(target) {
|
|
|
771
829
|
const object2 = { aor };
|
|
772
830
|
if (headers !== void 0) object2.headers = headers;
|
|
773
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;
|
|
774
840
|
return object2;
|
|
775
841
|
}
|
|
776
842
|
if (typeof uri !== "string") {
|
|
777
843
|
throw new TypeError('a dial target requires a string "uri" or "aor"');
|
|
778
844
|
}
|
|
779
|
-
if (nextHop === void 0 && headers === void 0 && to === void 0 && route === 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) {
|
|
780
846
|
return uri;
|
|
781
847
|
}
|
|
782
848
|
const object = { uri };
|
|
@@ -784,10 +850,29 @@ function dialTargetToWire(target) {
|
|
|
784
850
|
if (headers !== void 0) object.headers = headers;
|
|
785
851
|
if (to !== void 0) object.to = to;
|
|
786
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;
|
|
787
861
|
return object;
|
|
788
862
|
}
|
|
789
863
|
function dialArgs(targets, options) {
|
|
790
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
|
+
}
|
|
791
876
|
if (!options) return args;
|
|
792
877
|
if (options.strategy !== void 0) args.strategy = options.strategy;
|
|
793
878
|
if (options.timeout !== void 0) args.timeout = options.timeout;
|
|
@@ -806,6 +891,13 @@ function dialArgs(targets, options) {
|
|
|
806
891
|
}
|
|
807
892
|
if (options.onAnswer !== void 0) args.on_answer = options.onAnswer;
|
|
808
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
|
+
}
|
|
809
901
|
return args;
|
|
810
902
|
}
|
|
811
903
|
function branchList(value) {
|
|
@@ -948,6 +1040,12 @@ var Call = class {
|
|
|
948
1040
|
if (options?.wsUri !== void 0) {
|
|
949
1041
|
args.ws_uri = options.wsUri;
|
|
950
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
|
+
}
|
|
951
1049
|
await this.sip(SipVerb.Answer, args);
|
|
952
1050
|
}
|
|
953
1051
|
/**
|
|
@@ -959,8 +1057,15 @@ var Call = class {
|
|
|
959
1057
|
* then {@link Call.answer}; open an early-media path with
|
|
960
1058
|
* {@link Call.progress}.
|
|
961
1059
|
*/
|
|
962
|
-
async ring(reason) {
|
|
963
|
-
|
|
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);
|
|
964
1069
|
}
|
|
965
1070
|
/**
|
|
966
1071
|
* Send a UAS 1xx, optionally opening an early-media path with SDP (default
|
|
@@ -1092,7 +1197,7 @@ var Call = class {
|
|
|
1092
1197
|
*
|
|
1093
1198
|
* `targets` is a non-empty list of carriers tried cheapest-first: each entry
|
|
1094
1199
|
* is a bare URI string or a {@link RouteTargetObject}
|
|
1095
|
-
* (`{uri, nextHop?, headers?, timeout?, rerouteAfterProgress?, route?}`). A target
|
|
1200
|
+
* (`{uri, nextHop?, headers?, timeout?, rerouteAfterProgress?, route?, contactHost?, contactUser?}`). A target
|
|
1096
1201
|
* that has shown progress keeps the call past its `timeout` unless it sets
|
|
1097
1202
|
* `rerouteAfterProgress`. `strategy` defaults to
|
|
1098
1203
|
* `"sequential"` (v1 supports only sequential/single — anything else rejects
|
|
@@ -1103,7 +1208,7 @@ var Call = class {
|
|
|
1103
1208
|
* empty / invalid `targets` list rejects with `code === "bad_request"`; a call
|
|
1104
1209
|
* that is already gone rejects with `code === "not_found"`.
|
|
1105
1210
|
*/
|
|
1106
|
-
async route(targets, strategy = "sequential", headers) {
|
|
1211
|
+
async route(targets, strategy = "sequential", headers, options) {
|
|
1107
1212
|
const args = {
|
|
1108
1213
|
targets: targets.map(routeTargetToWire),
|
|
1109
1214
|
strategy
|
|
@@ -1111,6 +1216,12 @@ var Call = class {
|
|
|
1111
1216
|
if (headers !== void 0) {
|
|
1112
1217
|
args.headers = headers;
|
|
1113
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
|
+
}
|
|
1114
1225
|
return this.sip(SipVerb.Route, args);
|
|
1115
1226
|
}
|
|
1116
1227
|
/**
|
|
@@ -1191,6 +1302,10 @@ var Call = class {
|
|
|
1191
1302
|
const value = result?.ringback;
|
|
1192
1303
|
return typeof value === "string" || typeof value === "boolean" ? value : void 0;
|
|
1193
1304
|
})(),
|
|
1305
|
+
offer: (() => {
|
|
1306
|
+
const value = result?.offer;
|
|
1307
|
+
return value === "early" || value === "delayed" ? value : void 0;
|
|
1308
|
+
})(),
|
|
1194
1309
|
branches: branchList(result?.branches)
|
|
1195
1310
|
};
|
|
1196
1311
|
}
|
|
@@ -1701,6 +1816,39 @@ var SipClient = class _SipClient {
|
|
|
1701
1816
|
describe() {
|
|
1702
1817
|
return this.client.describe();
|
|
1703
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
|
+
}
|
|
1704
1852
|
/**
|
|
1705
1853
|
* Place an outbound call under a caller-supplied channel id.
|
|
1706
1854
|
*
|
|
@@ -1854,6 +2002,6 @@ var SipServer = class _SipServer {
|
|
|
1854
2002
|
}
|
|
1855
2003
|
};
|
|
1856
2004
|
|
|
1857
|
-
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 };
|
|
1858
2006
|
//# sourceMappingURL=index.js.map
|
|
1859
2007
|
//# sourceMappingURL=index.js.map
|