opensips-js 0.1.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/README.md +317 -0
- package/dist/index.d.ts +1044 -0
- package/dist/opensips-js.cjs.js +159 -0
- package/dist/opensips-js.es.js +25890 -0
- package/dist/opensips-js.iife.js +159 -0
- package/dist/opensips-js.umd.js +159 -0
- package/package.json +77 -0
- package/src/types/Dialog.d.ts +7 -0
- package/src/types/Socket.d.ts +8 -0
- package/src/types/Transactions.d.ts +9 -0
- package/src/types/UAExtended.d.ts +82 -0
- package/src/types/declarations.d.ts +6 -0
- package/src/types/generic.d.ts +1 -0
- package/src/types/listeners.d.ts +104 -0
- package/src/types/msrp.d.ts +55 -0
- package/src/types/rtc.d.ts +179 -0
- package/src/types/timer.d.ts +13 -0
- package/src/types/webrtcmetrics.d.ts +64 -0
package/README.md
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Getting started
|
|
3
|
+
description: The Opensips JS library and its expansive ecosystem offer developers a powerful and flexible solution for integrating Opensips protocol functionalities into a multitude of applications.
|
|
4
|
+
navigation:
|
|
5
|
+
title: Getting Started
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# Getting started
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
### Using npm:
|
|
12
|
+
```shell[Terminal]
|
|
13
|
+
$ npm i @voicenter-team/opensips-js
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### Using via CDN:
|
|
17
|
+
You can include the OpensipsJS library directly in your HTML file using a CDN like UNPKG or jsDelivr. This is especially useful for quick prototyping or when you don't want to set up a build environment.
|
|
18
|
+
|
|
19
|
+
Add the following script tag to your HTML file:
|
|
20
|
+
```html [index.html]
|
|
21
|
+
<script src="https://cdn.opensipsjs.org/opensipsjs/v1.0.96/opensips-js.iife.js"></script>
|
|
22
|
+
```
|
|
23
|
+
This will load the library and attach the OpensipsJS class to the global window object as OpensipsJS.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
### Using npm (ES Modules):
|
|
27
|
+
Firstly lets import the library and create the OpenSIPS instance:
|
|
28
|
+
```javascript [file.js]
|
|
29
|
+
import OpenSIPSJS from '@voicenter-team/opensips-js'
|
|
30
|
+
|
|
31
|
+
const openSIPSJS = new OpenSIPSJS({
|
|
32
|
+
configuration: {
|
|
33
|
+
session_timers: false,
|
|
34
|
+
uri: 'sip:extension_user@domain',
|
|
35
|
+
// --- Use password or authorization_jwt to authorize
|
|
36
|
+
password: 'password',
|
|
37
|
+
// or
|
|
38
|
+
authorization_jwt: 'token',
|
|
39
|
+
},
|
|
40
|
+
socketInterfaces: [ 'wss://domain' ],
|
|
41
|
+
pnExtraHeaders: {
|
|
42
|
+
'pn-provider': 'acme',
|
|
43
|
+
'pn-param': 'acme-param',
|
|
44
|
+
'pn-prid': 'ZH11Y4ZDJlMNzODE1NgKi0K>'
|
|
45
|
+
},
|
|
46
|
+
sipDomain: 'domain',
|
|
47
|
+
sipOptions: {
|
|
48
|
+
session_timers: false,
|
|
49
|
+
extraHeaders: [ 'X-Bar: bar' ],
|
|
50
|
+
pcConfig: {},
|
|
51
|
+
},
|
|
52
|
+
modules: [ 'audio', 'video', 'msrp' ]
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
// Then you can work with the appropriate modules
|
|
56
|
+
opensipsJS.audio
|
|
57
|
+
opensipsJS.video
|
|
58
|
+
opensipsJS.msrp
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Using via CDN:
|
|
62
|
+
After including the script via CDN, you can access the OpensipsJS class directly from the global scope.
|
|
63
|
+
```html [index.html]
|
|
64
|
+
<!DOCTYPE html>
|
|
65
|
+
<html>
|
|
66
|
+
<head>
|
|
67
|
+
<title>OpensipsJS CDN Usage</title>
|
|
68
|
+
</head>
|
|
69
|
+
<body>
|
|
70
|
+
<!-- Include the library via CDN -->
|
|
71
|
+
<script src="https://cdn.opensipsjs.org/opensipsjs/v1.0.96/opensips-js.iife.js"></script>
|
|
72
|
+
|
|
73
|
+
<script>
|
|
74
|
+
// Create an instance of OpensipsJS
|
|
75
|
+
const opensipsJS = new OpensipsJS({
|
|
76
|
+
configuration: {
|
|
77
|
+
session_timers: false,
|
|
78
|
+
uri: 'sip:extension_user@domain',
|
|
79
|
+
// --- Use password or authorization_jwt to authorize
|
|
80
|
+
password: 'password',
|
|
81
|
+
// or
|
|
82
|
+
authorization_jwt: 'token',
|
|
83
|
+
},
|
|
84
|
+
socketInterfaces: ['wss://domain'],
|
|
85
|
+
pnExtraHeaders: {
|
|
86
|
+
'pn-provider': 'acme',
|
|
87
|
+
'pn-param': 'acme-param',
|
|
88
|
+
'pn-prid': 'ZH11Y4ZDJlMNzODE1NgKi0K>',
|
|
89
|
+
},
|
|
90
|
+
sipDomain: 'domain',
|
|
91
|
+
sipOptions: {
|
|
92
|
+
session_timers: false,
|
|
93
|
+
extraHeaders: ['X-Bar: bar'],
|
|
94
|
+
pcConfig: {},
|
|
95
|
+
},
|
|
96
|
+
modules: ['audio', 'video', 'msrp'],
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Now you can use the modules
|
|
100
|
+
opensipsJS.audio;
|
|
101
|
+
opensipsJS.video;
|
|
102
|
+
opensipsJS.msrp;
|
|
103
|
+
</script>
|
|
104
|
+
</body>
|
|
105
|
+
</html>
|
|
106
|
+
```
|
|
107
|
+
Note: When using the library via CDN, ensure that you replace 'sip:extension_user@domain', 'password', 'token', and other placeholders with your actual configuration values.
|
|
108
|
+
|
|
109
|
+
### Using ES Modules via CDN:
|
|
110
|
+
If you prefer using ES modules in the browser and your environment supports them, you can import the ES module build directly from the CDN.
|
|
111
|
+
```html [index.html]
|
|
112
|
+
<!DOCTYPE html>
|
|
113
|
+
<html>
|
|
114
|
+
<head>
|
|
115
|
+
<title>OpensipsJS ES Module CDN Usage</title>
|
|
116
|
+
</head>
|
|
117
|
+
<body>
|
|
118
|
+
<script type="module">
|
|
119
|
+
import OpensipsJS from 'https://cdn.opensipsjs.org/opensipsjs/v1.0.96/opensips-js.es.js';
|
|
120
|
+
// Or using jsDelivr
|
|
121
|
+
// import OpensipsJS from 'https://cdn.jsdelivr.net/npm/@voicenter-team/opensips-js/dist/opensips-js.es.js';
|
|
122
|
+
|
|
123
|
+
const opensipsJS = new OpensipsJS({
|
|
124
|
+
configuration: {
|
|
125
|
+
session_timers: false,
|
|
126
|
+
uri: 'sip:extension_user@domain',
|
|
127
|
+
// --- Use password or authorization_jwt to authorize
|
|
128
|
+
password: 'password',
|
|
129
|
+
// or
|
|
130
|
+
authorization_jwt: 'token',
|
|
131
|
+
},
|
|
132
|
+
socketInterfaces: ['wss://domain'],
|
|
133
|
+
pnExtraHeaders: {
|
|
134
|
+
'pn-provider': 'acme',
|
|
135
|
+
'pn-param': 'acme-param',
|
|
136
|
+
'pn-prid': 'ZH11Y4ZDJlMNzODE1NgKi0K>',
|
|
137
|
+
},
|
|
138
|
+
sipDomain: 'domain',
|
|
139
|
+
sipOptions: {
|
|
140
|
+
session_timers: false,
|
|
141
|
+
extraHeaders: ['X-Bar: bar'],
|
|
142
|
+
pcConfig: {},
|
|
143
|
+
},
|
|
144
|
+
modules: ['audio', 'video', 'msrp'],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// Use the modules as before
|
|
148
|
+
opensipsJS.audio;
|
|
149
|
+
opensipsJS.video;
|
|
150
|
+
opensipsJS.msrp;
|
|
151
|
+
</script>
|
|
152
|
+
</body>
|
|
153
|
+
</html>
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
**Important**: When using ES modules via CDN:
|
|
157
|
+
* Ensure your browser supports ES modules.
|
|
158
|
+
* The `type="module"` attribute is necessary in the `<script>` tag.
|
|
159
|
+
|
|
160
|
+
## OpensipsJS
|
|
161
|
+
### OpensipsJS instance methods
|
|
162
|
+
- `begin(): OpensipsInstance` - start opensips
|
|
163
|
+
- `on(event: OpensipsEvent, callback): void` - remove event listener
|
|
164
|
+
- `subscribe({type: String, listener: function}): void` - subscribe to an event. Available events: `new_call`, `ended`, `progress`, `failed`, `confirmed`
|
|
165
|
+
- `removeIListener(type: String): void` - remove event listener
|
|
166
|
+
|
|
167
|
+
### OpensipsJS events
|
|
168
|
+
|
|
169
|
+
| Event | Callback interface | Description |
|
|
170
|
+
|---------------------------------|----------------------------------------------------------|-------------------------------------------------------|
|
|
171
|
+
| `ready` | `() => {}` | Emitted when opensips is initialized |
|
|
172
|
+
| `changeActiveCalls` | `(calls: { [key: string]: ICall }) => {}` | Emitted when active calls are changed |
|
|
173
|
+
| `callAddingInProgressChanged` | `(callId: string / undefined) => {}` | Emitted when any call adding state is changed |
|
|
174
|
+
| `changeAvailableDeviceList` | `(devices: Array<MediaDeviceInfo>) => {}` | Emitted when the list of available devices is changed |
|
|
175
|
+
| `changeActiveInputMediaDevice` | `(deviceId: string) => {}` | Emitted when active input device is changed |
|
|
176
|
+
| `changeActiveOutputMediaDevice` | `(deviceId: string) => {}` | Emitted when active output device is changed |
|
|
177
|
+
| `changeMuteWhenJoin` | `(value: boolean) => {}` | Emitted when mute on join value is changed |
|
|
178
|
+
| `changeIsDND` | `(value: boolean) => {}` | Emitted when is DND value is changed |
|
|
179
|
+
| `changeIsMuted` | `(value: boolean) => {}` | Emitted when mute value is changed |
|
|
180
|
+
| `changeActiveStream` | `(stream: MediaStream) => {}` | Emitted when active stream was changed |
|
|
181
|
+
| `changeCallVolume` | `(callId: string, volume: number) => {}` | Emits the volume meter's value for each participant |
|
|
182
|
+
| `currentActiveRoomChanged` | `(number / undefined) => {}` | Emitted when active room is changed |
|
|
183
|
+
| `addRoom` | `({room: IRoom, roomList: {[id: number]: IRoom}}) => {}` | Emitted when new room was added |
|
|
184
|
+
| `updateRoom` | `({room: IRoom, roomList: {[id: number]: IRoom}}) => {}` | Emitted when room was updated |
|
|
185
|
+
| `removeRoom` | `({room: IRoom, roomList: {[p: number]: IRoom}}) => {}` | Emitted when room was deleted |
|
|
186
|
+
|
|
187
|
+
WebrtcMetricsConfigType
|
|
188
|
+
|
|
189
|
+
| Parameter | Type | Default |
|
|
190
|
+
|----------------|-----------|-------------|
|
|
191
|
+
| `refreshEvery` | `number` | `undefined` |
|
|
192
|
+
| `startAfter` | `number` | `undefined` |
|
|
193
|
+
| `startAfter` | `number` | `undefined` |
|
|
194
|
+
| `verbose` | `boolean` | `undefined` |
|
|
195
|
+
| `pname` | `string` | `undefined` |
|
|
196
|
+
| `cid` | `string` | `undefined` |
|
|
197
|
+
| `uid` | `string` | `undefined` |
|
|
198
|
+
| `record` | `boolean` | `undefined` |
|
|
199
|
+
| `ticket` | `boolean` | `undefined` |
|
|
200
|
+
|
|
201
|
+
Also, there are next public fields on OpensipsJS instance:
|
|
202
|
+
### OpensipsJS instance fields
|
|
203
|
+
- `sipDomain: String` - returns sip domain
|
|
204
|
+
|
|
205
|
+
## Audio
|
|
206
|
+
|
|
207
|
+
### Audio methods
|
|
208
|
+
- `initCall(target: String, addToCurrentRoom: Boolean, holdOtherCalls: Boolean): void` - call to the target. If addToCurrentRoom is true then the call will be added to the user's current room
|
|
209
|
+
- `holdCall(callId: String, automatic?: Boolean): Promise<void>` - put call on hold
|
|
210
|
+
- `unholdCall(callId: String): Promise<void>` - unhold a call
|
|
211
|
+
- `terminateCall(callId: String): void` - terminate call
|
|
212
|
+
- `moveCall(callId: String, roomId: Number): Promise<void>` - Same as callChangeRoom. Move call to the specific room
|
|
213
|
+
- `transferCall(callId: String, target: String): void` - transfer call to target
|
|
214
|
+
- `mergeCall(roomId: Number): void` - merge calls in specific room. Works only for rooms with 2 calls inside
|
|
215
|
+
- `mergeCallByIds(firstCallId: string, secondCallId: string): void` - merge 2 calls by their ids
|
|
216
|
+
- `answerCall(callId: String): void` - answer a call
|
|
217
|
+
- `mute(): void` - mute ourself
|
|
218
|
+
- `unmute(): void` - unmute ourself
|
|
219
|
+
- `muteCaller(callId: String): void` - mute caller
|
|
220
|
+
- `unmuteCaller(callId: String): void` - unmute caller
|
|
221
|
+
- `setMicrophone(deviceId: String): Promise<void>` - set passed device as input device for calls
|
|
222
|
+
- `setSpeaker(deviceId: String): Promise<void>` - set passed device as output device for calls
|
|
223
|
+
- `setActiveRoom(roomId: Number): Promise<void>` - switch to the room
|
|
224
|
+
- `setMicrophoneSensitivity(value: Number): void` - set sensitivity of microphone. Value should be in range from 0 to 1
|
|
225
|
+
- `setSpeakerVolume(value: Number): void` - set volume of callers. Value should be in range from 0 to 1
|
|
226
|
+
- `setDND(value: Boolean): void` - set the agent "Do not disturb" status
|
|
227
|
+
- `setMetricsConfig(config: WebrtcMetricsConfigType): void` - set the metric config (used for audio quality indicator)
|
|
228
|
+
|
|
229
|
+
### Audio instance fields
|
|
230
|
+
- `sipOptions: Object` - returns sip options
|
|
231
|
+
- `getActiveRooms: { [key: number]: IRoom }` - returns an object of active rooms where key is room id and value is room data
|
|
232
|
+
- `sipDomain: String` - returns sip domain
|
|
233
|
+
- `sipOptions: Object` - returns sip options
|
|
234
|
+
- `getInputDeviceList: []` - returns list of input devices
|
|
235
|
+
- `getOutputDeviceList: []` - returns list of output devices
|
|
236
|
+
- `currentActiveRoomId: Number` - returns current active room id
|
|
237
|
+
- `selectedInputDevice: String` - returns current selected input device id
|
|
238
|
+
- `selectedOutputDevice: String` - returns current selected output device id
|
|
239
|
+
- `isDND: Boolean` - returns if the agent is in "Do not disturb" status
|
|
240
|
+
- `isMuted: Boolean` - returns if the agent is muted
|
|
241
|
+
|
|
242
|
+
## MSRP
|
|
243
|
+
|
|
244
|
+
### MSRP methods
|
|
245
|
+
- `initMSRP(target: String, body: String): void` - initialize connection with target contact. Body is the initial message to this target.
|
|
246
|
+
- `sendMSRP(sessionId: String, body: String): Promise<void>` - send message
|
|
247
|
+
- `msrpAnswer(sessionId: String)` - accept MSRP session invitation
|
|
248
|
+
- `messageTerminate(sessionId: String)` - terminate message session
|
|
249
|
+
|
|
250
|
+
### MSRP instance fields
|
|
251
|
+
- `getActiveMessages: { [key: string]: IMessage }` - returns an object of active message sessions where key is session id and value is message session data.
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
## Video
|
|
255
|
+
|
|
256
|
+
### Video methods
|
|
257
|
+
- `joinRoom(roomId: String, displayName: String, mediaConstraints: Object): void` - join conference room
|
|
258
|
+
- `hangup()` - exit room
|
|
259
|
+
- `startVideo()` - turn on camera
|
|
260
|
+
- `stopVideo()` - turn off camera
|
|
261
|
+
- `startAudio()` - mute
|
|
262
|
+
- `stopAudio()` - unmute
|
|
263
|
+
- `startScreenShare()` - start screen sharing
|
|
264
|
+
- `stopScreenShare()` - stop screen sharing
|
|
265
|
+
- `enableScreenShareWhiteboard(enable: boolean, stream: MediaStream)` - enable screen share whiteboard. stream parameter is screen share stream
|
|
266
|
+
- `enableBokehEffectMask(): Promise<MediaStream>` - enable bokeh mask effect
|
|
267
|
+
- `enableBackgroundImgEffectMask(): Promise<MediaStream>` - enable background image mask effect
|
|
268
|
+
- `disableMask(): Promise<MediaStream>` - turn off mask effect. Returns stream without masking
|
|
269
|
+
- `restartMasking(): Promise<void>` - rerun mask effect
|
|
270
|
+
- `setupMaskVisualizationConfig(config: VisualizationConfigType)` - setup mask config
|
|
271
|
+
- `startNoiseFilter()` - start noise filter
|
|
272
|
+
- `stopNoiseFilter()` - stop noise filter
|
|
273
|
+
- `setBitrate(bitrate: number)` - set bitrate for video
|
|
274
|
+
- `enableWhiteboard(mode: 'whiteboard' | 'imageWhiteboard', enable: boolean, base64Image?: string)` - enable whiteboard. if mode is 'imageWhiteboard' then third parameter base64Image is required
|
|
275
|
+
- `setupDrawerOptions(options: KonvaDrawerOptions)` - setup option for drawer
|
|
276
|
+
- `setupScreenShareDrawerOptions(options: KonvaScreenShareDrawerOptions)` - setup option for screen share drawer
|
|
277
|
+
|
|
278
|
+
VisualizationConfigType
|
|
279
|
+
|
|
280
|
+
| Parameter | Type | Default |
|
|
281
|
+
|-----------------------|----------|---------|
|
|
282
|
+
| `foregroundThreshold` | `number` | `0.5` |
|
|
283
|
+
| `maskOpacity` | `number` | `0.5` |
|
|
284
|
+
| `maskBlur` | `number` | `0` |
|
|
285
|
+
| `pixelCellWidth` | `number` | `10` |
|
|
286
|
+
| `backgroundBlur` | `number` | `15` |
|
|
287
|
+
| `edgeBlur` | `number` | `3` |
|
|
288
|
+
|
|
289
|
+
KonvaDrawerOptions
|
|
290
|
+
|
|
291
|
+
| Parameter | Type |
|
|
292
|
+
|-------------|----------|
|
|
293
|
+
| `container` | `number` |
|
|
294
|
+
| `width` | `number` |
|
|
295
|
+
| `height` | `number` |
|
|
296
|
+
|
|
297
|
+
KonvaScreenShareDrawerOptions
|
|
298
|
+
|
|
299
|
+
| Parameter | Type |
|
|
300
|
+
|---------------|----------|
|
|
301
|
+
| `strokeWidth` | `number` |
|
|
302
|
+
| `strokeColor` | `string` |
|
|
303
|
+
|
|
304
|
+
### Video events
|
|
305
|
+
|
|
306
|
+
| Event | Callback interface | Description |
|
|
307
|
+
|--------------------------|--------------------|-------------------------------------------|
|
|
308
|
+
| `member:join` | `(data) => {}` | Emitted when new member is joined |
|
|
309
|
+
| `member:update` | `(data) => {}` | Emitted when member data is changed |
|
|
310
|
+
| `member:hangup` | `(data) => {}` | Emitted when member leaves the conference |
|
|
311
|
+
| `hangup` | `() => {}` | Emitted when we leave the conference |
|
|
312
|
+
| `screenShare:start` | `() => {}` | Emitted when we share a screen |
|
|
313
|
+
| `screenShare:stop` | `() => {}` | Emitted when we stop a screen sharing |
|
|
314
|
+
| `reconnect` | `() => {}` | Emitted when reconnecting |
|
|
315
|
+
| `mediaConstraintsChange` | `() => {}` | Emitted when media constraints change |
|
|
316
|
+
| `metrics:report` | `() => {}` | Emitted on metric report |
|
|
317
|
+
| `metrics:stop` | `() => {}` | Emitted when metrics are stopped |
|