@siphon-project/control 0.3.0 → 0.4.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.d.cts CHANGED
@@ -182,6 +182,11 @@ declare const SipVerb: {
182
182
  readonly Hangup: "hangup";
183
183
  readonly Refer: "refer";
184
184
  readonly Route: "route";
185
+ /**
186
+ * Ring targets as B-legs while the caller stays unanswered and the app keeps
187
+ * the channel. Channel-addressed, unlike `originate`, which creates one.
188
+ */
189
+ readonly Dial: "dial";
185
190
  readonly SetHeader: "set_header";
186
191
  readonly GetHeader: "get_header";
187
192
  readonly RemoveHeader: "remove_header";
@@ -197,6 +202,10 @@ declare const SipVerb: {
197
202
  readonly Unhold: "unhold";
198
203
  readonly StreamStart: "stream_start";
199
204
  readonly StreamStop: "stream_stop";
205
+ /** Record the call's decoded audio to a wav file (siphon-rtp backend only). */
206
+ readonly RecordStart: "record_start";
207
+ /** Stop one recording by id, or every recording on the call. */
208
+ readonly RecordStop: "record_stop";
200
209
  };
201
210
  /** A value of {@link SipVerb}. */
202
211
  type SipVerbToken = (typeof SipVerb)[keyof typeof SipVerb];
@@ -888,6 +897,95 @@ interface Originated {
888
897
  sipCallId?: string;
889
898
  }
890
899
  declare function originateArgs(channel: string, to: string, media: OriginateMedia, options?: OriginateOptions): Record<string, unknown>;
900
+ /**
901
+ * One {@link Call.dial} target: a URI dialed as written, or an AoR forked to
902
+ * every contact registered against it.
903
+ *
904
+ * Two shapes rather than a bare string, because the server accepts both and they
905
+ * do entirely different things. A URI is dialed as written and resolved by DNS.
906
+ * An AoR is resolved against the registrar and forked to *every* registered
907
+ * contact, each branch over that contact's own captured flow — the only way to
908
+ * reach a phone registered over TCP, TLS or WSS behind NAT, since such a contact
909
+ * is reachable only on the connection it registered over.
910
+ * `"sip:204@pbx.example"` is a plausible spelling of both, and the wrong one
911
+ * places a call that connects to nothing while the trace looks healthy.
912
+ */
913
+ type DialTarget = {
914
+ /** The B-leg request URI, dialed as written. */
915
+ uri: string;
916
+ /** Send the INVITE here instead; the R-URI keeps `uri`'s shape. */
917
+ nextHop?: string;
918
+ /** Headers injected on this branch's INVITE, over the command's. */
919
+ headers?: Record<string, string>;
920
+ } | {
921
+ /**
922
+ * The address of record to fork to its registered contacts. It takes no
923
+ * `nextHop`: each branch routes over its own binding's captured flow, so
924
+ * there would be nothing for one to apply to.
925
+ */
926
+ aor: string;
927
+ /** Headers injected on every branch the AoR expands to. */
928
+ headers?: Record<string, string>;
929
+ };
930
+ /**
931
+ * Optional shaping for {@link Call.dial}; anything left out takes the server's
932
+ * own default rather than a copy of it pinned here.
933
+ */
934
+ interface DialOptions {
935
+ /** How to try the targets (`"parallel"` server-side when unset). */
936
+ strategy?: "parallel" | "sequential";
937
+ /** Ring timeout in seconds (30 server-side when unset, clamped to 1..3600). */
938
+ timeout?: number;
939
+ /** Headers injected on every branch's INVITE, under each target's own. */
940
+ headers?: Record<string, string>;
941
+ }
942
+ /**
943
+ * What the server answers an accepted `dial` with: the INVITEs are on the wire
944
+ * and nobody has answered yet.
945
+ */
946
+ interface Dialing {
947
+ /** The channel the targets are being rung for — still the caller's. */
948
+ channel: string;
949
+ /**
950
+ * How many **branches** the server resolved, which an AoR expands: a single
951
+ * AoR target registered on three devices reports three.
952
+ */
953
+ targets?: number;
954
+ /** The strategy in force (the server's default when none was asked for). */
955
+ strategy?: string;
956
+ /** The ring timeout in force, in seconds. */
957
+ timeout?: number;
958
+ }
959
+ /** Which side of the call {@link Call.recordStart} writes. */
960
+ type RecordDirection = "ingress" | "egress" | "both";
961
+ /** The channel layout of the recorded file. */
962
+ type RecordChannels = "mono" | "stereo";
963
+ /** Optional shaping for {@link Call.recordStart}. */
964
+ interface RecordOptions {
965
+ /** Which side to record (`"ingress"` server-side when unset). */
966
+ direction?: RecordDirection;
967
+ /** The file's channel layout (`"mono"` server-side when unset). */
968
+ channels?: RecordChannels;
969
+ /** Stop after this many milliseconds of recording. */
970
+ maxDurationMs?: number;
971
+ /** Stop after this many milliseconds of silence. */
972
+ silenceMs?: number;
973
+ /** Where the engine writes the file. */
974
+ path?: string;
975
+ }
976
+ /** What the server answers an accepted `record_start` with. */
977
+ interface Recording {
978
+ /** The channel being recorded. */
979
+ channel: string;
980
+ /**
981
+ * The id a later {@link Call.recordStop} and the `RecordingFinished` event
982
+ * carry.
983
+ */
984
+ recordingId?: string;
985
+ }
986
+ declare function dialArgs(targets: DialTarget[], options?: DialOptions): Record<string, unknown>;
987
+ declare function recordStartArgs(options?: RecordOptions): Record<string, unknown>;
988
+ declare function recordStopArgs(recordingId?: string): Record<string, unknown>;
891
989
  type PlaySource = {
892
990
  file: string;
893
991
  } | {
@@ -1039,6 +1137,40 @@ declare class Call {
1039
1137
  * that is already gone rejects with `code === "not_found"`.
1040
1138
  */
1041
1139
  route(targets: RouteTarget[], strategy?: string, headers?: Record<string, string>): Promise<unknown>;
1140
+ /**
1141
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
1142
+ * application keeps the channel.
1143
+ *
1144
+ * The difference from {@link Call.route} is who holds the call afterwards.
1145
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
1146
+ * and loses it; there is then no way to say "ring the extension, and if nobody
1147
+ * answers, voicemail" without answering the caller first — which starts
1148
+ * billing before anyone picks up, records an unanswered call as answered, and
1149
+ * denies the caller the callee's own ringback.
1150
+ *
1151
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
1152
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
1153
+ * arrives as a `DialFailed` event with the caller still ringing and still
1154
+ * parked, so the app decides what happens next.
1155
+ *
1156
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
1157
+ * registered contact over its own flow) — see {@link DialTarget}, and note
1158
+ * that a target naming both, or neither, throws before anything is sent.
1159
+ *
1160
+ * ```ts
1161
+ * const dialing = await call.dial(
1162
+ * [{ aor: "sip:204@pbx.example" }],
1163
+ * { strategy: "sequential", timeout: 20 },
1164
+ * );
1165
+ * ```
1166
+ *
1167
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
1168
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
1169
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
1170
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
1171
+ * does not implement).
1172
+ */
1173
+ dial(targets: DialTarget[], options?: DialOptions): Promise<Dialing>;
1042
1174
  /**
1043
1175
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
1044
1176
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1180,6 +1312,32 @@ declare class Call {
1180
1312
  streamStart(wsUri: string, options?: StreamOptions): Promise<void>;
1181
1313
  /** Detach the WebSocket audio tee (idempotent on siphon-rtp). */
1182
1314
  streamStop(): Promise<void>;
1315
+ /**
1316
+ * Record this call's decoded audio to a wav file.
1317
+ *
1318
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1319
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1320
+ * is *closed* and names its path, which is what an app that mails the audio
1321
+ * has to wait for — acting on this reply races a half-written file.
1322
+ *
1323
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1324
+ * greeting announces, and the engine evaluates both where the decoded audio
1325
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1326
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1327
+ * backend only — rtpengine / rtpproxy reject with
1328
+ * `code === "unsupported_verb"`; a call with no anchored media session
1329
+ * rejects with `"not_found"`.
1330
+ */
1331
+ recordStart(options?: RecordOptions): Promise<Recording>;
1332
+ /**
1333
+ * Stop the recording named by `recordingId`, or **every** recording on this
1334
+ * call when it is left out.
1335
+ *
1336
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1337
+ * `RecordingFinished` says that, and carries the path and the reason
1338
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1339
+ */
1340
+ recordStop(recordingId?: string): Promise<void>;
1183
1341
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1184
1342
  command(verb: string, args?: unknown): Promise<unknown>;
1185
1343
  /**
@@ -1283,4 +1441,4 @@ declare class SipServer {
1283
1441
  close(): Promise<void>;
1284
1442
  }
1285
1443
 
1286
- 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, type OriginateMedia, type OriginateOptions, type Originated, 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, type SessionRefresher, type SessionTimer, 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, originateArgs, parseInboundFrame, sipEventKind, transferOutcome };
1444
+ 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 DialOptions, type DialTarget, type Dialing, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, type OriginateMedia, type OriginateOptions, type Originated, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type RecordChannels, type RecordDirection, type RecordOptions, type Recording, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, type SessionRefresher, type SessionTimer, 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, dialArgs, encodeCommand, isBridgeFinal, isTransferFinal, originateArgs, parseInboundFrame, recordStartArgs, recordStopArgs, sipEventKind, transferOutcome };
package/dist/index.d.ts CHANGED
@@ -182,6 +182,11 @@ declare const SipVerb: {
182
182
  readonly Hangup: "hangup";
183
183
  readonly Refer: "refer";
184
184
  readonly Route: "route";
185
+ /**
186
+ * Ring targets as B-legs while the caller stays unanswered and the app keeps
187
+ * the channel. Channel-addressed, unlike `originate`, which creates one.
188
+ */
189
+ readonly Dial: "dial";
185
190
  readonly SetHeader: "set_header";
186
191
  readonly GetHeader: "get_header";
187
192
  readonly RemoveHeader: "remove_header";
@@ -197,6 +202,10 @@ declare const SipVerb: {
197
202
  readonly Unhold: "unhold";
198
203
  readonly StreamStart: "stream_start";
199
204
  readonly StreamStop: "stream_stop";
205
+ /** Record the call's decoded audio to a wav file (siphon-rtp backend only). */
206
+ readonly RecordStart: "record_start";
207
+ /** Stop one recording by id, or every recording on the call. */
208
+ readonly RecordStop: "record_stop";
200
209
  };
201
210
  /** A value of {@link SipVerb}. */
202
211
  type SipVerbToken = (typeof SipVerb)[keyof typeof SipVerb];
@@ -888,6 +897,95 @@ interface Originated {
888
897
  sipCallId?: string;
889
898
  }
890
899
  declare function originateArgs(channel: string, to: string, media: OriginateMedia, options?: OriginateOptions): Record<string, unknown>;
900
+ /**
901
+ * One {@link Call.dial} target: a URI dialed as written, or an AoR forked to
902
+ * every contact registered against it.
903
+ *
904
+ * Two shapes rather than a bare string, because the server accepts both and they
905
+ * do entirely different things. A URI is dialed as written and resolved by DNS.
906
+ * An AoR is resolved against the registrar and forked to *every* registered
907
+ * contact, each branch over that contact's own captured flow — the only way to
908
+ * reach a phone registered over TCP, TLS or WSS behind NAT, since such a contact
909
+ * is reachable only on the connection it registered over.
910
+ * `"sip:204@pbx.example"` is a plausible spelling of both, and the wrong one
911
+ * places a call that connects to nothing while the trace looks healthy.
912
+ */
913
+ type DialTarget = {
914
+ /** The B-leg request URI, dialed as written. */
915
+ uri: string;
916
+ /** Send the INVITE here instead; the R-URI keeps `uri`'s shape. */
917
+ nextHop?: string;
918
+ /** Headers injected on this branch's INVITE, over the command's. */
919
+ headers?: Record<string, string>;
920
+ } | {
921
+ /**
922
+ * The address of record to fork to its registered contacts. It takes no
923
+ * `nextHop`: each branch routes over its own binding's captured flow, so
924
+ * there would be nothing for one to apply to.
925
+ */
926
+ aor: string;
927
+ /** Headers injected on every branch the AoR expands to. */
928
+ headers?: Record<string, string>;
929
+ };
930
+ /**
931
+ * Optional shaping for {@link Call.dial}; anything left out takes the server's
932
+ * own default rather than a copy of it pinned here.
933
+ */
934
+ interface DialOptions {
935
+ /** How to try the targets (`"parallel"` server-side when unset). */
936
+ strategy?: "parallel" | "sequential";
937
+ /** Ring timeout in seconds (30 server-side when unset, clamped to 1..3600). */
938
+ timeout?: number;
939
+ /** Headers injected on every branch's INVITE, under each target's own. */
940
+ headers?: Record<string, string>;
941
+ }
942
+ /**
943
+ * What the server answers an accepted `dial` with: the INVITEs are on the wire
944
+ * and nobody has answered yet.
945
+ */
946
+ interface Dialing {
947
+ /** The channel the targets are being rung for — still the caller's. */
948
+ channel: string;
949
+ /**
950
+ * How many **branches** the server resolved, which an AoR expands: a single
951
+ * AoR target registered on three devices reports three.
952
+ */
953
+ targets?: number;
954
+ /** The strategy in force (the server's default when none was asked for). */
955
+ strategy?: string;
956
+ /** The ring timeout in force, in seconds. */
957
+ timeout?: number;
958
+ }
959
+ /** Which side of the call {@link Call.recordStart} writes. */
960
+ type RecordDirection = "ingress" | "egress" | "both";
961
+ /** The channel layout of the recorded file. */
962
+ type RecordChannels = "mono" | "stereo";
963
+ /** Optional shaping for {@link Call.recordStart}. */
964
+ interface RecordOptions {
965
+ /** Which side to record (`"ingress"` server-side when unset). */
966
+ direction?: RecordDirection;
967
+ /** The file's channel layout (`"mono"` server-side when unset). */
968
+ channels?: RecordChannels;
969
+ /** Stop after this many milliseconds of recording. */
970
+ maxDurationMs?: number;
971
+ /** Stop after this many milliseconds of silence. */
972
+ silenceMs?: number;
973
+ /** Where the engine writes the file. */
974
+ path?: string;
975
+ }
976
+ /** What the server answers an accepted `record_start` with. */
977
+ interface Recording {
978
+ /** The channel being recorded. */
979
+ channel: string;
980
+ /**
981
+ * The id a later {@link Call.recordStop} and the `RecordingFinished` event
982
+ * carry.
983
+ */
984
+ recordingId?: string;
985
+ }
986
+ declare function dialArgs(targets: DialTarget[], options?: DialOptions): Record<string, unknown>;
987
+ declare function recordStartArgs(options?: RecordOptions): Record<string, unknown>;
988
+ declare function recordStopArgs(recordingId?: string): Record<string, unknown>;
891
989
  type PlaySource = {
892
990
  file: string;
893
991
  } | {
@@ -1039,6 +1137,40 @@ declare class Call {
1039
1137
  * that is already gone rejects with `code === "not_found"`.
1040
1138
  */
1041
1139
  route(targets: RouteTarget[], strategy?: string, headers?: Record<string, string>): Promise<unknown>;
1140
+ /**
1141
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
1142
+ * application keeps the channel.
1143
+ *
1144
+ * The difference from {@link Call.route} is who holds the call afterwards.
1145
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
1146
+ * and loses it; there is then no way to say "ring the extension, and if nobody
1147
+ * answers, voicemail" without answering the caller first — which starts
1148
+ * billing before anyone picks up, records an unanswered call as answered, and
1149
+ * denies the caller the callee's own ringback.
1150
+ *
1151
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
1152
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
1153
+ * arrives as a `DialFailed` event with the caller still ringing and still
1154
+ * parked, so the app decides what happens next.
1155
+ *
1156
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
1157
+ * registered contact over its own flow) — see {@link DialTarget}, and note
1158
+ * that a target naming both, or neither, throws before anything is sent.
1159
+ *
1160
+ * ```ts
1161
+ * const dialing = await call.dial(
1162
+ * [{ aor: "sip:204@pbx.example" }],
1163
+ * { strategy: "sequential", timeout: 20 },
1164
+ * );
1165
+ * ```
1166
+ *
1167
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
1168
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
1169
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
1170
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
1171
+ * does not implement).
1172
+ */
1173
+ dial(targets: DialTarget[], options?: DialOptions): Promise<Dialing>;
1042
1174
  /**
1043
1175
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
1044
1176
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1180,6 +1312,32 @@ declare class Call {
1180
1312
  streamStart(wsUri: string, options?: StreamOptions): Promise<void>;
1181
1313
  /** Detach the WebSocket audio tee (idempotent on siphon-rtp). */
1182
1314
  streamStop(): Promise<void>;
1315
+ /**
1316
+ * Record this call's decoded audio to a wav file.
1317
+ *
1318
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1319
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1320
+ * is *closed* and names its path, which is what an app that mails the audio
1321
+ * has to wait for — acting on this reply races a half-written file.
1322
+ *
1323
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1324
+ * greeting announces, and the engine evaluates both where the decoded audio
1325
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1326
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1327
+ * backend only — rtpengine / rtpproxy reject with
1328
+ * `code === "unsupported_verb"`; a call with no anchored media session
1329
+ * rejects with `"not_found"`.
1330
+ */
1331
+ recordStart(options?: RecordOptions): Promise<Recording>;
1332
+ /**
1333
+ * Stop the recording named by `recordingId`, or **every** recording on this
1334
+ * call when it is left out.
1335
+ *
1336
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1337
+ * `RecordingFinished` says that, and carries the path and the reason
1338
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1339
+ */
1340
+ recordStop(recordingId?: string): Promise<void>;
1183
1341
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1184
1342
  command(verb: string, args?: unknown): Promise<unknown>;
1185
1343
  /**
@@ -1283,4 +1441,4 @@ declare class SipServer {
1283
1441
  close(): Promise<void>;
1284
1442
  }
1285
1443
 
1286
- 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, type OriginateMedia, type OriginateOptions, type Originated, 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, type SessionRefresher, type SessionTimer, 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, originateArgs, parseInboundFrame, sipEventKind, transferOutcome };
1444
+ 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 DialOptions, type DialTarget, type Dialing, type DtmfOptions, type EventFrame, type EventSink, EventStream, type FrameType, GET_VAR, HELLO, type HelloArgs, type HelloResult, MODULE_SIP, MODULE_SMPP, MODULE_SS7, type OriginateMedia, type OriginateOptions, type Originated, PROTOCOL_VERSION, type PeerHangupPolicy, type PlayFinishedPayload, type PlayOptions, type PlaySource, type PlayStartedPayload, RESYNC, type RecordChannels, type RecordDirection, type RecordOptions, type Recording, type ReferReplaces, type ReplyError, type ReplyFrame, type ReplyStatus, type ResponseOptions, type ResyncResult, type RouteTarget, type RouteTargetObject, SET_VAR, SUBPROTOCOL, type ServerConfig, type SessionRefresher, type SessionTimer, 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, dialArgs, encodeCommand, isBridgeFinal, isTransferFinal, originateArgs, parseInboundFrame, recordStartArgs, recordStopArgs, sipEventKind, transferOutcome };
package/dist/index.js CHANGED
@@ -112,6 +112,11 @@ var SipVerb = {
112
112
  Hangup: "hangup",
113
113
  Refer: "refer",
114
114
  Route: "route",
115
+ /**
116
+ * Ring targets as B-legs while the caller stays unanswered and the app keeps
117
+ * the channel. Channel-addressed, unlike `originate`, which creates one.
118
+ */
119
+ Dial: "dial",
115
120
  SetHeader: "set_header",
116
121
  GetHeader: "get_header",
117
122
  RemoveHeader: "remove_header",
@@ -126,7 +131,11 @@ var SipVerb = {
126
131
  Hold: "hold",
127
132
  Unhold: "unhold",
128
133
  StreamStart: "stream_start",
129
- StreamStop: "stream_stop"
134
+ StreamStop: "stream_stop",
135
+ /** Record the call's decoded audio to a wav file (siphon-rtp backend only). */
136
+ RecordStart: "record_start",
137
+ /** Stop one recording by id, or every recording on the call. */
138
+ RecordStop: "record_stop"
130
139
  };
131
140
  function sipEventKind(name) {
132
141
  return name;
@@ -674,6 +683,56 @@ function originateArgs(channel, to, media, options) {
674
683
  }
675
684
  return args;
676
685
  }
686
+ function dialTargetToWire(target) {
687
+ const uri = target.uri;
688
+ const aor = target.aor;
689
+ const nextHop = target.nextHop;
690
+ const headers = target.headers;
691
+ if (typeof uri === "string" && typeof aor === "string") {
692
+ throw new TypeError(
693
+ 'a dial target names "uri" or "aor", never both \u2014 siphon reads the aor and ignores the uri beside it, so this would place a different call'
694
+ );
695
+ }
696
+ if (typeof aor === "string") {
697
+ if (nextHop !== void 0) {
698
+ throw new TypeError(
699
+ `an aor target takes no "nextHop": each of its branches routes over its own contact's captured flow`
700
+ );
701
+ }
702
+ const object2 = { aor };
703
+ if (headers !== void 0) object2.headers = headers;
704
+ return object2;
705
+ }
706
+ if (typeof uri !== "string") {
707
+ throw new TypeError('a dial target requires a string "uri" or "aor"');
708
+ }
709
+ if (nextHop === void 0 && headers === void 0) return uri;
710
+ const object = { uri };
711
+ if (nextHop !== void 0) object.next_hop = nextHop;
712
+ if (headers !== void 0) object.headers = headers;
713
+ return object;
714
+ }
715
+ function dialArgs(targets, options) {
716
+ const args = { targets: targets.map(dialTargetToWire) };
717
+ if (!options) return args;
718
+ if (options.strategy !== void 0) args.strategy = options.strategy;
719
+ if (options.timeout !== void 0) args.timeout = options.timeout;
720
+ if (options.headers !== void 0) args.headers = options.headers;
721
+ return args;
722
+ }
723
+ function recordStartArgs(options) {
724
+ const args = {};
725
+ if (!options) return args;
726
+ if (options.direction !== void 0) args.direction = options.direction;
727
+ if (options.channels !== void 0) args.channels = options.channels;
728
+ if (options.maxDurationMs !== void 0) args.max_duration_ms = options.maxDurationMs;
729
+ if (options.silenceMs !== void 0) args.silence_ms = options.silenceMs;
730
+ if (options.path !== void 0) args.path = options.path;
731
+ return args;
732
+ }
733
+ function recordStopArgs(recordingId) {
734
+ return recordingId === void 0 ? {} : { recording_id: recordingId };
735
+ }
677
736
  function playArgs(source, options) {
678
737
  const args = {};
679
738
  if ("file" in source) {
@@ -876,6 +935,58 @@ var Call = class {
876
935
  }
877
936
  return this.sip(SipVerb.Route, args);
878
937
  }
938
+ /**
939
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
940
+ * application keeps the channel.
941
+ *
942
+ * The difference from {@link Call.route} is who holds the call afterwards.
943
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
944
+ * and loses it; there is then no way to say "ring the extension, and if nobody
945
+ * answers, voicemail" without answering the caller first — which starts
946
+ * billing before anyone picks up, records an unanswered call as answered, and
947
+ * denies the caller the callee's own ringback.
948
+ *
949
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
950
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
951
+ * arrives as a `DialFailed` event with the caller still ringing and still
952
+ * parked, so the app decides what happens next.
953
+ *
954
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
955
+ * registered contact over its own flow) — see {@link DialTarget}, and note
956
+ * that a target naming both, or neither, throws before anything is sent.
957
+ *
958
+ * ```ts
959
+ * const dialing = await call.dial(
960
+ * [{ aor: "sip:204@pbx.example" }],
961
+ * { strategy: "sequential", timeout: 20 },
962
+ * );
963
+ * ```
964
+ *
965
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
966
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
967
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
968
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
969
+ * does not implement).
970
+ */
971
+ async dial(targets, options) {
972
+ const result = await this.sip(SipVerb.Dial, dialArgs(targets, options));
973
+ const text = (name) => {
974
+ const value = result?.[name];
975
+ return typeof value === "string" ? value : void 0;
976
+ };
977
+ const count = (name) => {
978
+ const value = result?.[name];
979
+ return typeof value === "number" ? value : void 0;
980
+ };
981
+ return {
982
+ // The server echoes the channel back; fall back to the one addressed
983
+ // rather than returning an empty id.
984
+ channel: text("channel") ?? this.channelId,
985
+ targets: count("targets"),
986
+ strategy: text("strategy"),
987
+ timeout: count("timeout")
988
+ };
989
+ }
879
990
  /**
880
991
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
881
992
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1085,6 +1196,47 @@ var Call = class {
1085
1196
  async streamStop() {
1086
1197
  await this.sip(SipVerb.StreamStop, {});
1087
1198
  }
1199
+ /**
1200
+ * Record this call's decoded audio to a wav file.
1201
+ *
1202
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1203
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1204
+ * is *closed* and names its path, which is what an app that mails the audio
1205
+ * has to wait for — acting on this reply races a half-written file.
1206
+ *
1207
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1208
+ * greeting announces, and the engine evaluates both where the decoded audio
1209
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1210
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1211
+ * backend only — rtpengine / rtpproxy reject with
1212
+ * `code === "unsupported_verb"`; a call with no anchored media session
1213
+ * rejects with `"not_found"`.
1214
+ */
1215
+ async recordStart(options) {
1216
+ const result = await this.sip(
1217
+ SipVerb.RecordStart,
1218
+ recordStartArgs(options)
1219
+ );
1220
+ const text = (name) => {
1221
+ const value = result?.[name];
1222
+ return typeof value === "string" ? value : void 0;
1223
+ };
1224
+ return {
1225
+ channel: text("channel") ?? this.channelId,
1226
+ recordingId: text("recording_id")
1227
+ };
1228
+ }
1229
+ /**
1230
+ * Stop the recording named by `recordingId`, or **every** recording on this
1231
+ * call when it is left out.
1232
+ *
1233
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1234
+ * `RecordingFinished` says that, and carries the path and the reason
1235
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1236
+ */
1237
+ async recordStop(recordingId) {
1238
+ await this.sip(SipVerb.RecordStop, recordStopArgs(recordingId));
1239
+ }
1088
1240
  // --- escape hatch + events --------------------------------------------
1089
1241
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1090
1242
  async command(verb, args) {
@@ -1322,6 +1474,6 @@ var SipServer = class _SipServer {
1322
1474
  }
1323
1475
  };
1324
1476
 
1325
- 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, originateArgs, parseInboundFrame, sipEventKind, transferOutcome };
1477
+ 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, isTransferFinal, originateArgs, parseInboundFrame, recordStartArgs, recordStopArgs, sipEventKind, transferOutcome };
1326
1478
  //# sourceMappingURL=index.js.map
1327
1479
  //# sourceMappingURL=index.js.map