@voicenter-team/opensips-js 1.0.96 → 1.0.98
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +165 -58
- package/dist/index.d.ts +94 -4
- package/dist/opensips-js.cjs.js +14181 -132
- package/dist/opensips-js.es.js +48072 -12784
- package/dist/opensips-js.iife.js +14181 -132
- package/dist/opensips-js.umd.js +14181 -132
- package/package.json +19 -4
- package/src/types/listeners.d.ts +8 -1
- package/src/types/rtc.d.ts +5 -1
package/README.md
CHANGED
@@ -8,12 +8,22 @@ navigation:
|
|
8
8
|
# Getting started
|
9
9
|
|
10
10
|
## Installation
|
11
|
-
Using npm:
|
11
|
+
### Using npm:
|
12
12
|
```shell[Terminal]
|
13
13
|
$ npm i @voicenter-team/opensips-js
|
14
14
|
```
|
15
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
|
+
|
16
25
|
## Usage
|
26
|
+
### Using npm (ES Modules):
|
17
27
|
Firstly lets import the library and create the OpenSIPS instance:
|
18
28
|
```javascript [file.js]
|
19
29
|
import OpenSIPSJS from '@voicenter-team/opensips-js'
|
@@ -41,15 +51,112 @@ const openSIPSJS = new OpenSIPSJS({
|
|
41
51
|
},
|
42
52
|
modules: [ 'audio', 'video', 'msrp' ]
|
43
53
|
})
|
54
|
+
|
55
|
+
// Then you can work with the appropriate modules
|
56
|
+
opensipsJS.audio
|
57
|
+
opensipsJS.video
|
58
|
+
opensipsJS.msrp
|
44
59
|
```
|
45
60
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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>
|
51
154
|
```
|
52
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
|
+
|
53
160
|
## OpensipsJS
|
54
161
|
### OpensipsJS instance methods
|
55
162
|
- `begin(): OpensipsInstance` - start opensips
|
@@ -59,35 +166,35 @@ openSIPSJS.msrp
|
|
59
166
|
|
60
167
|
### OpensipsJS events
|
61
168
|
|
62
|
-
| Event
|
63
|
-
|
64
|
-
| `ready`
|
65
|
-
| `changeActiveCalls`
|
66
|
-
| `callAddingInProgressChanged` | `(callId: string / undefined) => {}`
|
67
|
-
| `changeAvailableDeviceList`
|
68
|
-
| `changeActiveInputMediaDevice`
|
69
|
-
| `changeActiveOutputMediaDevice`
|
70
|
-
| `changeMuteWhenJoin`
|
71
|
-
| `changeIsDND`
|
72
|
-
| `changeIsMuted`
|
73
|
-
| `changeActiveStream`
|
74
|
-
| `changeCallVolume`
|
75
|
-
| `currentActiveRoomChanged`
|
76
|
-
| `addRoom`
|
77
|
-
| `updateRoom`
|
78
|
-
| `removeRoom`
|
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 |
|
79
186
|
|
80
187
|
WebrtcMetricsConfigType
|
81
188
|
|
82
|
-
| Parameter | Type | Default
|
83
|
-
|
84
|
-
| `refreshEvery` | `number`
|
85
|
-
| `startAfter` | `number`
|
86
|
-
| `startAfter` | `number`
|
189
|
+
| Parameter | Type | Default |
|
190
|
+
|----------------|-----------|-------------|
|
191
|
+
| `refreshEvery` | `number` | `undefined` |
|
192
|
+
| `startAfter` | `number` | `undefined` |
|
193
|
+
| `startAfter` | `number` | `undefined` |
|
87
194
|
| `verbose` | `boolean` | `undefined` |
|
88
|
-
| `pname` | `string`
|
89
|
-
| `cid` | `string`
|
90
|
-
| `uid` | `string`
|
195
|
+
| `pname` | `string` | `undefined` |
|
196
|
+
| `cid` | `string` | `undefined` |
|
197
|
+
| `uid` | `string` | `undefined` |
|
91
198
|
| `record` | `boolean` | `undefined` |
|
92
199
|
| `ticket` | `boolean` | `undefined` |
|
93
200
|
|
@@ -170,41 +277,41 @@ Also, there are next public fields on OpensipsJS instance:
|
|
170
277
|
|
171
278
|
VisualizationConfigType
|
172
279
|
|
173
|
-
| Parameter
|
174
|
-
|
175
|
-
| `foregroundThreshold` | `number` | `0.5`
|
176
|
-
| `maskOpacity`
|
177
|
-
| `maskBlur`
|
178
|
-
| `pixelCellWidth` | `number
|
179
|
-
| `backgroundBlur`
|
180
|
-
| `edgeBlur`
|
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` |
|
181
288
|
|
182
289
|
KonvaDrawerOptions
|
183
290
|
|
184
|
-
| Parameter
|
185
|
-
|
291
|
+
| Parameter | Type |
|
292
|
+
|-------------|----------|
|
186
293
|
| `container` | `number` |
|
187
|
-
| `width`
|
188
|
-
| `height`
|
294
|
+
| `width` | `number` |
|
295
|
+
| `height` | `number` |
|
189
296
|
|
190
297
|
KonvaScreenShareDrawerOptions
|
191
298
|
|
192
|
-
| Parameter
|
193
|
-
|
299
|
+
| Parameter | Type |
|
300
|
+
|---------------|----------|
|
194
301
|
| `strokeWidth` | `number` |
|
195
|
-
| `strokeColor`
|
302
|
+
| `strokeColor` | `string` |
|
196
303
|
|
197
304
|
### Video events
|
198
305
|
|
199
|
-
| Event
|
200
|
-
|
201
|
-
| `member:join`
|
202
|
-
| `member:update`
|
203
|
-
| `member:hangup`
|
204
|
-
| `hangup`
|
205
|
-
| `screenShare:start`
|
206
|
-
| `screenShare:stop`
|
207
|
-
| `reconnect`
|
208
|
-
| `mediaConstraintsChange`
|
209
|
-
| `metrics:report`
|
210
|
-
| `metrics:stop`
|
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 |
|
package/dist/index.d.ts
CHANGED
@@ -191,6 +191,62 @@ declare class AudioModule {
|
|
191
191
|
|
192
192
|
declare type AudioModuleName = typeof MODULES.AUDIO
|
193
193
|
|
194
|
+
export declare class BaseNewStreamPlugin extends BasePlugin {
|
195
|
+
private _candidates;
|
196
|
+
private _subscribeSent;
|
197
|
+
private _configureSent;
|
198
|
+
private _lastTrickleReceived;
|
199
|
+
private _publisherSubscribeSent;
|
200
|
+
private opaqueId;
|
201
|
+
private handleId;
|
202
|
+
private readonly type;
|
203
|
+
protected _connection: RTCPeerConnection;
|
204
|
+
protected jsep_offer: RTCSessionDescription | void;
|
205
|
+
protected _request: unknown;
|
206
|
+
stream: MediaStream;
|
207
|
+
constructor(name: any, type: any);
|
208
|
+
connect(options?: ConnectOptions): void;
|
209
|
+
getStream(): MediaStream;
|
210
|
+
getConnection(): RTCPeerConnection;
|
211
|
+
private _createRTCConnection;
|
212
|
+
private addTracks;
|
213
|
+
private _sendInitialRequest;
|
214
|
+
private _receiveInviteResponse;
|
215
|
+
private _sendConfigureMessage;
|
216
|
+
private _sendDetach;
|
217
|
+
protected stopMedia(): Promise<void>;
|
218
|
+
stop(): Promise<void>;
|
219
|
+
generateStream(): Promise<void>;
|
220
|
+
}
|
221
|
+
|
222
|
+
declare class BasePlugin {
|
223
|
+
opensips: any;
|
224
|
+
session: any;
|
225
|
+
name: string;
|
226
|
+
constructor(name: any);
|
227
|
+
setOpensips(opensips: any): void;
|
228
|
+
setSession(session: any): void;
|
229
|
+
kill(): void;
|
230
|
+
}
|
231
|
+
|
232
|
+
export declare class BaseProcessStreamPlugin extends BasePlugin {
|
233
|
+
stream: any;
|
234
|
+
running: boolean;
|
235
|
+
immediate: boolean;
|
236
|
+
type: string;
|
237
|
+
constructor(name: any, type: any, options?: BaseProcessStreamPluginOptions);
|
238
|
+
start(stream: any): any;
|
239
|
+
stop(): void;
|
240
|
+
process(stream: any): Promise<any>;
|
241
|
+
connect(): Promise<void>;
|
242
|
+
terminate(): void;
|
243
|
+
kill(): Promise<void>;
|
244
|
+
}
|
245
|
+
|
246
|
+
declare interface BaseProcessStreamPluginOptions {
|
247
|
+
immediate?: boolean;
|
248
|
+
}
|
249
|
+
|
194
250
|
declare type CallAddingProgressListener = (callId: string | undefined) => void
|
195
251
|
|
196
252
|
declare interface CallOptionsExtended extends AnswerOptionsExtended {
|
@@ -233,8 +289,6 @@ declare type changeIsDNDListener = (value: boolean) => void
|
|
233
289
|
|
234
290
|
declare type changeIsMutedListener = (value: boolean) => void
|
235
291
|
|
236
|
-
declare type changeMainVideoStreamListener = (event: { name: string, event: MediaStream }) => void
|
237
|
-
|
238
292
|
declare type changeMuteWhenJoinListener = (value: boolean) => void
|
239
293
|
|
240
294
|
declare type changeVideoStateListener = (state: boolean) => void
|
@@ -250,6 +304,14 @@ declare type conferenceStartListener = () => void
|
|
250
304
|
|
251
305
|
declare type connectionListener = (value: boolean) => void
|
252
306
|
|
307
|
+
declare interface ConnectOptions {
|
308
|
+
extraHeaders?: Array<string>;
|
309
|
+
fromUserName?: string;
|
310
|
+
fromDisplayName?: string;
|
311
|
+
rtcConstraints?: object;
|
312
|
+
pcConfig?: object;
|
313
|
+
}
|
314
|
+
|
253
315
|
declare interface CustomLoggerType {
|
254
316
|
log: CommonLogMethodType
|
255
317
|
warn: CommonLogMethodType
|
@@ -301,7 +363,7 @@ declare interface IncomingMSRPSessionEvent {
|
|
301
363
|
|
302
364
|
declare type IncomingMSRPSessionListener = (event: IncomingMSRPSessionEvent) => void;
|
303
365
|
|
304
|
-
declare type IOpenSIPSConfiguration = Omit<
|
366
|
+
declare type IOpenSIPSConfiguration = Omit<UAConfigurationExtended, 'sockets'>
|
305
367
|
|
306
368
|
declare interface IOpenSIPSJSOptions {
|
307
369
|
configuration: IOpenSIPSConfiguration
|
@@ -660,7 +722,10 @@ declare interface OpenSIPSEventMap extends UAEventMap {
|
|
660
722
|
newMSRPSession: MSRPSessionListener
|
661
723
|
// JANUS
|
662
724
|
conferenceStart: conferenceStartListener
|
663
|
-
|
725
|
+
startScreenShare: startScreenShareListener
|
726
|
+
stopScreenShare: stopScreenShareListener
|
727
|
+
startBlur: startBlurListener
|
728
|
+
stopBlur: stopBlurListener
|
664
729
|
memberJoin: memberJoinListener
|
665
730
|
memberHangup: memberHangupListener
|
666
731
|
changeAudioState: changeAudioStateListener
|
@@ -680,6 +745,7 @@ declare class OpenSIPSJS extends UAExtended {
|
|
680
745
|
private readonly newMSRPSessionEventName;
|
681
746
|
private isMSRPInitializingValue;
|
682
747
|
private isReconnecting;
|
748
|
+
private activeConnection;
|
683
749
|
audio: AudioModule;
|
684
750
|
msrp: MSRPModule;
|
685
751
|
video: VideoModule;
|
@@ -690,7 +756,10 @@ declare class OpenSIPSJS extends UAExtended {
|
|
690
756
|
off<T extends ListenersKeyType>(type: T, listener: ListenerCallbackFnType<T>): this;
|
691
757
|
emit(type: ListenersKeyType, args: any): boolean;
|
692
758
|
get sipDomain(): string;
|
759
|
+
use(plugin: BaseNewStreamPlugin | BaseProcessStreamPlugin): void;
|
760
|
+
getPlugin(name: string): BaseNewStreamPlugin | BaseProcessStreamPlugin;
|
693
761
|
begin(): this;
|
762
|
+
disconnect(): void;
|
694
763
|
subscribe(type: string, listener: (c: RTCSessionExtended) => void): void;
|
695
764
|
removeIListener(value: string): void;
|
696
765
|
triggerListener({ listenerType, session, event }: TriggerListenerOptions): void;
|
@@ -767,6 +836,14 @@ declare interface RTCSessionExtended extends RTCSession {
|
|
767
836
|
init_icncoming(request: IncomingRequest): void
|
768
837
|
}
|
769
838
|
|
839
|
+
declare type startBlurListener = () => void
|
840
|
+
|
841
|
+
declare type startScreenShareListener = (event: MediaStream) => void
|
842
|
+
|
843
|
+
declare type stopBlurListener = () => void
|
844
|
+
|
845
|
+
declare type stopScreenShareListener = () => void
|
846
|
+
|
770
847
|
declare interface StreamMediaType extends HTMLAudioElement {
|
771
848
|
className: string
|
772
849
|
setSinkId (id: string): Promise<void>
|
@@ -780,6 +857,10 @@ declare interface TriggerListenerOptions {
|
|
780
857
|
event?: ListenerEventType
|
781
858
|
}
|
782
859
|
|
860
|
+
declare type UAConfigurationExtended = UAConfiguration & {
|
861
|
+
overrideUserAgent: (userAgent: string) => string
|
862
|
+
}
|
863
|
+
|
783
864
|
declare const UAConstructor: typeof UA;
|
784
865
|
|
785
866
|
declare class UAExtended extends UAConstructor implements UAExtendedInterface {
|
@@ -791,15 +872,21 @@ declare class UAExtended extends UAConstructor implements UAExtendedInterface {
|
|
791
872
|
ict: {};
|
792
873
|
};
|
793
874
|
_janus_sessions: any[];
|
875
|
+
protected newStreamPlugins: Array<BaseNewStreamPlugin>;
|
876
|
+
protected processStreamPlugins: Array<BaseProcessStreamPlugin>;
|
794
877
|
constructor(configuration: UAConfiguration);
|
795
878
|
call(target: string, options?: CallOptionsExtended): RTCSession;
|
796
879
|
joinVideoCall(target: any, displayName: any, options: any): any;
|
880
|
+
startScreenShare(): void;
|
881
|
+
startBlur(): void;
|
882
|
+
stopBlur(): void;
|
797
883
|
_loadConfig(configuration: any): void;
|
798
884
|
/**
|
799
885
|
* new MSRPSession
|
800
886
|
*/
|
801
887
|
newMSRPSession(session: MSRPSession, data: object): void;
|
802
888
|
newJanusSession(session: any, data: any): void;
|
889
|
+
kill(): void;
|
803
890
|
/**
|
804
891
|
* MSRPSession destroyed.
|
805
892
|
*/
|
@@ -863,6 +950,9 @@ declare class VideoModule {
|
|
863
950
|
stopAudio(): void;
|
864
951
|
startVideo(): void;
|
865
952
|
stopVideo(): void;
|
953
|
+
startScreenShare(): void;
|
954
|
+
startBlur(): void;
|
955
|
+
stopBlur(): void;
|
866
956
|
}
|
867
957
|
|
868
958
|
declare type VideoModuleName = typeof MODULES.VIDEO
|