@ipcom/asterisk-ari 0.0.154 → 0.0.155
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 +117 -32
- package/dist/cjs/index.cjs +665 -67
- package/dist/cjs/index.cjs.map +4 -4
- package/dist/esm/index.js +664 -67
- package/dist/esm/index.js.map +4 -4
- package/dist/types/ari-client/ariClient.d.ts +13 -1
- package/dist/types/ari-client/ariClient.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/events.types.d.ts +5 -0
- package/dist/types/ari-client/interfaces/events.types.d.ts.map +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts +1 -1
- package/dist/types/ari-client/interfaces/index.d.ts.map +1 -1
- package/dist/types/ari-client/resources/bridges.d.ts +365 -14
- package/dist/types/ari-client/resources/bridges.d.ts.map +1 -1
- package/dist/types/ari-client/websocketClient.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,11 +26,11 @@ npm install @ipcom/asterisk-ari
|
|
|
26
26
|
import { AriClient } from '@ipcom/asterisk-ari';
|
|
27
27
|
|
|
28
28
|
const client = new AriClient({
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
29
|
+
host: 'localhost', // Asterisk host
|
|
30
|
+
port: 8088, // ARI port
|
|
31
|
+
username: 'username', // ARI username
|
|
32
|
+
password: 'password', // ARI password
|
|
33
|
+
secure: false // Use true for HTTPS/WSS
|
|
34
34
|
});
|
|
35
35
|
```
|
|
36
36
|
|
|
@@ -42,16 +42,16 @@ await client.connectWebSocket(['myApp']); // 'myApp' is your application name
|
|
|
42
42
|
|
|
43
43
|
// Listen for specific events
|
|
44
44
|
client.on('StasisStart', event => {
|
|
45
|
-
|
|
45
|
+
console.log('New channel started:', event.channel.id);
|
|
46
46
|
});
|
|
47
47
|
|
|
48
48
|
client.on('StasisEnd', event => {
|
|
49
|
-
|
|
49
|
+
console.log('Channel ended:', event.channel.id);
|
|
50
50
|
});
|
|
51
51
|
|
|
52
52
|
// Listen for DTMF events
|
|
53
53
|
client.on('ChannelDtmfReceived', event => {
|
|
54
|
-
|
|
54
|
+
console.log('DTMF received:', event.digit);
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// Close WebSocket connection
|
|
@@ -60,21 +60,32 @@ client.closeWebSocket();
|
|
|
60
60
|
|
|
61
61
|
## Event Instances
|
|
62
62
|
|
|
63
|
-
### Channel and Playback Instances in Events
|
|
63
|
+
### Channel, Bridge and Playback Instances in Events
|
|
64
64
|
|
|
65
65
|
When working with WebSocket events, you get access to both the raw event data and convenient instance objects that allow direct interaction with the channel or playback:
|
|
66
66
|
|
|
67
67
|
```typescript
|
|
68
68
|
client.on('StasisStart', async event => {
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// event.channel contains the raw channel data
|
|
70
|
+
console.log('New channel started:', event.channel.id);
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
// event.instanceChannel provides a ready-to-use ChannelInstance
|
|
73
|
+
const channelInstance = event.instanceChannel;
|
|
74
|
+
|
|
75
|
+
// You can directly interact with the channel through the instance
|
|
76
|
+
await channelInstance.answer();
|
|
77
|
+
await channelInstance.play({ media: 'sound:welcome' });
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
client.on('BridgeCreated', async event => {
|
|
81
|
+
// event.bridge contains the raw bridge data
|
|
82
|
+
console.log('Bridge created:', event.bridge.id);
|
|
83
|
+
|
|
84
|
+
// event.instanceBridge provides a ready-to-use BridgeInstance
|
|
85
|
+
const bridgeInstance = event.instanceBridge;
|
|
86
|
+
|
|
87
|
+
// Direct control through the instance
|
|
88
|
+
await bridgeInstance.add({ channel: ['channel-id-1', 'channel-id-2'] });
|
|
78
89
|
});
|
|
79
90
|
|
|
80
91
|
// Similarly for playback events
|
|
@@ -163,6 +174,41 @@ await playback.control('restart'); // Restart
|
|
|
163
174
|
await playback.stop(); // Stop
|
|
164
175
|
```
|
|
165
176
|
|
|
177
|
+
### Bridge Handling
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// Create a bridge instance
|
|
181
|
+
const bridge = client.Bridge();
|
|
182
|
+
|
|
183
|
+
// Create a new bridge with specific settings
|
|
184
|
+
await bridge.getDetails();
|
|
185
|
+
|
|
186
|
+
// Add channels to the bridge
|
|
187
|
+
await bridge.add({
|
|
188
|
+
channel: ['channel-id-1', 'channel-id-2']
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
// Remove channels from the bridge
|
|
192
|
+
await bridge.remove({
|
|
193
|
+
channel: ['channel-id-1']
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Play audio on the bridge
|
|
197
|
+
const playback = await bridge.playMedia({
|
|
198
|
+
media: 'sound:announcement',
|
|
199
|
+
lang: 'en'
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Stop playback on the bridge
|
|
203
|
+
await bridge.stopPlayback(playback.id);
|
|
204
|
+
|
|
205
|
+
// Set video source
|
|
206
|
+
await bridge.setVideoSource('video-channel-id');
|
|
207
|
+
|
|
208
|
+
// Clear video source
|
|
209
|
+
await bridge.clearVideoSource();
|
|
210
|
+
```
|
|
211
|
+
|
|
166
212
|
### Specific Channel Monitoring
|
|
167
213
|
|
|
168
214
|
```typescript
|
|
@@ -208,6 +254,39 @@ await channel.pausePlayback(playback.id);
|
|
|
208
254
|
await channel.resumePlayback(playback.id);
|
|
209
255
|
```
|
|
210
256
|
|
|
257
|
+
### Bridge Event Monitoring
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// Create an instance for a specific bridge
|
|
261
|
+
const bridge = client.Bridge('bridge-id');
|
|
262
|
+
|
|
263
|
+
// Monitor bridge events
|
|
264
|
+
bridge.on('BridgeCreated', event => {
|
|
265
|
+
console.log('Bridge created:', event.bridge.id);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
bridge.on('BridgeDestroyed', event => {
|
|
269
|
+
console.log('Bridge destroyed:', event.bridge.id);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
bridge.on('BridgeMerged', event => {
|
|
273
|
+
console.log('Bridge merged:', event.bridge.id);
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
// Get bridge details
|
|
277
|
+
const details = await bridge.get();
|
|
278
|
+
console.log('Bridge details:', details);
|
|
279
|
+
|
|
280
|
+
// Monitor channel events in bridge
|
|
281
|
+
bridge.on('ChannelEnteredBridge', event => {
|
|
282
|
+
console.log('Channel entered bridge:', event.channel.id);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
bridge.on('ChannelLeftBridge', event => {
|
|
286
|
+
console.log('Channel left bridge:', event.channel.id);
|
|
287
|
+
});
|
|
288
|
+
```
|
|
289
|
+
|
|
211
290
|
## Error Handling
|
|
212
291
|
|
|
213
292
|
```typescript
|
|
@@ -233,23 +312,29 @@ try {
|
|
|
233
312
|
The library provides complete type definitions for all operations:
|
|
234
313
|
|
|
235
314
|
```typescript
|
|
236
|
-
import type {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
315
|
+
import type {
|
|
316
|
+
Channel,
|
|
317
|
+
Bridge,
|
|
318
|
+
ChannelEvent,
|
|
319
|
+
BridgeEvent,
|
|
320
|
+
WebSocketEvent
|
|
240
321
|
} from '@ipcom/asterisk-ari';
|
|
241
322
|
|
|
242
323
|
// Types will be available for use
|
|
243
324
|
const handleChannelEvent = (event: ChannelEvent) => {
|
|
244
325
|
const channelId: string = event.channel.id;
|
|
245
326
|
};
|
|
327
|
+
|
|
328
|
+
// Types will be available for use
|
|
329
|
+
const handleBridgeEvent = (event: BridgeEvent) => {
|
|
330
|
+
const bridgeId: string = event.bridge.id;
|
|
331
|
+
};
|
|
246
332
|
```
|
|
247
333
|
|
|
248
334
|
## Additional Features
|
|
249
335
|
|
|
250
336
|
The library provides access to many other ARI features:
|
|
251
337
|
|
|
252
|
-
- Bridge management
|
|
253
338
|
- Endpoint handling
|
|
254
339
|
- Sound manipulation
|
|
255
340
|
- Application control
|
|
@@ -263,13 +348,13 @@ The library provides access to many other ARI features:
|
|
|
263
348
|
```typescript
|
|
264
349
|
// Create and manage a bridge
|
|
265
350
|
const bridge = await client.bridges.createBridge({
|
|
266
|
-
|
|
267
|
-
|
|
351
|
+
type: 'mixing',
|
|
352
|
+
name: 'myBridge'
|
|
268
353
|
});
|
|
269
354
|
|
|
270
355
|
// Add channels to bridge
|
|
271
356
|
await client.bridges.addChannels(bridge.id, {
|
|
272
|
-
|
|
357
|
+
channel: ['channel-id-1', 'channel-id-2']
|
|
273
358
|
});
|
|
274
359
|
```
|
|
275
360
|
|
|
@@ -279,10 +364,10 @@ await client.bridges.addChannels(bridge.id, {
|
|
|
279
364
|
// Start recording on a channel
|
|
280
365
|
const channel = client.Channel('channel-id');
|
|
281
366
|
await channel.record({
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
367
|
+
name: 'recording-name',
|
|
368
|
+
format: 'wav',
|
|
369
|
+
maxDurationSeconds: 60,
|
|
370
|
+
beep: true
|
|
286
371
|
});
|
|
287
372
|
```
|
|
288
373
|
|
|
@@ -291,9 +376,9 @@ await channel.record({
|
|
|
291
376
|
```typescript
|
|
292
377
|
// Create external media channel
|
|
293
378
|
const channel = await client.channels.createExternalMedia({
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
379
|
+
app: 'myApp',
|
|
380
|
+
external_host: 'media-server:8088',
|
|
381
|
+
format: 'slin16'
|
|
297
382
|
});
|
|
298
383
|
```
|
|
299
384
|
|