@siphon-project/control 0.1.3 → 0.2.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/dist/index.cjs +85 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +90 -2
- package/dist/index.d.ts +90 -2
- package/dist/index.js +85 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -189,6 +189,7 @@ declare const SipVerb: {
|
|
|
189
189
|
readonly RejectRefer: "reject_refer";
|
|
190
190
|
readonly Bridge: "bridge";
|
|
191
191
|
readonly Unbridge: "unbridge";
|
|
192
|
+
readonly ReplacePeer: "replace_peer";
|
|
192
193
|
readonly Play: "play";
|
|
193
194
|
readonly Stop: "stop";
|
|
194
195
|
readonly Dtmf: "dtmf";
|
|
@@ -200,7 +201,7 @@ declare const SipVerb: {
|
|
|
200
201
|
/** A value of {@link SipVerb}. */
|
|
201
202
|
type SipVerbToken = (typeof SipVerb)[keyof typeof SipVerb];
|
|
202
203
|
/** The well-known SIP-adapter event names (the ARI *Stasis* model). */
|
|
203
|
-
type SipEventKind = "StasisStart" | "StasisEnd" | "ChannelStateChange" | "ChannelHangupRequest" | "ChannelDtmfReceived" | "PlayStarted" | "TransferRequested" | "TransferProgress" | "TransferCompleted" | "TransferFailed" | "ChannelBridged" | "BridgeFailed" | "ChannelUnbridged" | "PlayFinished" | "WsTeeStarted" | "WsTeeEnded" | "WsBridgeStarted" | "WsBridgeEnded" | (string & {});
|
|
204
|
+
type SipEventKind = "StasisStart" | "StasisEnd" | "ChannelStateChange" | "ChannelHangupRequest" | "ChannelDtmfReceived" | "PlayStarted" | "TransferRequested" | "TransferProgress" | "TransferCompleted" | "TransferFailed" | "ChannelBridged" | "BridgeFailed" | "ChannelUnbridged" | "PeerReplaced" | "ReplaceFailed" | "PlayFinished" | "WsTeeStarted" | "WsTeeEnded" | "WsBridgeStarted" | "WsBridgeEnded" | (string & {});
|
|
204
205
|
/** Parse a wire event name; unknown names pass through verbatim (forward-compatible). */
|
|
205
206
|
declare function sipEventKind(name: string): SipEventKind;
|
|
206
207
|
/**
|
|
@@ -320,6 +321,19 @@ interface TransferOutcomePayload {
|
|
|
320
321
|
* event arrives per `refer`, so this is the signal to stop waiting.
|
|
321
322
|
*/
|
|
322
323
|
declare function isTransferFinal(name: string): boolean;
|
|
324
|
+
/**
|
|
325
|
+
* The transfer verdict carried by an event, or `null` if it is not one.
|
|
326
|
+
*
|
|
327
|
+
* Takes an event as {@link import("./sip").CallEvent} shapes it and narrows its
|
|
328
|
+
* `payload` to {@link TransferOutcomePayload} for `TransferProgress` /
|
|
329
|
+
* `TransferCompleted` / `TransferFailed`. Anything else — including
|
|
330
|
+
* `TransferRequested`, which is an *inbound* REFER somebody else asked for
|
|
331
|
+
* rather than a verdict on one of ours — gives `null`.
|
|
332
|
+
*/
|
|
333
|
+
declare function transferOutcome(event: {
|
|
334
|
+
kind: string;
|
|
335
|
+
payload: unknown;
|
|
336
|
+
}): TransferOutcomePayload | null;
|
|
323
337
|
/**
|
|
324
338
|
* What happens to the surviving leg when its bridge partner hangs up — the
|
|
325
339
|
* `onPeerHangup` option of {@link import("./sip").Call.bridge}.
|
|
@@ -704,6 +718,20 @@ interface ResponseOptions {
|
|
|
704
718
|
body?: string;
|
|
705
719
|
contentType?: string;
|
|
706
720
|
}
|
|
721
|
+
/** Options for an anchored answer ({@link Call.answerAnchored}). */
|
|
722
|
+
interface AnchoredAnswerOptions {
|
|
723
|
+
/** UAS 2xx code (default `200`). */
|
|
724
|
+
code?: number;
|
|
725
|
+
/** Reason phrase (default `OK`). */
|
|
726
|
+
reason?: string;
|
|
727
|
+
/** Media profile to anchor with (default `voice_ai`). */
|
|
728
|
+
profile?: string;
|
|
729
|
+
/**
|
|
730
|
+
* Per-call WebSocket bridge URI, overriding the profile's own. Supports
|
|
731
|
+
* `{call_id}` / `{from_tag}` / `{from_user}` / `{to_user}` templating.
|
|
732
|
+
*/
|
|
733
|
+
wsUri?: string;
|
|
734
|
+
}
|
|
707
735
|
/** The RFC 3891 `Replaces` triple for an attended transfer. */
|
|
708
736
|
interface ReferReplaces {
|
|
709
737
|
callId: string;
|
|
@@ -837,6 +865,26 @@ declare class Call {
|
|
|
837
865
|
private substrate;
|
|
838
866
|
/** Send a UAS 2xx to the parked A-leg (default `200 OK`). */
|
|
839
867
|
answer(options?: ResponseOptions): Promise<void>;
|
|
868
|
+
/**
|
|
869
|
+
* Answer the parked A-leg **and** anchor its media to the media engine in one
|
|
870
|
+
* act — the verb form of the routing script's
|
|
871
|
+
* `call.handover(answer=True, profile=…, ws_uri=…)`.
|
|
872
|
+
*
|
|
873
|
+
* This is how an application that accepted an **un-answered** handover
|
|
874
|
+
* connects the call. It can already hold the call open for as long as its own
|
|
875
|
+
* policy says with {@link Call.ring}; what it could not do is connect the
|
|
876
|
+
* caller to anything, because a plain {@link Call.answer} sends a 2xx and
|
|
877
|
+
* anchors nothing. Answering first and attaching a stream afterwards is not
|
|
878
|
+
* the same thing: `received_from`, echo cancellation and the VAD engine are
|
|
879
|
+
* properties of the answer, not of a bridge attached after it.
|
|
880
|
+
*
|
|
881
|
+
* Synthesizing the RFC 3264 answer against the media engine is a siphon-rtp
|
|
882
|
+
* capability, so on rtpengine / rtpproxy this rejects with
|
|
883
|
+
* `code === "unavailable"` rather than sending a 200 with nothing behind it.
|
|
884
|
+
* On any media failure the 2xx is never sent and the call stays parked —
|
|
885
|
+
* retry with another profile, or reject it.
|
|
886
|
+
*/
|
|
887
|
+
answerAnchored(options?: AnchoredAnswerOptions): Promise<void>;
|
|
840
888
|
/**
|
|
841
889
|
* Send `180 Ringing`: alerting only, no early media.
|
|
842
890
|
*
|
|
@@ -956,6 +1004,46 @@ declare class Call {
|
|
|
956
1004
|
* with `code === "invalid_state"`.
|
|
957
1005
|
*/
|
|
958
1006
|
unbridge(reason?: string): Promise<unknown>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Replace one leg of this answered call with a freshly dialed target, with no
|
|
1009
|
+
* REFER involved.
|
|
1010
|
+
*
|
|
1011
|
+
* The transfer siphon already runs for a REFER it terminates, reachable
|
|
1012
|
+
* because *this app* decided: an IVR that has worked out where the caller
|
|
1013
|
+
* should go, a controller handing a call from an AI to a human, a supervisor
|
|
1014
|
+
* take-over. siphon dials `target` as a new leg on the same call, re-anchors
|
|
1015
|
+
* the surviving party's media onto it, and once the target answers promotes
|
|
1016
|
+
* it into the surviving pair and BYEs the leg it replaced.
|
|
1017
|
+
*
|
|
1018
|
+
* The replaced leg **stays up while the target rings**, so the surviving
|
|
1019
|
+
* party hears ringback rather than silence, and a target that refuses or
|
|
1020
|
+
* never answers leaves the call exactly as it was.
|
|
1021
|
+
*
|
|
1022
|
+
* `replaceALeg` picks the direction: omitted/`false` replaces the callee and
|
|
1023
|
+
* keeps the caller, `true` does the reverse. `profile` names the media
|
|
1024
|
+
* profile for the pair this creates — required when the call is anchored with
|
|
1025
|
+
* a direction-bound one, whose answer half describes the party that is
|
|
1026
|
+
* leaving. `timeout` bounds the ring in seconds (`0` = no ring policy, only
|
|
1027
|
+
* siphon's guard against a target that answers nothing).
|
|
1028
|
+
*
|
|
1029
|
+
* Resolves as soon as the INVITE is on the wire
|
|
1030
|
+
* (`{channel, replacement: "dialing", target}`) and says nothing about the
|
|
1031
|
+
* target. Wait for the `PeerReplaced`
|
|
1032
|
+
* ({@link import("./protocol").PeerReplacedPayload}) or `ReplaceFailed`
|
|
1033
|
+
* ({@link import("./protocol").ReplaceFailedPayload}) event for the outcome —
|
|
1034
|
+
* acting on the reply alone would tear down a call whose replacement is still
|
|
1035
|
+
* ringing.
|
|
1036
|
+
*
|
|
1037
|
+
* Rejects with `code === "not_found"` (no such call), `"invalid_state"` (not
|
|
1038
|
+
* answered, no peer leg, or a replacement already in flight — all worth
|
|
1039
|
+
* retrying later) or `"bad_request"` (the target will not parse or route).
|
|
1040
|
+
*/
|
|
1041
|
+
replacePeer(target: string, options?: {
|
|
1042
|
+
nextHop?: string;
|
|
1043
|
+
replaceALeg?: boolean;
|
|
1044
|
+
profile?: string;
|
|
1045
|
+
timeout?: number;
|
|
1046
|
+
}): Promise<unknown>;
|
|
959
1047
|
/** Set a header on the stored A-leg INVITE. */
|
|
960
1048
|
setHeader(name: string, value: string): Promise<void>;
|
|
961
1049
|
/** Read a header from the stored A-leg INVITE (`null` when absent). */
|
|
@@ -1079,4 +1167,4 @@ declare class SipServer {
|
|
|
1079
1167
|
close(): Promise<void>;
|
|
1080
1168
|
}
|
|
1081
1169
|
|
|
1082
|
-
export { type AcceptReferOptions, type BridgeFailedPayload, type BridgeOptions, type BridgeRole, type BridgeStage, Call, type CallEvent, type CallHandler, CallStream, type ChannelBridgedPayload, type ChannelDtmfPayload, type ChannelSnapshot, type ChannelUnbridgedPayload, type ClientConfig, type ClientEvent, type CommandTransport, type ConnectionEventSink, ControlClient, ControlError, type ControlErrorCode, type ControlErrorKind, ControlServer, DESCRIBE, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, SipClient, type SipEventKind, SipServer, SipVerb, type SipVerbToken, type StreamOptions, type TransferOutcomePayload, type TransferReplaces, type TransferRequestedPayload, type TransferStage, type WsBridgeEndedPayload, type WsBridgeStartedPayload, type WsTeeEndedPayload, type WsTeeStartedPayload, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind };
|
|
1170
|
+
export { type AcceptReferOptions, type AnchoredAnswerOptions, type BridgeFailedPayload, type BridgeOptions, type BridgeRole, type BridgeStage, Call, type CallEvent, type CallHandler, CallStream, type ChannelBridgedPayload, type ChannelDtmfPayload, type ChannelSnapshot, type ChannelUnbridgedPayload, type ClientConfig, type ClientEvent, type CommandTransport, type ConnectionEventSink, ControlClient, ControlError, type ControlErrorCode, type ControlErrorKind, ControlServer, DESCRIBE, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, SipClient, type SipEventKind, SipServer, SipVerb, type SipVerbToken, type StreamOptions, type TransferOutcomePayload, type TransferReplaces, type TransferRequestedPayload, type TransferStage, type WsBridgeEndedPayload, type WsBridgeStartedPayload, type WsTeeEndedPayload, type WsTeeStartedPayload, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind, transferOutcome };
|
package/dist/index.d.ts
CHANGED
|
@@ -189,6 +189,7 @@ declare const SipVerb: {
|
|
|
189
189
|
readonly RejectRefer: "reject_refer";
|
|
190
190
|
readonly Bridge: "bridge";
|
|
191
191
|
readonly Unbridge: "unbridge";
|
|
192
|
+
readonly ReplacePeer: "replace_peer";
|
|
192
193
|
readonly Play: "play";
|
|
193
194
|
readonly Stop: "stop";
|
|
194
195
|
readonly Dtmf: "dtmf";
|
|
@@ -200,7 +201,7 @@ declare const SipVerb: {
|
|
|
200
201
|
/** A value of {@link SipVerb}. */
|
|
201
202
|
type SipVerbToken = (typeof SipVerb)[keyof typeof SipVerb];
|
|
202
203
|
/** The well-known SIP-adapter event names (the ARI *Stasis* model). */
|
|
203
|
-
type SipEventKind = "StasisStart" | "StasisEnd" | "ChannelStateChange" | "ChannelHangupRequest" | "ChannelDtmfReceived" | "PlayStarted" | "TransferRequested" | "TransferProgress" | "TransferCompleted" | "TransferFailed" | "ChannelBridged" | "BridgeFailed" | "ChannelUnbridged" | "PlayFinished" | "WsTeeStarted" | "WsTeeEnded" | "WsBridgeStarted" | "WsBridgeEnded" | (string & {});
|
|
204
|
+
type SipEventKind = "StasisStart" | "StasisEnd" | "ChannelStateChange" | "ChannelHangupRequest" | "ChannelDtmfReceived" | "PlayStarted" | "TransferRequested" | "TransferProgress" | "TransferCompleted" | "TransferFailed" | "ChannelBridged" | "BridgeFailed" | "ChannelUnbridged" | "PeerReplaced" | "ReplaceFailed" | "PlayFinished" | "WsTeeStarted" | "WsTeeEnded" | "WsBridgeStarted" | "WsBridgeEnded" | (string & {});
|
|
204
205
|
/** Parse a wire event name; unknown names pass through verbatim (forward-compatible). */
|
|
205
206
|
declare function sipEventKind(name: string): SipEventKind;
|
|
206
207
|
/**
|
|
@@ -320,6 +321,19 @@ interface TransferOutcomePayload {
|
|
|
320
321
|
* event arrives per `refer`, so this is the signal to stop waiting.
|
|
321
322
|
*/
|
|
322
323
|
declare function isTransferFinal(name: string): boolean;
|
|
324
|
+
/**
|
|
325
|
+
* The transfer verdict carried by an event, or `null` if it is not one.
|
|
326
|
+
*
|
|
327
|
+
* Takes an event as {@link import("./sip").CallEvent} shapes it and narrows its
|
|
328
|
+
* `payload` to {@link TransferOutcomePayload} for `TransferProgress` /
|
|
329
|
+
* `TransferCompleted` / `TransferFailed`. Anything else — including
|
|
330
|
+
* `TransferRequested`, which is an *inbound* REFER somebody else asked for
|
|
331
|
+
* rather than a verdict on one of ours — gives `null`.
|
|
332
|
+
*/
|
|
333
|
+
declare function transferOutcome(event: {
|
|
334
|
+
kind: string;
|
|
335
|
+
payload: unknown;
|
|
336
|
+
}): TransferOutcomePayload | null;
|
|
323
337
|
/**
|
|
324
338
|
* What happens to the surviving leg when its bridge partner hangs up — the
|
|
325
339
|
* `onPeerHangup` option of {@link import("./sip").Call.bridge}.
|
|
@@ -704,6 +718,20 @@ interface ResponseOptions {
|
|
|
704
718
|
body?: string;
|
|
705
719
|
contentType?: string;
|
|
706
720
|
}
|
|
721
|
+
/** Options for an anchored answer ({@link Call.answerAnchored}). */
|
|
722
|
+
interface AnchoredAnswerOptions {
|
|
723
|
+
/** UAS 2xx code (default `200`). */
|
|
724
|
+
code?: number;
|
|
725
|
+
/** Reason phrase (default `OK`). */
|
|
726
|
+
reason?: string;
|
|
727
|
+
/** Media profile to anchor with (default `voice_ai`). */
|
|
728
|
+
profile?: string;
|
|
729
|
+
/**
|
|
730
|
+
* Per-call WebSocket bridge URI, overriding the profile's own. Supports
|
|
731
|
+
* `{call_id}` / `{from_tag}` / `{from_user}` / `{to_user}` templating.
|
|
732
|
+
*/
|
|
733
|
+
wsUri?: string;
|
|
734
|
+
}
|
|
707
735
|
/** The RFC 3891 `Replaces` triple for an attended transfer. */
|
|
708
736
|
interface ReferReplaces {
|
|
709
737
|
callId: string;
|
|
@@ -837,6 +865,26 @@ declare class Call {
|
|
|
837
865
|
private substrate;
|
|
838
866
|
/** Send a UAS 2xx to the parked A-leg (default `200 OK`). */
|
|
839
867
|
answer(options?: ResponseOptions): Promise<void>;
|
|
868
|
+
/**
|
|
869
|
+
* Answer the parked A-leg **and** anchor its media to the media engine in one
|
|
870
|
+
* act — the verb form of the routing script's
|
|
871
|
+
* `call.handover(answer=True, profile=…, ws_uri=…)`.
|
|
872
|
+
*
|
|
873
|
+
* This is how an application that accepted an **un-answered** handover
|
|
874
|
+
* connects the call. It can already hold the call open for as long as its own
|
|
875
|
+
* policy says with {@link Call.ring}; what it could not do is connect the
|
|
876
|
+
* caller to anything, because a plain {@link Call.answer} sends a 2xx and
|
|
877
|
+
* anchors nothing. Answering first and attaching a stream afterwards is not
|
|
878
|
+
* the same thing: `received_from`, echo cancellation and the VAD engine are
|
|
879
|
+
* properties of the answer, not of a bridge attached after it.
|
|
880
|
+
*
|
|
881
|
+
* Synthesizing the RFC 3264 answer against the media engine is a siphon-rtp
|
|
882
|
+
* capability, so on rtpengine / rtpproxy this rejects with
|
|
883
|
+
* `code === "unavailable"` rather than sending a 200 with nothing behind it.
|
|
884
|
+
* On any media failure the 2xx is never sent and the call stays parked —
|
|
885
|
+
* retry with another profile, or reject it.
|
|
886
|
+
*/
|
|
887
|
+
answerAnchored(options?: AnchoredAnswerOptions): Promise<void>;
|
|
840
888
|
/**
|
|
841
889
|
* Send `180 Ringing`: alerting only, no early media.
|
|
842
890
|
*
|
|
@@ -956,6 +1004,46 @@ declare class Call {
|
|
|
956
1004
|
* with `code === "invalid_state"`.
|
|
957
1005
|
*/
|
|
958
1006
|
unbridge(reason?: string): Promise<unknown>;
|
|
1007
|
+
/**
|
|
1008
|
+
* Replace one leg of this answered call with a freshly dialed target, with no
|
|
1009
|
+
* REFER involved.
|
|
1010
|
+
*
|
|
1011
|
+
* The transfer siphon already runs for a REFER it terminates, reachable
|
|
1012
|
+
* because *this app* decided: an IVR that has worked out where the caller
|
|
1013
|
+
* should go, a controller handing a call from an AI to a human, a supervisor
|
|
1014
|
+
* take-over. siphon dials `target` as a new leg on the same call, re-anchors
|
|
1015
|
+
* the surviving party's media onto it, and once the target answers promotes
|
|
1016
|
+
* it into the surviving pair and BYEs the leg it replaced.
|
|
1017
|
+
*
|
|
1018
|
+
* The replaced leg **stays up while the target rings**, so the surviving
|
|
1019
|
+
* party hears ringback rather than silence, and a target that refuses or
|
|
1020
|
+
* never answers leaves the call exactly as it was.
|
|
1021
|
+
*
|
|
1022
|
+
* `replaceALeg` picks the direction: omitted/`false` replaces the callee and
|
|
1023
|
+
* keeps the caller, `true` does the reverse. `profile` names the media
|
|
1024
|
+
* profile for the pair this creates — required when the call is anchored with
|
|
1025
|
+
* a direction-bound one, whose answer half describes the party that is
|
|
1026
|
+
* leaving. `timeout` bounds the ring in seconds (`0` = no ring policy, only
|
|
1027
|
+
* siphon's guard against a target that answers nothing).
|
|
1028
|
+
*
|
|
1029
|
+
* Resolves as soon as the INVITE is on the wire
|
|
1030
|
+
* (`{channel, replacement: "dialing", target}`) and says nothing about the
|
|
1031
|
+
* target. Wait for the `PeerReplaced`
|
|
1032
|
+
* ({@link import("./protocol").PeerReplacedPayload}) or `ReplaceFailed`
|
|
1033
|
+
* ({@link import("./protocol").ReplaceFailedPayload}) event for the outcome —
|
|
1034
|
+
* acting on the reply alone would tear down a call whose replacement is still
|
|
1035
|
+
* ringing.
|
|
1036
|
+
*
|
|
1037
|
+
* Rejects with `code === "not_found"` (no such call), `"invalid_state"` (not
|
|
1038
|
+
* answered, no peer leg, or a replacement already in flight — all worth
|
|
1039
|
+
* retrying later) or `"bad_request"` (the target will not parse or route).
|
|
1040
|
+
*/
|
|
1041
|
+
replacePeer(target: string, options?: {
|
|
1042
|
+
nextHop?: string;
|
|
1043
|
+
replaceALeg?: boolean;
|
|
1044
|
+
profile?: string;
|
|
1045
|
+
timeout?: number;
|
|
1046
|
+
}): Promise<unknown>;
|
|
959
1047
|
/** Set a header on the stored A-leg INVITE. */
|
|
960
1048
|
setHeader(name: string, value: string): Promise<void>;
|
|
961
1049
|
/** Read a header from the stored A-leg INVITE (`null` when absent). */
|
|
@@ -1079,4 +1167,4 @@ declare class SipServer {
|
|
|
1079
1167
|
close(): Promise<void>;
|
|
1080
1168
|
}
|
|
1081
1169
|
|
|
1082
|
-
export { type AcceptReferOptions, type BridgeFailedPayload, type BridgeOptions, type BridgeRole, type BridgeStage, Call, type CallEvent, type CallHandler, CallStream, type ChannelBridgedPayload, type ChannelDtmfPayload, type ChannelSnapshot, type ChannelUnbridgedPayload, type ClientConfig, type ClientEvent, type CommandTransport, type ConnectionEventSink, ControlClient, ControlError, type ControlErrorCode, type ControlErrorKind, ControlServer, DESCRIBE, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, SipClient, type SipEventKind, SipServer, SipVerb, type SipVerbToken, type StreamOptions, type TransferOutcomePayload, type TransferReplaces, type TransferRequestedPayload, type TransferStage, type WsBridgeEndedPayload, type WsBridgeStartedPayload, type WsTeeEndedPayload, type WsTeeStartedPayload, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind };
|
|
1170
|
+
export { type AcceptReferOptions, type AnchoredAnswerOptions, type BridgeFailedPayload, type BridgeOptions, type BridgeRole, type BridgeStage, Call, type CallEvent, type CallHandler, CallStream, type ChannelBridgedPayload, type ChannelDtmfPayload, type ChannelSnapshot, type ChannelUnbridgedPayload, type ClientConfig, type ClientEvent, type CommandTransport, type ConnectionEventSink, ControlClient, ControlError, type ControlErrorCode, type ControlErrorKind, ControlServer, DESCRIBE, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, SipClient, type SipEventKind, SipServer, SipVerb, type SipVerbToken, type StreamOptions, type TransferOutcomePayload, type TransferReplaces, type TransferRequestedPayload, type TransferStage, type WsBridgeEndedPayload, type WsBridgeStartedPayload, type WsTeeEndedPayload, type WsTeeStartedPayload, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind, transferOutcome };
|
package/dist/index.js
CHANGED
|
@@ -119,6 +119,7 @@ var SipVerb = {
|
|
|
119
119
|
RejectRefer: "reject_refer",
|
|
120
120
|
Bridge: "bridge",
|
|
121
121
|
Unbridge: "unbridge",
|
|
122
|
+
ReplacePeer: "replace_peer",
|
|
122
123
|
Play: "play",
|
|
123
124
|
Stop: "stop",
|
|
124
125
|
Dtmf: "dtmf",
|
|
@@ -133,6 +134,12 @@ function sipEventKind(name) {
|
|
|
133
134
|
function isTransferFinal(name) {
|
|
134
135
|
return name === "TransferCompleted" || name === "TransferFailed";
|
|
135
136
|
}
|
|
137
|
+
function transferOutcome(event) {
|
|
138
|
+
if (event.kind !== "TransferProgress" && event.kind !== "TransferCompleted" && event.kind !== "TransferFailed") {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
return event.payload ?? null;
|
|
142
|
+
}
|
|
136
143
|
function isBridgeFinal(name) {
|
|
137
144
|
return name === "ChannelBridged" || name === "BridgeFailed";
|
|
138
145
|
}
|
|
@@ -701,6 +708,41 @@ var Call = class {
|
|
|
701
708
|
async answer(options) {
|
|
702
709
|
await this.sip(SipVerb.Answer, options ? responseArgs(options) : {});
|
|
703
710
|
}
|
|
711
|
+
/**
|
|
712
|
+
* Answer the parked A-leg **and** anchor its media to the media engine in one
|
|
713
|
+
* act — the verb form of the routing script's
|
|
714
|
+
* `call.handover(answer=True, profile=…, ws_uri=…)`.
|
|
715
|
+
*
|
|
716
|
+
* This is how an application that accepted an **un-answered** handover
|
|
717
|
+
* connects the call. It can already hold the call open for as long as its own
|
|
718
|
+
* policy says with {@link Call.ring}; what it could not do is connect the
|
|
719
|
+
* caller to anything, because a plain {@link Call.answer} sends a 2xx and
|
|
720
|
+
* anchors nothing. Answering first and attaching a stream afterwards is not
|
|
721
|
+
* the same thing: `received_from`, echo cancellation and the VAD engine are
|
|
722
|
+
* properties of the answer, not of a bridge attached after it.
|
|
723
|
+
*
|
|
724
|
+
* Synthesizing the RFC 3264 answer against the media engine is a siphon-rtp
|
|
725
|
+
* capability, so on rtpengine / rtpproxy this rejects with
|
|
726
|
+
* `code === "unavailable"` rather than sending a 200 with nothing behind it.
|
|
727
|
+
* On any media failure the 2xx is never sent and the call stays parked —
|
|
728
|
+
* retry with another profile, or reject it.
|
|
729
|
+
*/
|
|
730
|
+
async answerAnchored(options) {
|
|
731
|
+
const args = { anchor: true };
|
|
732
|
+
if (options?.code !== void 0) {
|
|
733
|
+
args.code = options.code;
|
|
734
|
+
}
|
|
735
|
+
if (options?.reason !== void 0) {
|
|
736
|
+
args.reason = options.reason;
|
|
737
|
+
}
|
|
738
|
+
if (options?.profile !== void 0) {
|
|
739
|
+
args.profile = options.profile;
|
|
740
|
+
}
|
|
741
|
+
if (options?.wsUri !== void 0) {
|
|
742
|
+
args.ws_uri = options.wsUri;
|
|
743
|
+
}
|
|
744
|
+
await this.sip(SipVerb.Answer, args);
|
|
745
|
+
}
|
|
704
746
|
/**
|
|
705
747
|
* Send `180 Ringing`: alerting only, no early media.
|
|
706
748
|
*
|
|
@@ -886,6 +928,48 @@ var Call = class {
|
|
|
886
928
|
async unbridge(reason) {
|
|
887
929
|
return this.sip(SipVerb.Unbridge, reason !== void 0 ? { reason } : {});
|
|
888
930
|
}
|
|
931
|
+
/**
|
|
932
|
+
* Replace one leg of this answered call with a freshly dialed target, with no
|
|
933
|
+
* REFER involved.
|
|
934
|
+
*
|
|
935
|
+
* The transfer siphon already runs for a REFER it terminates, reachable
|
|
936
|
+
* because *this app* decided: an IVR that has worked out where the caller
|
|
937
|
+
* should go, a controller handing a call from an AI to a human, a supervisor
|
|
938
|
+
* take-over. siphon dials `target` as a new leg on the same call, re-anchors
|
|
939
|
+
* the surviving party's media onto it, and once the target answers promotes
|
|
940
|
+
* it into the surviving pair and BYEs the leg it replaced.
|
|
941
|
+
*
|
|
942
|
+
* The replaced leg **stays up while the target rings**, so the surviving
|
|
943
|
+
* party hears ringback rather than silence, and a target that refuses or
|
|
944
|
+
* never answers leaves the call exactly as it was.
|
|
945
|
+
*
|
|
946
|
+
* `replaceALeg` picks the direction: omitted/`false` replaces the callee and
|
|
947
|
+
* keeps the caller, `true` does the reverse. `profile` names the media
|
|
948
|
+
* profile for the pair this creates — required when the call is anchored with
|
|
949
|
+
* a direction-bound one, whose answer half describes the party that is
|
|
950
|
+
* leaving. `timeout` bounds the ring in seconds (`0` = no ring policy, only
|
|
951
|
+
* siphon's guard against a target that answers nothing).
|
|
952
|
+
*
|
|
953
|
+
* Resolves as soon as the INVITE is on the wire
|
|
954
|
+
* (`{channel, replacement: "dialing", target}`) and says nothing about the
|
|
955
|
+
* target. Wait for the `PeerReplaced`
|
|
956
|
+
* ({@link import("./protocol").PeerReplacedPayload}) or `ReplaceFailed`
|
|
957
|
+
* ({@link import("./protocol").ReplaceFailedPayload}) event for the outcome —
|
|
958
|
+
* acting on the reply alone would tear down a call whose replacement is still
|
|
959
|
+
* ringing.
|
|
960
|
+
*
|
|
961
|
+
* Rejects with `code === "not_found"` (no such call), `"invalid_state"` (not
|
|
962
|
+
* answered, no peer leg, or a replacement already in flight — all worth
|
|
963
|
+
* retrying later) or `"bad_request"` (the target will not parse or route).
|
|
964
|
+
*/
|
|
965
|
+
async replacePeer(target, options = {}) {
|
|
966
|
+
const args = { target };
|
|
967
|
+
if (options.nextHop !== void 0) args.next_hop = options.nextHop;
|
|
968
|
+
if (options.replaceALeg !== void 0) args.replace_a_leg = options.replaceALeg;
|
|
969
|
+
if (options.profile !== void 0) args.profile = options.profile;
|
|
970
|
+
if (options.timeout !== void 0) args.timeout = options.timeout;
|
|
971
|
+
return this.sip(SipVerb.ReplacePeer, args);
|
|
972
|
+
}
|
|
889
973
|
/** Set a header on the stored A-leg INVITE. */
|
|
890
974
|
async setHeader(name, value) {
|
|
891
975
|
await this.sip(SipVerb.SetHeader, { name, value });
|
|
@@ -1162,6 +1246,6 @@ var SipServer = class _SipServer {
|
|
|
1162
1246
|
}
|
|
1163
1247
|
};
|
|
1164
1248
|
|
|
1165
|
-
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, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind };
|
|
1249
|
+
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, encodeCommand, isBridgeFinal, isTransferFinal, parseInboundFrame, sipEventKind, transferOutcome };
|
|
1166
1250
|
//# sourceMappingURL=index.js.map
|
|
1167
1251
|
//# sourceMappingURL=index.js.map
|