@voctiv/agent-sdk 0.2.6 → 0.2.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +288 -13
- package/dist/define-script.d.ts +7 -321
- package/dist/define-script.d.ts.map +1 -1
- package/dist/define-script.js +4 -3
- package/dist/define-script.js.map +1 -1
- package/dist/index.d.ts +8 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/asr-handle.d.ts +23 -10
- package/dist/types/asr-handle.d.ts.map +1 -1
- package/dist/types/errors.d.ts +19 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +3 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/llm.d.ts +78 -0
- package/dist/types/llm.d.ts.map +1 -0
- package/dist/types/llm.js +3 -0
- package/dist/types/llm.js.map +1 -0
- package/dist/types/media-channel.d.ts +20 -559
- package/dist/types/media-channel.d.ts.map +1 -1
- package/dist/types/mixer.d.ts +7 -5
- package/dist/types/mixer.d.ts.map +1 -1
- package/dist/types/platform.d.ts +164 -0
- package/dist/types/platform.d.ts.map +1 -0
- package/dist/types/platform.js +3 -0
- package/dist/types/platform.js.map +1 -0
- package/dist/types/script-context.d.ts +170 -0
- package/dist/types/script-context.d.ts.map +1 -0
- package/dist/types/script-context.js +3 -0
- package/dist/types/script-context.js.map +1 -0
- package/dist/types/sip.d.ts +485 -0
- package/dist/types/sip.d.ts.map +1 -0
- package/dist/types/sip.js +3 -0
- package/dist/types/sip.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,485 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { DtmfEvent, SipInfo, SipSignal } from './events';
|
|
3
|
+
import type { MediaChannel } from './media-channel';
|
|
4
|
+
/**
|
|
5
|
+
* SIP call state visible to script developers.
|
|
6
|
+
*
|
|
7
|
+
* ### Lifecycle
|
|
8
|
+
*
|
|
9
|
+
* ```
|
|
10
|
+
* outbound 183 w/ SDP
|
|
11
|
+
* idle ──► ringing ─────────────────► early ──► active ──► terminated
|
|
12
|
+
* │ ▲ ▲
|
|
13
|
+
* │ inbound │ │
|
|
14
|
+
* │ sendProgress()───────┘ │
|
|
15
|
+
* └───────────────────────────────────┘ (early may be skipped)
|
|
16
|
+
* ```
|
|
17
|
+
*
|
|
18
|
+
* | State | Meaning | How you get here |
|
|
19
|
+
* |---|---|---|
|
|
20
|
+
* | **`idle`** | Call object exists but no SIP signalling has started yet. | Initial state. |
|
|
21
|
+
* | **`ringing`** | INVITE sent (outbound) or received (inbound); remote party is ringing. No media yet. | Automatic after INVITE. |
|
|
22
|
+
* | **`early`** | RTP pipeline is up — you can **send and receive audio**, run ASR, play TTS. This is the "pre-answer" phase before final 200 OK. | **Outbound:** remote sends 183 Session Progress with SDP. **Inbound:** your script calls `sip.sendProgress()`. |
|
|
23
|
+
* | **`active`** | 200 OK received/sent — the call is fully established. | **Outbound:** remote answers. **Inbound:** your script calls `sip.answer()`. |
|
|
24
|
+
* | **`holding`** | Local hold is active. | Your script calls `sip.hold()`. |
|
|
25
|
+
* | **`terminated`** | Call ended (BYE, CANCEL, or error). No further audio is possible. | Either side hangs up, or network error. |
|
|
26
|
+
*
|
|
27
|
+
* > **Note:** not every call goes through every state. A fast answer may jump
|
|
28
|
+
* > `ringing` → `active` without `early`. An unanswered outbound call may go
|
|
29
|
+
* > `ringing` → `terminated`. Inbound calls stay in `ringing` until you call
|
|
30
|
+
* > either `sendProgress()` (→ `early`) or `answer()` (→ `active`).
|
|
31
|
+
*/
|
|
32
|
+
export type SipState = 'idle' | 'ringing' | 'early' | 'active' | 'holding' | 'terminated';
|
|
33
|
+
/**
|
|
34
|
+
* A SIP 1xx provisional response forwarded to the script.
|
|
35
|
+
*
|
|
36
|
+
* Provisional responses are sent by the remote party **before** the final answer (200 OK).
|
|
37
|
+
* Common examples:
|
|
38
|
+
*
|
|
39
|
+
* | Code | Phrase | Typical meaning |
|
|
40
|
+
* |------|--------|-----------------|
|
|
41
|
+
* | 100 | Trying | Request received, processing |
|
|
42
|
+
* | 180 | Ringing | Remote phone is ringing (may carry SDP → early media) |
|
|
43
|
+
* | 183 | Session Progress | Early media available — SDP is present, RTP can flow |
|
|
44
|
+
*
|
|
45
|
+
* Subscribe to `sip.progress$` to track every provisional response. The `sdp` field
|
|
46
|
+
* is present only when the response carries a Session Description (media offer/answer).
|
|
47
|
+
*/
|
|
48
|
+
export interface SipProgressEvent {
|
|
49
|
+
/** SIP status code (100–199). */
|
|
50
|
+
statusCode: number;
|
|
51
|
+
/** Human-readable reason phrase, e.g. `"Ringing"`, `"Session Progress"`. */
|
|
52
|
+
statusPhrase: string;
|
|
53
|
+
/** Raw SDP body when the provisional response carries a media description. */
|
|
54
|
+
sdp?: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* SIP channel API — call-state observables, DTMF, INFO, hold/mute/hangup,
|
|
58
|
+
* outbound **`makeCall`**, **`bridge`**, and **pre-answer media**.
|
|
59
|
+
*
|
|
60
|
+
* ---
|
|
61
|
+
*
|
|
62
|
+
* ### Pre-answer media (early media)
|
|
63
|
+
*
|
|
64
|
+
* Both **inbound** and **outbound** calls support full-duplex audio **before** the
|
|
65
|
+
* 200 OK answer. In the `"early"` state the RTP pipeline is fully operational —
|
|
66
|
+
* ASR, TTS, `audio.say()`, `audio.play()`, and DTMF all work **exactly the same**
|
|
67
|
+
* as in the `"active"` state.
|
|
68
|
+
*
|
|
69
|
+
* #### Outbound calls
|
|
70
|
+
*
|
|
71
|
+
* The remote side may send **183 Session Progress** with SDP (e.g. an IVR greeting,
|
|
72
|
+
* ringback tone, or DTMF challenge). The call enters `"early"` automatically.
|
|
73
|
+
*
|
|
74
|
+
* #### Inbound calls
|
|
75
|
+
*
|
|
76
|
+
* Call `sip.sendProgress()` to send **183 Session Progress** to the caller. The call
|
|
77
|
+
* enters `"early"` and audio flows in both directions before final 200 OK. The API
|
|
78
|
+
* does not mark the call answered until `sip.answer()`; external billing still depends
|
|
79
|
+
* on carrier policy. Call `sip.answer()` later to complete the answer.
|
|
80
|
+
*
|
|
81
|
+
* ---
|
|
82
|
+
*
|
|
83
|
+
* ### Quick examples
|
|
84
|
+
*
|
|
85
|
+
* #### Outbound — interact with an IVR before answer
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const call = await channel.sip.makeCall({ sipUri: 'sip:+1234@trunk.example.com' });
|
|
89
|
+
*
|
|
90
|
+
* // Wait until RTP is ready (early media or full answer)
|
|
91
|
+
* await call.sip.waitForEarly();
|
|
92
|
+
* // Audio flows — start ASR to listen to the remote IVR
|
|
93
|
+
* const asr = await call.createAsr();
|
|
94
|
+
* asr.result$.subscribe((text) => {
|
|
95
|
+
* if (/press 1/i.test(text)) call.sip.sendDtmf('1');
|
|
96
|
+
* });
|
|
97
|
+
*
|
|
98
|
+
* // Optionally wait for the actual answer
|
|
99
|
+
* await call.sip.waitForAnswer();
|
|
100
|
+
* await call.audio.say('Hello! We are calling about your order.');
|
|
101
|
+
* ```
|
|
102
|
+
*
|
|
103
|
+
* #### Inbound — collect data before the final answer
|
|
104
|
+
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* // Inbound call arrives — state is 'ringing'
|
|
107
|
+
* channel.sip.sendProgress();
|
|
108
|
+
* // State is now 'early' — full duplex audio before final 200 OK
|
|
109
|
+
*
|
|
110
|
+
* const asr = await channel.createAsr();
|
|
111
|
+
* await channel.audio.say('Please say your account number.');
|
|
112
|
+
* const account = await firstValueFrom(asr.result$);
|
|
113
|
+
*
|
|
114
|
+
* // Now send final answer
|
|
115
|
+
* channel.sip.answer();
|
|
116
|
+
* await channel.audio.say(`Thank you! Looking up account ${account}…`);
|
|
117
|
+
* ```
|
|
118
|
+
*
|
|
119
|
+
* #### Inbound — simple answer (no pre-answer)
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* // Inbound call — answer immediately
|
|
123
|
+
* channel.sip.answer();
|
|
124
|
+
* await channel.audio.say('Welcome!');
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* #### Audio auto-buffering
|
|
128
|
+
*
|
|
129
|
+
* You do **not** need to manually wait for early/answer before calling `audio.say()`
|
|
130
|
+
* or `audio.play()`. These methods automatically defer until the RTP pipeline is ready
|
|
131
|
+
* and resolve as no-ops if the call terminates first. The explicit `waitForEarly()` /
|
|
132
|
+
* `waitForAnswer()` await points are useful when you need to **sequence logic** around
|
|
133
|
+
* call state (e.g. create ASR only after media is available).
|
|
134
|
+
*/
|
|
135
|
+
export interface ChannelSip {
|
|
136
|
+
/**
|
|
137
|
+
* Emits every time the remote party sends a DTMF digit (RFC 2833 in-band or SIP INFO).
|
|
138
|
+
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* sip.dtmf$.subscribe(({ digit, duration }) => {
|
|
141
|
+
* console.log(`User pressed ${digit}`);
|
|
142
|
+
* });
|
|
143
|
+
* ```
|
|
144
|
+
*/
|
|
145
|
+
readonly dtmf$: Observable<DtmfEvent>;
|
|
146
|
+
/**
|
|
147
|
+
* Raw SIP INFO messages received on this call leg.
|
|
148
|
+
*
|
|
149
|
+
* Useful for carrier-specific signalling (e.g. `application/dtmf-relay`). On the
|
|
150
|
+
* current SIP runtime this stream is low-level and may not include parsed body
|
|
151
|
+
* details for every Sofia event; prefer `dtmf$` for DTMF.
|
|
152
|
+
*/
|
|
153
|
+
readonly sipInfo$: Observable<SipInfo>;
|
|
154
|
+
/**
|
|
155
|
+
* Low-level SIP state-change events from the underlying Sofia stack.
|
|
156
|
+
*
|
|
157
|
+
* Prefer the higher-level **`state$`**, **`progress$`**, **`early$`**, **`answered$`**
|
|
158
|
+
* observables unless you need raw Sofia event details.
|
|
159
|
+
*/
|
|
160
|
+
readonly sipSignal$: Observable<SipSignal>;
|
|
161
|
+
/**
|
|
162
|
+
* Live observable of the current call state.
|
|
163
|
+
*
|
|
164
|
+
* Emits the new {@link SipState} every time the call transitions. Starts with the
|
|
165
|
+
* state the call was in when the script began (typically `"ringing"` for inbound,
|
|
166
|
+
* `"idle"` or `"ringing"` for outbound).
|
|
167
|
+
*
|
|
168
|
+
* ```ts
|
|
169
|
+
* sip.state$.subscribe((state) => {
|
|
170
|
+
* console.log(`Call state → ${state}`);
|
|
171
|
+
* });
|
|
172
|
+
* ```
|
|
173
|
+
*
|
|
174
|
+
* > **Tip:** for one-shot checks use the synchronous `sip.state` getter instead.
|
|
175
|
+
*/
|
|
176
|
+
readonly state$: Observable<SipState>;
|
|
177
|
+
/**
|
|
178
|
+
* Current call state at the moment of access (synchronous).
|
|
179
|
+
*
|
|
180
|
+
* Returns one of: `'idle'`, `'ringing'`, `'early'`, `'active'`, `'holding'`, `'terminated'`.
|
|
181
|
+
*
|
|
182
|
+
* ```ts
|
|
183
|
+
* if (sip.state === 'active') {
|
|
184
|
+
* await audio.say('Call is live');
|
|
185
|
+
* }
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
readonly state: SipState;
|
|
189
|
+
/**
|
|
190
|
+
* Whether the call has been answered — `true` after 200 OK is received (outbound)
|
|
191
|
+
* or sent (inbound via `sip.answer()`).
|
|
192
|
+
*
|
|
193
|
+
* This is a synchronous getter. For an awaitable version use {@link waitForAnswer}.
|
|
194
|
+
*
|
|
195
|
+
* ```ts
|
|
196
|
+
* if (!sip.isAnswered) {
|
|
197
|
+
* console.log('Still waiting for answer…');
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
readonly isAnswered: boolean;
|
|
202
|
+
/**
|
|
203
|
+
* Emits every SIP 1xx provisional response (180 Ringing, 183 Session Progress, etc.).
|
|
204
|
+
*
|
|
205
|
+
* Useful for tracking ringing state, ringback-tone detection, or reading SDP from
|
|
206
|
+
* early 183 responses. Each event is a {@link SipProgressEvent} with `statusCode`,
|
|
207
|
+
* `statusPhrase`, and optionally `sdp`.
|
|
208
|
+
*
|
|
209
|
+
* ```ts
|
|
210
|
+
* sip.progress$.subscribe(({ statusCode, statusPhrase }) => {
|
|
211
|
+
* console.log(`1xx: ${statusCode} ${statusPhrase}`);
|
|
212
|
+
* });
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* > **Note:** `progress$` may emit **zero** events if the remote party answers
|
|
216
|
+
* > immediately (200 OK without any provisional).
|
|
217
|
+
*/
|
|
218
|
+
readonly progress$: Observable<SipProgressEvent>;
|
|
219
|
+
/**
|
|
220
|
+
* Emits **once** when early media becomes available — the RTP pipeline is up and
|
|
221
|
+
* audio can be sent/received **before** the call is formally answered.
|
|
222
|
+
*
|
|
223
|
+
* **Outbound:** fires automatically when the remote side sends a 1xx with SDP
|
|
224
|
+
* (typically **183 Session Progress**).
|
|
225
|
+
*
|
|
226
|
+
* **Inbound:** fires after your script calls `sip.sendProgress()`.
|
|
227
|
+
*
|
|
228
|
+
* After this event fires:
|
|
229
|
+
* - `audio.say()` / `audio.play()` will be heard by the remote party
|
|
230
|
+
* - `createAsr()` will receive remote audio
|
|
231
|
+
* - `dtmf$` will deliver in-band DTMF
|
|
232
|
+
* - The API has not marked the call answered yet; carrier billing policy may vary
|
|
233
|
+
*
|
|
234
|
+
* If the call is answered without any early media (outbound: no 183 with SDP;
|
|
235
|
+
* inbound: `answer()` called directly), `early$` **may not emit at all** —
|
|
236
|
+
* use `answered$` or `waitForAnswer()` instead.
|
|
237
|
+
*
|
|
238
|
+
* ```ts
|
|
239
|
+
* sip.early$.subscribe(() => {
|
|
240
|
+
* console.log('Early media — RTP is flowing before answer');
|
|
241
|
+
* });
|
|
242
|
+
* ```
|
|
243
|
+
*/
|
|
244
|
+
readonly early$: Observable<void>;
|
|
245
|
+
/**
|
|
246
|
+
* Emits **once** when the call is answered (200 OK received for outbound,
|
|
247
|
+
* or sent for inbound after `sip.answer()`).
|
|
248
|
+
*
|
|
249
|
+
* After this event the call state is `"active"` and the call is fully established.
|
|
250
|
+
*
|
|
251
|
+
* ```ts
|
|
252
|
+
* sip.answered$.subscribe(() => {
|
|
253
|
+
* console.log('Call answered — full duplex');
|
|
254
|
+
* });
|
|
255
|
+
* ```
|
|
256
|
+
*
|
|
257
|
+
* > For the awaitable version see {@link waitForAnswer}.
|
|
258
|
+
*/
|
|
259
|
+
readonly answered$: Observable<void>;
|
|
260
|
+
/**
|
|
261
|
+
* Returns a `Promise` that resolves when the call is answered (200 OK).
|
|
262
|
+
*
|
|
263
|
+
* If the call is **already answered** at the time of calling, resolves immediately.
|
|
264
|
+
*
|
|
265
|
+
* Useful in outbound scenarios where you want to block until the remote party picks up:
|
|
266
|
+
*
|
|
267
|
+
* ```ts
|
|
268
|
+
* const call = await channel.sip.makeCall({ sipUri: destination });
|
|
269
|
+
* await call.sip.waitForAnswer();
|
|
270
|
+
* await call.audio.say('You have picked up!');
|
|
271
|
+
* ```
|
|
272
|
+
*
|
|
273
|
+
* > **Warning:** if the call is never answered (busy, timeout, rejection) and your
|
|
274
|
+
* > script does not handle `events.terminated$`, this Promise will remain pending
|
|
275
|
+
* > until the call terminates (at which point the script exits).
|
|
276
|
+
*/
|
|
277
|
+
waitForAnswer(): Promise<void>;
|
|
278
|
+
/**
|
|
279
|
+
* Returns a `Promise` that resolves as soon as the RTP pipeline is ready —
|
|
280
|
+
* either on **early media** or on **answer**, whichever comes first.
|
|
281
|
+
*
|
|
282
|
+
* If the call is already in `"early"` or `"active"` state, resolves immediately.
|
|
283
|
+
*
|
|
284
|
+
* #### Outbound usage
|
|
285
|
+
*
|
|
286
|
+
* The recommended await point when you want to start ASR / play audio
|
|
287
|
+
* **as early as possible** (including pre-answer):
|
|
288
|
+
*
|
|
289
|
+
* ```ts
|
|
290
|
+
* const call = await channel.sip.makeCall({ sipUri: destination });
|
|
291
|
+
*
|
|
292
|
+
* // Don't wait for full answer — start as soon as any media path exists
|
|
293
|
+
* await call.sip.waitForEarly();
|
|
294
|
+
*
|
|
295
|
+
* // ASR is already receiving remote audio (IVR prompts, ringback, etc.)
|
|
296
|
+
* const asr = await call.createAsr();
|
|
297
|
+
* asr.result$.subscribe((text) => console.log('Heard:', text));
|
|
298
|
+
*
|
|
299
|
+
* // Play DTMF to navigate an IVR — works even before 200 OK
|
|
300
|
+
* call.sip.sendDtmf('1');
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* #### Inbound usage
|
|
304
|
+
*
|
|
305
|
+
* For inbound calls you must call `sendProgress()` **first** to trigger early media,
|
|
306
|
+
* then `waitForEarly()` resolves:
|
|
307
|
+
*
|
|
308
|
+
* ```ts
|
|
309
|
+
* channel.sip.sendProgress();
|
|
310
|
+
* await channel.sip.waitForEarly(); // resolves immediately after sendProgress()
|
|
311
|
+
* const asr = await channel.createAsr();
|
|
312
|
+
* ```
|
|
313
|
+
*
|
|
314
|
+
* > **Tip:** some carriers answer outbound calls without early media (180 without SDP).
|
|
315
|
+
* > In that case `waitForEarly()` resolves only when the 200 OK arrives.
|
|
316
|
+
*/
|
|
317
|
+
waitForEarly(): Promise<void>;
|
|
318
|
+
/**
|
|
319
|
+
* Send a DTMF digit to the remote party.
|
|
320
|
+
*
|
|
321
|
+
* SIP channels delegate to the telephony stack. WS channels validate one digit
|
|
322
|
+
* and emit `dtmf-send` to the connected client. Headless channels ignore it.
|
|
323
|
+
*
|
|
324
|
+
* @param digit - One of `0`–`9`, `*`, `#`.
|
|
325
|
+
* @param duration - Tone duration in milliseconds (default **250 ms**).
|
|
326
|
+
*
|
|
327
|
+
* ```ts
|
|
328
|
+
* // Navigate an IVR: press 1, wait, press 3
|
|
329
|
+
* sip.sendDtmf('1');
|
|
330
|
+
* await new Promise((r) => setTimeout(r, 2000));
|
|
331
|
+
* sip.sendDtmf('3');
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
sendDtmf(digit: string, duration?: number): void;
|
|
335
|
+
/**
|
|
336
|
+
* Send a SIP INFO request with an arbitrary content type and body on this call leg.
|
|
337
|
+
*
|
|
338
|
+
* No-op on WS and headless channels.
|
|
339
|
+
*
|
|
340
|
+
* @param contentType - MIME type, e.g. `"application/dtmf-relay"`.
|
|
341
|
+
* @param body - Raw text body of the INFO request.
|
|
342
|
+
*/
|
|
343
|
+
sendInfo(contentType: string, body: string): void;
|
|
344
|
+
/**
|
|
345
|
+
* Put the SIP call on hold (sends re-INVITE with `a=sendonly`).
|
|
346
|
+
*
|
|
347
|
+
* The remote party hears silence (or hold music if your carrier supports it).
|
|
348
|
+
* Call {@link unhold} to resume.
|
|
349
|
+
*/
|
|
350
|
+
hold(): void;
|
|
351
|
+
/**
|
|
352
|
+
* Resume a held SIP call (sends re-INVITE with `a=sendrecv`).
|
|
353
|
+
*/
|
|
354
|
+
unhold(): void;
|
|
355
|
+
/**
|
|
356
|
+
* Suppress outgoing SIP audio locally — the remote party hears silence,
|
|
357
|
+
* but you still receive their audio.
|
|
358
|
+
*
|
|
359
|
+
* This does **not** send a re-INVITE; it simply stops feeding PCM
|
|
360
|
+
* to the RTP encoder. Call {@link unmute} to resume.
|
|
361
|
+
*/
|
|
362
|
+
mute(): void;
|
|
363
|
+
/** Resume sending audio after {@link mute}. No-op on WS/headless channels. */
|
|
364
|
+
unmute(): void;
|
|
365
|
+
/**
|
|
366
|
+
* Hang up the call.
|
|
367
|
+
*
|
|
368
|
+
* SIP channels send BYE. WS channels disconnect the socket. Headless channels destroy
|
|
369
|
+
* the synthetic channel. After this call `events.terminated$` will emit and the session ends.
|
|
370
|
+
*/
|
|
371
|
+
hangup(): void;
|
|
372
|
+
/**
|
|
373
|
+
* Answer an **inbound** call (sends 200 OK with SDP).
|
|
374
|
+
*
|
|
375
|
+
* No-op if the call is already answered or if this is an outbound call. Also no-op
|
|
376
|
+
* on WS/headless channels. After answering, the state transitions to `"active"` and
|
|
377
|
+
* the API records the call answer time.
|
|
378
|
+
*
|
|
379
|
+
* If the call is in `"early"` state (after `sendProgress()`), `answer()` promotes it
|
|
380
|
+
* to `"active"` — audio was already flowing and the final answer is now sent.
|
|
381
|
+
*
|
|
382
|
+
* ```ts
|
|
383
|
+
* // Simple: answer immediately
|
|
384
|
+
* channel.sip.answer();
|
|
385
|
+
* await channel.audio.say('Hello, how can I help?');
|
|
386
|
+
* ```
|
|
387
|
+
*
|
|
388
|
+
* ```ts
|
|
389
|
+
* // Advanced: pre-answer → answer
|
|
390
|
+
* channel.sip.sendProgress(); // early media before final 200 OK
|
|
391
|
+
* await channel.audio.say('One moment…');
|
|
392
|
+
* channel.sip.answer(); // final 200 OK
|
|
393
|
+
* await channel.audio.say('How can I help?');
|
|
394
|
+
* ```
|
|
395
|
+
*/
|
|
396
|
+
answer(): void;
|
|
397
|
+
/**
|
|
398
|
+
* Send **183 Session Progress** with SDP on an **inbound** call, enabling
|
|
399
|
+
* early media (full-duplex audio) **before** the 200 OK answer.
|
|
400
|
+
*
|
|
401
|
+
* After calling `sendProgress()`:
|
|
402
|
+
* - The call state transitions to `"early"` and `early$` emits.
|
|
403
|
+
* - `audio.say()`, `audio.play()`, `createAsr()`, `dtmf$` all work —
|
|
404
|
+
* exactly the same as in the `"active"` state.
|
|
405
|
+
* - The remote party hears your audio before the final 200 OK. The API still treats
|
|
406
|
+
* the call as not answered; external billing depends on carrier policy.
|
|
407
|
+
*
|
|
408
|
+
* Call `sip.answer()` later to send the final 200 OK and transition to `"active"`.
|
|
409
|
+
*
|
|
410
|
+
* No-op if the call is already in `"early"` or `"active"` state, or if this is
|
|
411
|
+
* an outbound / WS / headless channel.
|
|
412
|
+
*
|
|
413
|
+
* ### Typical use case: play a greeting before answering
|
|
414
|
+
*
|
|
415
|
+
* ```ts
|
|
416
|
+
* // Inbound call arrives — state is 'ringing'
|
|
417
|
+
* channel.sip.sendProgress();
|
|
418
|
+
* // State is now 'early' — audio flows before final 200 OK
|
|
419
|
+
*
|
|
420
|
+
* await channel.audio.say('Please hold while we connect you…');
|
|
421
|
+
*
|
|
422
|
+
* // Now answer with final 200 OK
|
|
423
|
+
* channel.sip.answer();
|
|
424
|
+
* await channel.audio.say('Hello! How can I help?');
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* ### Typical use case: start ASR before answering
|
|
428
|
+
*
|
|
429
|
+
* ```ts
|
|
430
|
+
* channel.sip.sendProgress();
|
|
431
|
+
* const asr = await channel.createAsr();
|
|
432
|
+
* await channel.audio.say('Hi! What is your account number?');
|
|
433
|
+
* const result = await firstValueFrom(asr.result$);
|
|
434
|
+
* // Collected account number before sending final 200 OK
|
|
435
|
+
* channel.sip.answer();
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
sendProgress(): void;
|
|
439
|
+
/**
|
|
440
|
+
* Initiate an **outbound** SIP call to the given SIP URI.
|
|
441
|
+
*
|
|
442
|
+
* Returns a new {@link MediaChannel} representing the B-leg. The returned channel
|
|
443
|
+
* has its own `sip`, `audio`, `events`, etc. — use `waitForAnswer()` or
|
|
444
|
+
* `waitForEarly()` on the B-leg before sending audio.
|
|
445
|
+
*
|
|
446
|
+
* Supported only by the main-thread SIP channel. Worker-isolated, WS, and headless
|
|
447
|
+
* channels throw because the current worker bridge does not proxy nested call legs.
|
|
448
|
+
*
|
|
449
|
+
* @param opts.sipUri - Full SIP URI, e.g. `"sip:+12025551234@trunk.carrier.com"`.
|
|
450
|
+
* @param opts.fromUri - Optional caller-ID override SIP URI.
|
|
451
|
+
* @returns A new `MediaChannel` for the outbound leg.
|
|
452
|
+
*
|
|
453
|
+
* ```ts
|
|
454
|
+
* const bLeg = await channel.sip.makeCall({
|
|
455
|
+
* sipUri: 'sip:+12025551234@trunk.carrier.com',
|
|
456
|
+
* });
|
|
457
|
+
* await bLeg.sip.waitForAnswer();
|
|
458
|
+
* // Bridge both legs so callers hear each other
|
|
459
|
+
* const teardown = channel.sip.bridge(bLeg);
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
makeCall(opts: {
|
|
463
|
+
sipUri: string;
|
|
464
|
+
fromUri?: string;
|
|
465
|
+
}): Promise<MediaChannel>;
|
|
466
|
+
/**
|
|
467
|
+
* Cross-connect audio between this SIP call and another SIP call (conference bridge).
|
|
468
|
+
*
|
|
469
|
+
* Both parties hear each other in real time. Returns a teardown function
|
|
470
|
+
* that disconnects the bridge when called. ScriptEngine only bridges two
|
|
471
|
+
* `SipMediaChannel` instances directly; non-SIP channels return a no-op teardown
|
|
472
|
+
* or throw depending on the host.
|
|
473
|
+
*
|
|
474
|
+
* @param other - The other `MediaChannel` (e.g. an outbound B-leg).
|
|
475
|
+
* @returns A function to tear down the bridge.
|
|
476
|
+
*
|
|
477
|
+
* ```ts
|
|
478
|
+
* const teardown = channel.sip.bridge(bLeg);
|
|
479
|
+
* // ... later
|
|
480
|
+
* teardown(); // disconnect the bridge
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
bridge(other: MediaChannel): () => void;
|
|
484
|
+
}
|
|
485
|
+
//# sourceMappingURL=sip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sip.d.ts","sourceRoot":"","sources":["../../src/types/sip.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,MAAM,QAAQ,GAChB,MAAM,GACN,SAAS,GACT,OAAO,GACP,QAAQ,GACR,SAAS,GACT,YAAY,CAAC;AAEjB;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,gBAAgB;IAC/B,iCAAiC;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,4EAA4E;IAC5E,YAAY,EAAE,MAAM,CAAC;IACrB,8EAA8E;IAC9E,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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