@signalwire/js 4.0.0-dev-20260803213546 → 4.0.0-dev-20260826210511
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/dist/browser.mjs +208 -7
- package/dist/browser.mjs.map +1 -1
- package/dist/browser.umd.js +208 -7
- package/dist/browser.umd.js.map +1 -1
- package/dist/index.cjs +208 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +110 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +208 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/browser.umd.js
CHANGED
|
@@ -14514,6 +14514,33 @@ function throwOnRPCError() {
|
|
|
14514
14514
|
});
|
|
14515
14515
|
}
|
|
14516
14516
|
|
|
14517
|
+
//#endregion
|
|
14518
|
+
//#region src/utils/unwrapVertoReply.ts
|
|
14519
|
+
/**
|
|
14520
|
+
* Unwrap a method's own reply from a `webrtc.verto` envelope.
|
|
14521
|
+
*
|
|
14522
|
+
* A control verb sent in-dialog comes back nested two levels deep:
|
|
14523
|
+
*
|
|
14524
|
+
* ```
|
|
14525
|
+
* { result: { node_id, code, result: { jsonrpc, id, result: <method payload> } } }
|
|
14526
|
+
* ```
|
|
14527
|
+
*
|
|
14528
|
+
* whereas the routed transport resolves the method payload directly under
|
|
14529
|
+
* `.result`. Readers want the latter shape, and the difference is silent when it
|
|
14530
|
+
* is wrong — `response.result.layouts` simply evaluates to `undefined` against the
|
|
14531
|
+
* envelope, so the data arrives, nothing throws, and the caller sees an empty
|
|
14532
|
+
* value. That exact failure produced an empty layout dropdown with a successful
|
|
14533
|
+
* request behind it.
|
|
14534
|
+
*
|
|
14535
|
+
* Accepting both shapes here keeps every reader indifferent to which transport
|
|
14536
|
+
* produced the response. Anything that is not a nested envelope (a plain ack, or
|
|
14537
|
+
* an already-unwrapped reply) passes through untouched.
|
|
14538
|
+
*/
|
|
14539
|
+
function unwrapVertoReply(response) {
|
|
14540
|
+
const inner = getValueFrom(response, "result.result");
|
|
14541
|
+
return inner && typeof inner === "object" && "result" in inner ? inner : response;
|
|
14542
|
+
}
|
|
14543
|
+
|
|
14517
14544
|
//#endregion
|
|
14518
14545
|
//#region src/managers/CallEventsManager.ts
|
|
14519
14546
|
var import_cjs$20 = require_cjs();
|
|
@@ -14706,9 +14733,10 @@ var CallEventsManager = class extends Destroyable {
|
|
|
14706
14733
|
updateLayouts() {
|
|
14707
14734
|
if (!this.selfId) return;
|
|
14708
14735
|
this.webRtcCallSession.executeMethod(this.selfId, "call.layout.list", {}).then((response) => {
|
|
14736
|
+
const { result } = unwrapVertoReply(response);
|
|
14709
14737
|
this._sessionState$.next({
|
|
14710
14738
|
...this._sessionState$.value,
|
|
14711
|
-
layouts:
|
|
14739
|
+
layouts: result.layouts
|
|
14712
14740
|
});
|
|
14713
14741
|
}).catch((error) => {
|
|
14714
14742
|
logger$22.error("[CallEventsManager] Error fetching layouts:", error);
|
|
@@ -16713,6 +16741,48 @@ const logger$16 = getLogger();
|
|
|
16713
16741
|
function resolveInviteNodeId(args) {
|
|
16714
16742
|
return args.isInvite && !args.reattach && !args.explicitNodeId ? "" : args.currentNodeId ?? "";
|
|
16715
16743
|
}
|
|
16744
|
+
/**
|
|
16745
|
+
* Surface the real outcome of a `webrtc.verto` reply.
|
|
16746
|
+
*
|
|
16747
|
+
* A webrtc.verto response nests several envelopes, each keyed by a verto-style
|
|
16748
|
+
* string `code` ("200" ok, "400"/etc. fail) rather than a JSON-RPC `error`. An outer
|
|
16749
|
+
* layer reports only whether the frame was delivered; an inner layer carries the op's
|
|
16750
|
+
* own outcome:
|
|
16751
|
+
*
|
|
16752
|
+
* response.result = { code:"200", result:{…} } ← delivery acknowledgement
|
|
16753
|
+
* .result = { jsonrpc, id, result:{…} } ← the reply payload
|
|
16754
|
+
* .result = { code:"400", message:"Bad request" } ← the actual op outcome
|
|
16755
|
+
*
|
|
16756
|
+
* A failure can appear at any layer (delivery refused, or the op itself rejected
|
|
16757
|
+
* deeper down), so walk every nested `.result` object and return the FIRST non-2xx
|
|
16758
|
+
* `code` with its message. Returns null when every `code` seen is 2xx or absent —
|
|
16759
|
+
* i.e. the op succeeded. This is the only way to detect that e.g. a mute/kick was
|
|
16760
|
+
* rejected, since the outer delivery `code` is "200" (delivered) even then.
|
|
16761
|
+
*
|
|
16762
|
+
* Pure function — exported for unit testing.
|
|
16763
|
+
*/
|
|
16764
|
+
function findNestedVertoFailure(response) {
|
|
16765
|
+
let node = response;
|
|
16766
|
+
while (node !== null && typeof node === "object") {
|
|
16767
|
+
const obj = node;
|
|
16768
|
+
const err = obj.error;
|
|
16769
|
+
if (err !== null && typeof err === "object") {
|
|
16770
|
+
const e = err;
|
|
16771
|
+
const errCode = typeof e.code === "string" || typeof e.code === "number" ? String(e.code) : void 0;
|
|
16772
|
+
if (errCode !== void 0 && !/^2\d\d$/.test(errCode)) return {
|
|
16773
|
+
code: errCode,
|
|
16774
|
+
message: typeof e.message === "string" ? e.message : void 0
|
|
16775
|
+
};
|
|
16776
|
+
}
|
|
16777
|
+
const code = typeof obj.code === "string" || typeof obj.code === "number" ? String(obj.code) : void 0;
|
|
16778
|
+
if (code !== void 0 && !/^2\d\d$/.test(code)) return {
|
|
16779
|
+
code,
|
|
16780
|
+
message: typeof obj.message === "string" ? obj.message : void 0
|
|
16781
|
+
};
|
|
16782
|
+
node = obj.result !== null && typeof obj.result === "object" ? obj.result : null;
|
|
16783
|
+
}
|
|
16784
|
+
return null;
|
|
16785
|
+
}
|
|
16716
16786
|
var VertoManager = class extends Destroyable {
|
|
16717
16787
|
constructor(callSession) {
|
|
16718
16788
|
super();
|
|
@@ -17037,6 +17107,33 @@ var WebRTCVertoManager = class extends VertoManager {
|
|
|
17037
17107
|
get vertoPing$() {
|
|
17038
17108
|
return this.cachedObservable("vertoPing$", () => this.webRtcCallSession.webrtcMessages$.pipe(filterAs(isVertoPingInnerParams, "params"), (0, import_cjs$15.takeUntil)(this.destroyed$)));
|
|
17039
17109
|
}
|
|
17110
|
+
/**
|
|
17111
|
+
* Send a member-control op in-dialog via verto.info.
|
|
17112
|
+
*
|
|
17113
|
+
* The control payload rides in `params.command` — a sibling of `dialogParams`,
|
|
17114
|
+
* at the same level as `dtmf` in {@link sendDigits} — and the inner verto.info
|
|
17115
|
+
* is matched to this call's channel by `dialogParams.callID`, the in-dialog
|
|
17116
|
+
* convention for member-scoped frames. Because it is delivered on the dialog
|
|
17117
|
+
* itself, control lands on the call's own channel with no {node_id,call_id,member_id}
|
|
17118
|
+
* "self" tuple to get wrong. The outer webrtc.verto envelope (added by executeVerto)
|
|
17119
|
+
* still carries the own-leg callID + node_id for session routing.
|
|
17120
|
+
*
|
|
17121
|
+
* Keep `command` OUT of `dialogParams`: it is read at the params level, and
|
|
17122
|
+
* filterVertoParams rewrites/filters dialogParams keys but passes params-level
|
|
17123
|
+
* keys through verbatim.
|
|
17124
|
+
*/
|
|
17125
|
+
async sendCallControl(method, params) {
|
|
17126
|
+
const response = await this.executeVerto(VertoInfo({
|
|
17127
|
+
dialogParams: { callID: this.webRtcCallSession.id },
|
|
17128
|
+
command: {
|
|
17129
|
+
method,
|
|
17130
|
+
params
|
|
17131
|
+
}
|
|
17132
|
+
}));
|
|
17133
|
+
const failure = findNestedVertoFailure(response);
|
|
17134
|
+
if (failure) throw new JSONRPCError(Number.parseInt(failure.code, 10) || 0, failure.message ?? `Call control "${method}" failed (code ${failure.code})`, void 0);
|
|
17135
|
+
return response;
|
|
17136
|
+
}
|
|
17040
17137
|
async executeVerto(message, optionals = {}) {
|
|
17041
17138
|
const webrtcVertoMessage = WebrtcVerto({
|
|
17042
17139
|
callID: optionals.callID ?? this.webRtcCallSession.id,
|
|
@@ -17045,15 +17142,16 @@ var WebRTCVertoManager = class extends VertoManager {
|
|
|
17045
17142
|
subscribe: optionals.subscribe
|
|
17046
17143
|
});
|
|
17047
17144
|
const response = await this.webRtcCallSession.execute(webrtcVertoMessage);
|
|
17145
|
+
const nonFatal = message.method === "verto.info" ? { fatal: false } : void 0;
|
|
17048
17146
|
if (response.error) {
|
|
17049
17147
|
const error = new JSONRPCError(response.error.code, response.error.message, response.error.data);
|
|
17050
|
-
this.onError?.(error);
|
|
17148
|
+
this.onError?.(error, nonFatal);
|
|
17051
17149
|
return response;
|
|
17052
17150
|
}
|
|
17053
17151
|
const innerResult = getValueFrom(response, "result.result");
|
|
17054
17152
|
if (innerResult?.error) {
|
|
17055
17153
|
const error = new JSONRPCError(innerResult.error.code, innerResult.error.message, innerResult.error.data);
|
|
17056
|
-
this.onError?.(error);
|
|
17154
|
+
this.onError?.(error, nonFatal);
|
|
17057
17155
|
return response;
|
|
17058
17156
|
}
|
|
17059
17157
|
return response;
|
|
@@ -18440,8 +18538,11 @@ var WebRTCCall = class extends Destroyable {
|
|
|
18440
18538
|
emitError(callError) {
|
|
18441
18539
|
if (this._status$.value === "destroyed" || this._status$.value === "failed") return;
|
|
18442
18540
|
this._errors$.next(callError);
|
|
18443
|
-
if (callError.fatal) {
|
|
18541
|
+
if (callError.fatal && this._status$.value !== "disconnecting") {
|
|
18444
18542
|
this._status$.next("failed");
|
|
18543
|
+
this.vertoManager.bye().catch((error) => {
|
|
18544
|
+
logger$12.debug("[Call] fatal-teardown bye failed (signaling likely already dead):", error);
|
|
18545
|
+
});
|
|
18445
18546
|
this.destroy();
|
|
18446
18547
|
}
|
|
18447
18548
|
}
|
|
@@ -18558,6 +18659,7 @@ var WebRTCCall = class extends Destroyable {
|
|
|
18558
18659
|
async executeMethod(target, method, args) {
|
|
18559
18660
|
const self = this.callSelf;
|
|
18560
18661
|
if (typeof target === "string" && target !== self.member_id) throw new InvalidParams(`Target member ID ${target} does not match call's self member ID ${self.member_id}`);
|
|
18662
|
+
if (this.clientSession.callControl === "in-dialog") return this.executeMethodInDialog(target, method, args);
|
|
18561
18663
|
const params = {
|
|
18562
18664
|
...args,
|
|
18563
18665
|
self,
|
|
@@ -18577,6 +18679,81 @@ var WebRTCCall = class extends Destroyable {
|
|
|
18577
18679
|
}
|
|
18578
18680
|
}
|
|
18579
18681
|
/**
|
|
18682
|
+
* `executeMethod` for a call opened with `callControl: 'in-dialog'`.
|
|
18683
|
+
*
|
|
18684
|
+
* Translates the routed transport's calling convention into the in-dialog one. No
|
|
18685
|
+
* `self` tuple is sent, but a `target` is — the same {call_id, member_id} the routed
|
|
18686
|
+
* transport puts in `target` (minus node_id), for self-ops and cross-member ops alike.
|
|
18687
|
+
*
|
|
18688
|
+
* Target shapes are per-verb and irregular, so they are centralised here rather
|
|
18689
|
+
* than left to callers: most verbs take a singular `target`, `call.member.remove`
|
|
18690
|
+
* takes a plural `targets` array, and `call.member.position.set` takes a flat
|
|
18691
|
+
* `targets` of `{call_id, position}` — the one verb keyed on call_id rather than
|
|
18692
|
+
* member_id, so the member triple `Participant.setPosition` built is unwrapped.
|
|
18693
|
+
*/
|
|
18694
|
+
async executeMethodInDialog(target, method, args) {
|
|
18695
|
+
const control = { ...args };
|
|
18696
|
+
if (method === "call.member.position.set") control.targets = (args.targets ?? []).map((entry) => ({
|
|
18697
|
+
call_id: entry.target?.call_id ?? entry.call_id,
|
|
18698
|
+
position: entry.position
|
|
18699
|
+
}));
|
|
18700
|
+
else {
|
|
18701
|
+
const member = typeof target === "object" ? {
|
|
18702
|
+
call_id: target.call_id,
|
|
18703
|
+
member_id: target.member_id
|
|
18704
|
+
} : {
|
|
18705
|
+
call_id: this.id,
|
|
18706
|
+
member_id: target
|
|
18707
|
+
};
|
|
18708
|
+
if (method === "call.member.remove") control.targets = [member];
|
|
18709
|
+
else control.target = member;
|
|
18710
|
+
}
|
|
18711
|
+
return this.sendCommand(method, control);
|
|
18712
|
+
}
|
|
18713
|
+
/**
|
|
18714
|
+
* Sends a `call.*` control verb **in-dialog** via `verto.info`, as an alternative
|
|
18715
|
+
* to the routed {@link executeMethod} transport.
|
|
18716
|
+
*
|
|
18717
|
+
* Why both exist: `executeMethod` addresses the member with an explicit
|
|
18718
|
+
* `{node_id, call_id, member_id}` tuple, which does not resolve for every conference,
|
|
18719
|
+
* so the op can fail. An in-dialog frame carries the verb on the member's own
|
|
18720
|
+
* signaling channel instead, so control works without the client needing to know how
|
|
18721
|
+
* the conference is hosted.
|
|
18722
|
+
*
|
|
18723
|
+
* The trade-off is reach: the in-dialog transport is only accepted for calls that
|
|
18724
|
+
* join a conference over SWML (e.g. an SWML `join_conference`); use the routed
|
|
18725
|
+
* default otherwise.
|
|
18726
|
+
*
|
|
18727
|
+
* `params` are sent verbatim — nothing is built for you, which includes the target.
|
|
18728
|
+
* **A self-directed op still needs one**, or it is refused; name yourself explicitly:
|
|
18729
|
+
*
|
|
18730
|
+
* ```ts
|
|
18731
|
+
* const { call_id, member_id } = call.self.target;
|
|
18732
|
+
* await call.sendCommand('call.mute', { channels: ['audio'], target: { call_id, member_id } });
|
|
18733
|
+
* ```
|
|
18734
|
+
*
|
|
18735
|
+
* Never include `node_id` — only the two ids. The shapes are per-verb: most take a
|
|
18736
|
+
* singular `target`, `call.member.remove` takes a plural `targets` array, and
|
|
18737
|
+
* `call.member.position.set` takes a flat `targets: [{call_id, position}]` (the one
|
|
18738
|
+
* verb keyed on `call_id` rather than `member_id`). Verbs that act on the call as a
|
|
18739
|
+
* whole, or that the SDK does not wrap at all, take no target.
|
|
18740
|
+
*
|
|
18741
|
+
* For the typed alternative that handles all of this, create the client with
|
|
18742
|
+
* `callControl: 'in-dialog'` and use the ordinary `Call`/`Participant` methods.
|
|
18743
|
+
*
|
|
18744
|
+
* @internal Not part of the supported surface while the in-dialog transport is still
|
|
18745
|
+
* rolling out. `WebRTCCall` is exported from the package entry, so without this tag
|
|
18746
|
+
* TypeDoc publishes the method — and the example above — as public API.
|
|
18747
|
+
*
|
|
18748
|
+
* @param method - A `call.*` method name (e.g. `'call.mute'`).
|
|
18749
|
+
* @param params - Method parameters, sent verbatim.
|
|
18750
|
+
* @returns The method's own reply, unwrapped from the `verto.info` envelope.
|
|
18751
|
+
* @throws {JSONRPCError} If the control op fails.
|
|
18752
|
+
*/
|
|
18753
|
+
async sendCommand(method, params = {}) {
|
|
18754
|
+
return unwrapVertoReply(await this.vertoManager.sendCallControl(method, params));
|
|
18755
|
+
}
|
|
18756
|
+
/**
|
|
18580
18757
|
* The local leg's member triple — sent as `self` in every member RPC
|
|
18581
18758
|
* envelope, and as the `target` of call-scoped self-operations (e.g. lock,
|
|
18582
18759
|
* layout).
|
|
@@ -19907,6 +20084,7 @@ var ClientSessionManager = class extends Destroyable {
|
|
|
19907
20084
|
minor: 0,
|
|
19908
20085
|
revision: 0
|
|
19909
20086
|
};
|
|
20087
|
+
this.callControl = "routed";
|
|
19910
20088
|
this._authorization$ = this.createBehaviorSubject(void 0);
|
|
19911
20089
|
this._errors$ = this.createReplaySubject(1);
|
|
19912
20090
|
this._authState$ = this.createBehaviorSubject({ kind: "unauthenticated" });
|
|
@@ -20380,6 +20558,9 @@ var ClientSessionWrapper = class {
|
|
|
20380
20558
|
get iceServers() {
|
|
20381
20559
|
return this.clientSessionManager.iceServers;
|
|
20382
20560
|
}
|
|
20561
|
+
get callControl() {
|
|
20562
|
+
return this.clientSessionManager.callControl;
|
|
20563
|
+
}
|
|
20383
20564
|
async execute(request, options) {
|
|
20384
20565
|
return this.clientSessionManager.execute(request, options);
|
|
20385
20566
|
}
|
|
@@ -20620,7 +20801,7 @@ var DeviceTokenManager = class extends Destroyable {
|
|
|
20620
20801
|
method: "POST",
|
|
20621
20802
|
uri: DEVICE_TOKEN_ENDPOINT
|
|
20622
20803
|
});
|
|
20623
|
-
const response = await this.http.request({
|
|
20804
|
+
const response = await this.http().request({
|
|
20624
20805
|
url: DEVICE_TOKEN_ENDPOINT,
|
|
20625
20806
|
...POST_PARAMS,
|
|
20626
20807
|
body: JSON.stringify({
|
|
@@ -20647,7 +20828,7 @@ var DeviceTokenManager = class extends Destroyable {
|
|
|
20647
20828
|
uri: DEVICE_REFRESH_ENDPOINT,
|
|
20648
20829
|
accessToken: currentToken
|
|
20649
20830
|
});
|
|
20650
|
-
const response = await this.http.request({
|
|
20831
|
+
const response = await this.http().request({
|
|
20651
20832
|
url: DEVICE_REFRESH_ENDPOINT,
|
|
20652
20833
|
...POST_PARAMS,
|
|
20653
20834
|
body: JSON.stringify({
|
|
@@ -21812,6 +21993,16 @@ var SignalWire = class extends Destroyable {
|
|
|
21812
21993
|
});
|
|
21813
21994
|
}
|
|
21814
21995
|
/**
|
|
21996
|
+
* Build the refresh path's own HTTP controller, against whatever host is current.
|
|
21997
|
+
*
|
|
21998
|
+
* Called on first use rather than up front, so `apiHost` already reflects the
|
|
21999
|
+
* token's `ch` claim. Same credential source as the container's controller — only
|
|
22000
|
+
* the instance, and therefore its observable streams, is separate.
|
|
22001
|
+
*/
|
|
22002
|
+
createRefreshHttpController() {
|
|
22003
|
+
return new HTTPRequestController(this._deps.apiHost, () => this._deps.credential);
|
|
22004
|
+
}
|
|
22005
|
+
/**
|
|
21815
22006
|
* Initializes DPoP if not already set up. Returns the fingerprint on success.
|
|
21816
22007
|
*/
|
|
21817
22008
|
async initDPoP() {
|
|
@@ -21838,7 +22029,14 @@ var SignalWire = class extends Destroyable {
|
|
|
21838
22029
|
async resolveCredentials() {
|
|
21839
22030
|
const fingerprint = await this.initDPoP();
|
|
21840
22031
|
this._refreshCoordinator = new CredentialRefreshCoordinator(this._dpopManager, {
|
|
21841
|
-
http:
|
|
22032
|
+
http: () => {
|
|
22033
|
+
if (!this._refreshHttp || this._refreshHttpHost !== this._deps.apiHost) {
|
|
22034
|
+
this._refreshHttp?.destroy();
|
|
22035
|
+
this._refreshHttp = this.createRefreshHttpController();
|
|
22036
|
+
this._refreshHttpHost = this._deps.apiHost;
|
|
22037
|
+
}
|
|
22038
|
+
return this._refreshHttp;
|
|
22039
|
+
},
|
|
21842
22040
|
notifier: {
|
|
21843
22041
|
onError: (error) => this._errors$.next(error),
|
|
21844
22042
|
onWarning: (warning) => this._warnings$.next(warning),
|
|
@@ -22104,6 +22302,7 @@ var SignalWire = class extends Destroyable {
|
|
|
22104
22302
|
this._attachManager = new AttachManager(this._deps.storage, this._deps.deviceController, PreferencesContainer.instance.reconnectCallsTimeout, this._deps.attachedCallsKey);
|
|
22105
22303
|
this._clientSession = new ClientSessionManager(() => this._deps.credential, this._transport, this._deps.storage, this._deps.authorizationStateKey, this._deps.deviceController, this._attachManager, this._deps.webRTCApiProvider, this._dpopManager, this._networkMonitor?.networkChange$);
|
|
22106
22304
|
this._publicSession = new ClientSessionWrapper(this._clientSession);
|
|
22305
|
+
this._clientSession.callControl = this._options.callControl ?? "routed";
|
|
22107
22306
|
this._clientSession.onBeforeReconnect = async () => this.refreshCredentialForReconnect();
|
|
22108
22307
|
this.subscribeTo(this._clientSession.errors$, (error) => {
|
|
22109
22308
|
this._errors$.next(error);
|
|
@@ -22720,6 +22919,8 @@ var SignalWire = class extends Destroyable {
|
|
|
22720
22919
|
destroy() {
|
|
22721
22920
|
this._refreshCoordinator?.destroy();
|
|
22722
22921
|
this._refreshCoordinator = void 0;
|
|
22922
|
+
this._refreshHttp?.destroy();
|
|
22923
|
+
this._refreshHttp = void 0;
|
|
22723
22924
|
this._dpopManager?.destroy();
|
|
22724
22925
|
const session = this._clientSession;
|
|
22725
22926
|
session?.teardownSessionState();
|