@siphon-project/control 0.3.0 → 0.5.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,132 @@ 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
+ * A configured media profile to anchor both legs through, so the caller and
943
+ * the phones never exchange media directly.
944
+ *
945
+ * What a carrier-delivered call to a ring group needs: the carrier hands over
946
+ * plain RTP at a routable address and every phone answers from an address on
947
+ * its own LAN, so without the relay in the middle the two ends cannot reach
948
+ * each other. Left out, the caller's own SDP passes through.
949
+ */
950
+ profile?: string;
951
+ /**
952
+ * The calling identity to present — the From URI (RFC 3261 §8.1.1.3).
953
+ *
954
+ * Without it a B-leg presents the caller's own From, which on a call out to a
955
+ * trunk is the internal extension. A carrier that looks its account up by the
956
+ * From user does not recognise that, so it challenges the INVITE and keeps
957
+ * challenging however correct the digest is. A `headers` entry cannot do
958
+ * this: From is framework-managed on a B-leg and is rewritten after the fact.
959
+ */
960
+ from?: string;
961
+ /**
962
+ * The From display name. Naming a `from` without one drops the caller's
963
+ * rather than presenting it beside a number that replaced it.
964
+ */
965
+ fromDisplay?: string;
966
+ /**
967
+ * `P-Asserted-Identity` for a trusted next hop (RFC 3325 §9.1). Reaches the
968
+ * wire after the header policy, so a preset that strips `P-*` at a trust
969
+ * boundary cannot silently drop it.
970
+ */
971
+ pAssertedIdentity?: string;
972
+ /**
973
+ * Whether the calling identity may be presented (RFC 3323 §4.1 / TS 24.607).
974
+ * `"restricted"` anonymises From and asserts `Privacy: id`, keeping the real
975
+ * identity in `pAssertedIdentity` for the trusted next hop.
976
+ */
977
+ privacy?: "allowed" | "restricted";
978
+ }
979
+ /**
980
+ * What the server answers an accepted `dial` with: the INVITEs are on the wire
981
+ * and nobody has answered yet.
982
+ */
983
+ interface Dialing {
984
+ /** The channel the targets are being rung for — still the caller's. */
985
+ channel: string;
986
+ /**
987
+ * How many **branches** the server resolved, which an AoR expands: a single
988
+ * AoR target registered on three devices reports three.
989
+ */
990
+ targets?: number;
991
+ /** The strategy in force (the server's default when none was asked for). */
992
+ strategy?: string;
993
+ /** The ring timeout in force, in seconds. */
994
+ timeout?: number;
995
+ }
996
+ /** Which side of the call {@link Call.recordStart} writes. */
997
+ type RecordDirection = "ingress" | "egress" | "both";
998
+ /** The channel layout of the recorded file. */
999
+ type RecordChannels = "mono" | "stereo";
1000
+ /** Optional shaping for {@link Call.recordStart}. */
1001
+ interface RecordOptions {
1002
+ /** Which side to record (`"ingress"` server-side when unset). */
1003
+ direction?: RecordDirection;
1004
+ /** The file's channel layout (`"mono"` server-side when unset). */
1005
+ channels?: RecordChannels;
1006
+ /** Stop after this many milliseconds of recording. */
1007
+ maxDurationMs?: number;
1008
+ /** Stop after this many milliseconds of silence. */
1009
+ silenceMs?: number;
1010
+ /** Where the engine writes the file. */
1011
+ path?: string;
1012
+ }
1013
+ /** What the server answers an accepted `record_start` with. */
1014
+ interface Recording {
1015
+ /** The channel being recorded. */
1016
+ channel: string;
1017
+ /**
1018
+ * The id a later {@link Call.recordStop} and the `RecordingFinished` event
1019
+ * carry.
1020
+ */
1021
+ recordingId?: string;
1022
+ }
1023
+ declare function dialArgs(targets: DialTarget[], options?: DialOptions): Record<string, unknown>;
1024
+ declare function recordStartArgs(options?: RecordOptions): Record<string, unknown>;
1025
+ declare function recordStopArgs(recordingId?: string): Record<string, unknown>;
891
1026
  type PlaySource = {
892
1027
  file: string;
893
1028
  } | {
@@ -1039,6 +1174,40 @@ declare class Call {
1039
1174
  * that is already gone rejects with `code === "not_found"`.
1040
1175
  */
1041
1176
  route(targets: RouteTarget[], strategy?: string, headers?: Record<string, string>): Promise<unknown>;
1177
+ /**
1178
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
1179
+ * application keeps the channel.
1180
+ *
1181
+ * The difference from {@link Call.route} is who holds the call afterwards.
1182
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
1183
+ * and loses it; there is then no way to say "ring the extension, and if nobody
1184
+ * answers, voicemail" without answering the caller first — which starts
1185
+ * billing before anyone picks up, records an unanswered call as answered, and
1186
+ * denies the caller the callee's own ringback.
1187
+ *
1188
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
1189
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
1190
+ * arrives as a `DialFailed` event with the caller still ringing and still
1191
+ * parked, so the app decides what happens next.
1192
+ *
1193
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
1194
+ * registered contact over its own flow) — see {@link DialTarget}, and note
1195
+ * that a target naming both, or neither, throws before anything is sent.
1196
+ *
1197
+ * ```ts
1198
+ * const dialing = await call.dial(
1199
+ * [{ aor: "sip:204@pbx.example" }],
1200
+ * { strategy: "sequential", timeout: 20 },
1201
+ * );
1202
+ * ```
1203
+ *
1204
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
1205
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
1206
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
1207
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
1208
+ * does not implement).
1209
+ */
1210
+ dial(targets: DialTarget[], options?: DialOptions): Promise<Dialing>;
1042
1211
  /**
1043
1212
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
1044
1213
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1180,6 +1349,32 @@ declare class Call {
1180
1349
  streamStart(wsUri: string, options?: StreamOptions): Promise<void>;
1181
1350
  /** Detach the WebSocket audio tee (idempotent on siphon-rtp). */
1182
1351
  streamStop(): Promise<void>;
1352
+ /**
1353
+ * Record this call's decoded audio to a wav file.
1354
+ *
1355
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1356
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1357
+ * is *closed* and names its path, which is what an app that mails the audio
1358
+ * has to wait for — acting on this reply races a half-written file.
1359
+ *
1360
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1361
+ * greeting announces, and the engine evaluates both where the decoded audio
1362
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1363
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1364
+ * backend only — rtpengine / rtpproxy reject with
1365
+ * `code === "unsupported_verb"`; a call with no anchored media session
1366
+ * rejects with `"not_found"`.
1367
+ */
1368
+ recordStart(options?: RecordOptions): Promise<Recording>;
1369
+ /**
1370
+ * Stop the recording named by `recordingId`, or **every** recording on this
1371
+ * call when it is left out.
1372
+ *
1373
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1374
+ * `RecordingFinished` says that, and carries the path and the reason
1375
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1376
+ */
1377
+ recordStop(recordingId?: string): Promise<void>;
1183
1378
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1184
1379
  command(verb: string, args?: unknown): Promise<unknown>;
1185
1380
  /**
@@ -1283,4 +1478,4 @@ declare class SipServer {
1283
1478
  close(): Promise<void>;
1284
1479
  }
1285
1480
 
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 };
1481
+ 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,132 @@ 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
+ * A configured media profile to anchor both legs through, so the caller and
943
+ * the phones never exchange media directly.
944
+ *
945
+ * What a carrier-delivered call to a ring group needs: the carrier hands over
946
+ * plain RTP at a routable address and every phone answers from an address on
947
+ * its own LAN, so without the relay in the middle the two ends cannot reach
948
+ * each other. Left out, the caller's own SDP passes through.
949
+ */
950
+ profile?: string;
951
+ /**
952
+ * The calling identity to present — the From URI (RFC 3261 §8.1.1.3).
953
+ *
954
+ * Without it a B-leg presents the caller's own From, which on a call out to a
955
+ * trunk is the internal extension. A carrier that looks its account up by the
956
+ * From user does not recognise that, so it challenges the INVITE and keeps
957
+ * challenging however correct the digest is. A `headers` entry cannot do
958
+ * this: From is framework-managed on a B-leg and is rewritten after the fact.
959
+ */
960
+ from?: string;
961
+ /**
962
+ * The From display name. Naming a `from` without one drops the caller's
963
+ * rather than presenting it beside a number that replaced it.
964
+ */
965
+ fromDisplay?: string;
966
+ /**
967
+ * `P-Asserted-Identity` for a trusted next hop (RFC 3325 §9.1). Reaches the
968
+ * wire after the header policy, so a preset that strips `P-*` at a trust
969
+ * boundary cannot silently drop it.
970
+ */
971
+ pAssertedIdentity?: string;
972
+ /**
973
+ * Whether the calling identity may be presented (RFC 3323 §4.1 / TS 24.607).
974
+ * `"restricted"` anonymises From and asserts `Privacy: id`, keeping the real
975
+ * identity in `pAssertedIdentity` for the trusted next hop.
976
+ */
977
+ privacy?: "allowed" | "restricted";
978
+ }
979
+ /**
980
+ * What the server answers an accepted `dial` with: the INVITEs are on the wire
981
+ * and nobody has answered yet.
982
+ */
983
+ interface Dialing {
984
+ /** The channel the targets are being rung for — still the caller's. */
985
+ channel: string;
986
+ /**
987
+ * How many **branches** the server resolved, which an AoR expands: a single
988
+ * AoR target registered on three devices reports three.
989
+ */
990
+ targets?: number;
991
+ /** The strategy in force (the server's default when none was asked for). */
992
+ strategy?: string;
993
+ /** The ring timeout in force, in seconds. */
994
+ timeout?: number;
995
+ }
996
+ /** Which side of the call {@link Call.recordStart} writes. */
997
+ type RecordDirection = "ingress" | "egress" | "both";
998
+ /** The channel layout of the recorded file. */
999
+ type RecordChannels = "mono" | "stereo";
1000
+ /** Optional shaping for {@link Call.recordStart}. */
1001
+ interface RecordOptions {
1002
+ /** Which side to record (`"ingress"` server-side when unset). */
1003
+ direction?: RecordDirection;
1004
+ /** The file's channel layout (`"mono"` server-side when unset). */
1005
+ channels?: RecordChannels;
1006
+ /** Stop after this many milliseconds of recording. */
1007
+ maxDurationMs?: number;
1008
+ /** Stop after this many milliseconds of silence. */
1009
+ silenceMs?: number;
1010
+ /** Where the engine writes the file. */
1011
+ path?: string;
1012
+ }
1013
+ /** What the server answers an accepted `record_start` with. */
1014
+ interface Recording {
1015
+ /** The channel being recorded. */
1016
+ channel: string;
1017
+ /**
1018
+ * The id a later {@link Call.recordStop} and the `RecordingFinished` event
1019
+ * carry.
1020
+ */
1021
+ recordingId?: string;
1022
+ }
1023
+ declare function dialArgs(targets: DialTarget[], options?: DialOptions): Record<string, unknown>;
1024
+ declare function recordStartArgs(options?: RecordOptions): Record<string, unknown>;
1025
+ declare function recordStopArgs(recordingId?: string): Record<string, unknown>;
891
1026
  type PlaySource = {
892
1027
  file: string;
893
1028
  } | {
@@ -1039,6 +1174,40 @@ declare class Call {
1039
1174
  * that is already gone rejects with `code === "not_found"`.
1040
1175
  */
1041
1176
  route(targets: RouteTarget[], strategy?: string, headers?: Record<string, string>): Promise<unknown>;
1177
+ /**
1178
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
1179
+ * application keeps the channel.
1180
+ *
1181
+ * The difference from {@link Call.route} is who holds the call afterwards.
1182
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
1183
+ * and loses it; there is then no way to say "ring the extension, and if nobody
1184
+ * answers, voicemail" without answering the caller first — which starts
1185
+ * billing before anyone picks up, records an unanswered call as answered, and
1186
+ * denies the caller the callee's own ringback.
1187
+ *
1188
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
1189
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
1190
+ * arrives as a `DialFailed` event with the caller still ringing and still
1191
+ * parked, so the app decides what happens next.
1192
+ *
1193
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
1194
+ * registered contact over its own flow) — see {@link DialTarget}, and note
1195
+ * that a target naming both, or neither, throws before anything is sent.
1196
+ *
1197
+ * ```ts
1198
+ * const dialing = await call.dial(
1199
+ * [{ aor: "sip:204@pbx.example" }],
1200
+ * { strategy: "sequential", timeout: 20 },
1201
+ * );
1202
+ * ```
1203
+ *
1204
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
1205
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
1206
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
1207
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
1208
+ * does not implement).
1209
+ */
1210
+ dial(targets: DialTarget[], options?: DialOptions): Promise<Dialing>;
1042
1211
  /**
1043
1212
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
1044
1213
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1180,6 +1349,32 @@ declare class Call {
1180
1349
  streamStart(wsUri: string, options?: StreamOptions): Promise<void>;
1181
1350
  /** Detach the WebSocket audio tee (idempotent on siphon-rtp). */
1182
1351
  streamStop(): Promise<void>;
1352
+ /**
1353
+ * Record this call's decoded audio to a wav file.
1354
+ *
1355
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1356
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1357
+ * is *closed* and names its path, which is what an app that mails the audio
1358
+ * has to wait for — acting on this reply races a half-written file.
1359
+ *
1360
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1361
+ * greeting announces, and the engine evaluates both where the decoded audio
1362
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1363
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1364
+ * backend only — rtpengine / rtpproxy reject with
1365
+ * `code === "unsupported_verb"`; a call with no anchored media session
1366
+ * rejects with `"not_found"`.
1367
+ */
1368
+ recordStart(options?: RecordOptions): Promise<Recording>;
1369
+ /**
1370
+ * Stop the recording named by `recordingId`, or **every** recording on this
1371
+ * call when it is left out.
1372
+ *
1373
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1374
+ * `RecordingFinished` says that, and carries the path and the reason
1375
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1376
+ */
1377
+ recordStop(recordingId?: string): Promise<void>;
1183
1378
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1184
1379
  command(verb: string, args?: unknown): Promise<unknown>;
1185
1380
  /**
@@ -1283,4 +1478,4 @@ declare class SipServer {
1283
1478
  close(): Promise<void>;
1284
1479
  }
1285
1480
 
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 };
1481
+ 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,63 @@ 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
+ if (options.profile !== void 0) args.profile = options.profile;
722
+ if (options.from !== void 0) args.from = options.from;
723
+ if (options.fromDisplay !== void 0) args.from_display = options.fromDisplay;
724
+ if (options.pAssertedIdentity !== void 0) {
725
+ args.p_asserted_identity = options.pAssertedIdentity;
726
+ }
727
+ if (options.privacy !== void 0) args.privacy = options.privacy;
728
+ return args;
729
+ }
730
+ function recordStartArgs(options) {
731
+ const args = {};
732
+ if (!options) return args;
733
+ if (options.direction !== void 0) args.direction = options.direction;
734
+ if (options.channels !== void 0) args.channels = options.channels;
735
+ if (options.maxDurationMs !== void 0) args.max_duration_ms = options.maxDurationMs;
736
+ if (options.silenceMs !== void 0) args.silence_ms = options.silenceMs;
737
+ if (options.path !== void 0) args.path = options.path;
738
+ return args;
739
+ }
740
+ function recordStopArgs(recordingId) {
741
+ return recordingId === void 0 ? {} : { recording_id: recordingId };
742
+ }
677
743
  function playArgs(source, options) {
678
744
  const args = {};
679
745
  if ("file" in source) {
@@ -876,6 +942,58 @@ var Call = class {
876
942
  }
877
943
  return this.sip(SipVerb.Route, args);
878
944
  }
945
+ /**
946
+ * Ring `targets` as B-legs while the caller stays **unanswered** and this
947
+ * application keeps the channel.
948
+ *
949
+ * The difference from {@link Call.route} is who holds the call afterwards.
950
+ * `route` hands it back to siphon, so the app gets `StasisEnd{reason: routed}`
951
+ * and loses it; there is then no way to say "ring the extension, and if nobody
952
+ * answers, voicemail" without answering the caller first — which starts
953
+ * billing before anyone picks up, records an unanswered call as answered, and
954
+ * denies the caller the callee's own ringback.
955
+ *
956
+ * The first 2xx answers the caller with the winner's SDP and the pair becomes
957
+ * an ordinary two-leg call, still owned by this app. A failure or timeout
958
+ * arrives as a `DialFailed` event with the caller still ringing and still
959
+ * parked, so the app decides what happens next.
960
+ *
961
+ * Each target is a URI (dialed as written) or an `{aor}` (forked to every
962
+ * registered contact over its own flow) — see {@link DialTarget}, and note
963
+ * that a target naming both, or neither, throws before anything is sent.
964
+ *
965
+ * ```ts
966
+ * const dialing = await call.dial(
967
+ * [{ aor: "sip:204@pbx.example" }],
968
+ * { strategy: "sequential", timeout: 20 },
969
+ * );
970
+ * ```
971
+ *
972
+ * Rejects with `code === "not_found"` (the call is gone, or no target yielded
973
+ * a branch — an AoR nobody has registered), `"invalid_state"` (already
974
+ * answered, which is what this verb exists to avoid), `"bad_request"` (an
975
+ * empty or malformed target list) or `"unsupported_verb"` (a strategy siphon
976
+ * does not implement).
977
+ */
978
+ async dial(targets, options) {
979
+ const result = await this.sip(SipVerb.Dial, dialArgs(targets, options));
980
+ const text = (name) => {
981
+ const value = result?.[name];
982
+ return typeof value === "string" ? value : void 0;
983
+ };
984
+ const count = (name) => {
985
+ const value = result?.[name];
986
+ return typeof value === "number" ? value : void 0;
987
+ };
988
+ return {
989
+ // The server echoes the channel back; fall back to the one addressed
990
+ // rather than returning an empty id.
991
+ channel: text("channel") ?? this.channelId,
992
+ targets: count("targets"),
993
+ strategy: text("strategy"),
994
+ timeout: count("timeout")
995
+ };
996
+ }
879
997
  /**
880
998
  * Accept a *pending inbound* REFER (surfaced as a `TransferRequested` event)
881
999
  * and run the transfer. `target` overrides the Refer-To URI, `nextHop` steers
@@ -1085,6 +1203,47 @@ var Call = class {
1085
1203
  async streamStop() {
1086
1204
  await this.sip(SipVerb.StreamStop, {});
1087
1205
  }
1206
+ /**
1207
+ * Record this call's decoded audio to a wav file.
1208
+ *
1209
+ * The reply names the `recordingId` a later {@link Call.recordStop}
1210
+ * addresses. It is **not** the file: `RecordingFinished` fires when the file
1211
+ * is *closed* and names its path, which is what an app that mails the audio
1212
+ * has to wait for — acting on this reply races a half-written file.
1213
+ *
1214
+ * `maxDurationMs` and `silenceMs` are the two stop conditions a voicemail
1215
+ * greeting announces, and the engine evaluates both where the decoded audio
1216
+ * already is. Not SIPREC: this writes a file and works on a single-leg,
1217
+ * engine-terminated call, which is what a voicemail box is. siphon-rtp
1218
+ * backend only — rtpengine / rtpproxy reject with
1219
+ * `code === "unsupported_verb"`; a call with no anchored media session
1220
+ * rejects with `"not_found"`.
1221
+ */
1222
+ async recordStart(options) {
1223
+ const result = await this.sip(
1224
+ SipVerb.RecordStart,
1225
+ recordStartArgs(options)
1226
+ );
1227
+ const text = (name) => {
1228
+ const value = result?.[name];
1229
+ return typeof value === "string" ? value : void 0;
1230
+ };
1231
+ return {
1232
+ channel: text("channel") ?? this.channelId,
1233
+ recordingId: text("recording_id")
1234
+ };
1235
+ }
1236
+ /**
1237
+ * Stop the recording named by `recordingId`, or **every** recording on this
1238
+ * call when it is left out.
1239
+ *
1240
+ * Resolves once the engine has accepted the stop; the file is not closed yet.
1241
+ * `RecordingFinished` says that, and carries the path and the reason
1242
+ * (`stopped`, `max_duration`, `silence`, `call_ended`, `error`).
1243
+ */
1244
+ async recordStop(recordingId) {
1245
+ await this.sip(SipVerb.RecordStop, recordStopArgs(recordingId));
1246
+ }
1088
1247
  // --- escape hatch + events --------------------------------------------
1089
1248
  /** Send an arbitrary SIP-adapter verb + args and return the raw result. */
1090
1249
  async command(verb, args) {
@@ -1322,6 +1481,6 @@ var SipServer = class _SipServer {
1322
1481
  }
1323
1482
  };
1324
1483
 
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 };
1484
+ 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
1485
  //# sourceMappingURL=index.js.map
1327
1486
  //# sourceMappingURL=index.js.map