surflion-service 1.5.2 → 1.5.4

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/package.json CHANGED
@@ -1,11 +1,27 @@
1
1
  {
2
2
  "name": "surflion-service",
3
- "version": "1.5.2",
4
- "description": "SurfLion WebRTC Service Library with integrated JsSIP for real-time communication",
3
+ "version": "1.5.4",
4
+ "description": "SurfLion WebRTC Library",
5
+ "type": "module",
5
6
  "main": "surflion.js",
7
+ "module": "surflion.js",
8
+ "browser": "dist/surflion.min.js",
9
+ "unpkg": "dist/surflion.js",
10
+ "jsdelivr": "dist/surflion.js",
11
+ "types": "surflion.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./surflion.d.ts",
15
+ "import": "./surflion.js",
16
+ "require": "./surflion.js",
17
+ "browser": "./dist/surflion.min.js",
18
+ "default": "./surflion.js"
19
+ }
20
+ },
6
21
  "files": [
7
22
  "surflion.js",
8
- "surflion.min.js"
23
+ "surflion.d.ts",
24
+ "dist/"
9
25
  ],
10
26
  "keywords": [
11
27
  "webrtc",
package/surflion.d.ts ADDED
@@ -0,0 +1,178 @@
1
+ // TypeScript declarations for SurfLion WebRTC Library
2
+
3
+ declare module 'surflion-service' {
4
+ export default SurfLion;
5
+ }
6
+
7
+ /**
8
+ * Call type enumeration
9
+ */
10
+ export enum CallTypeEnum {
11
+ INIT = 0,
12
+ PREDICTIVE_OUTBOUND = 10,
13
+ }
14
+
15
+ /**
16
+ * Call information interface
17
+ */
18
+ export interface CallInfo {
19
+ CallNumber: string;
20
+ [key: string]: any;
21
+ }
22
+
23
+ /**
24
+ * User list item interface
25
+ */
26
+ export interface UserListItem {
27
+ value: string;
28
+ label: string;
29
+ }
30
+
31
+ /**
32
+ * Media constraints interface
33
+ */
34
+ export interface MediaConstraints {
35
+ audio: boolean;
36
+ video: boolean;
37
+ }
38
+
39
+ /**
40
+ * Position configuration interface
41
+ */
42
+ export interface PositionConfig {
43
+ position?: number;
44
+ positionX?: string;
45
+ positionY?: string;
46
+ }
47
+
48
+ /**
49
+ * Event handler function types
50
+ */
51
+ export type EventHandler = () => void;
52
+ export type CallEventHandler = (callInfo: CallInfo) => void;
53
+
54
+ /**
55
+ * Main SurfLion interface
56
+ */
57
+ export interface SurfLionInterface {
58
+ // Version and configuration
59
+ version: string;
60
+ showAll: boolean;
61
+
62
+ // Session management
63
+ outgoingSession: any | null;
64
+ incomingSession: any | null;
65
+ currentSession: any | null;
66
+ vCallTimerId: any | null;
67
+
68
+ // Audio/Video settings
69
+ microphone: boolean;
70
+ outgoing: boolean;
71
+ constraints: MediaConstraints;
72
+ localStream: HTMLAudioElement | null;
73
+ ringtoneStream: HTMLAudioElement | null;
74
+ hangupStream: HTMLAudioElement | null;
75
+
76
+ // SIP configuration
77
+ ext_num: string;
78
+ sip_uri_: string;
79
+ sip_password_: string;
80
+ ws_uri_: string;
81
+ userAgent: any | null;
82
+
83
+ // Status and state
84
+ debug: boolean;
85
+ agentStatus: boolean;
86
+ canIncoming: boolean;
87
+ phoneEnded: boolean;
88
+ phoneState: string;
89
+ callingState: string;
90
+ floatWindowState: boolean;
91
+ phoneToward: string;
92
+ phoneCallingTime: string;
93
+ phoneResult: boolean;
94
+
95
+ // UI positioning
96
+ vPosition: number;
97
+ vDirection: boolean;
98
+ positionX: string;
99
+ positionY: string;
100
+
101
+ // Data and identification
102
+ userList: UserListItem[];
103
+ showPhoneNumber: string;
104
+ callID: string;
105
+ endReason: string;
106
+ pageError: string;
107
+ CallType: number;
108
+ XUuid: string;
109
+ worker: any | null;
110
+
111
+ // Event handlers
112
+ onRegister: EventHandler;
113
+ onUnRegister: EventHandler;
114
+ onRegisterFail: EventHandler;
115
+ onCallBegin: EventHandler;
116
+ onCallAnswer: EventHandler;
117
+ onCallEnd: EventHandler;
118
+ onCallIn: CallEventHandler;
119
+
120
+ // UI management methods
121
+ closeVCalling(): void;
122
+ createVCalling(callInfo: CallInfo): void;
123
+ closeVAnswer(): void;
124
+ createVAnswer(callInfo: CallInfo): void;
125
+ createVError(position: number, positionX: string, positionY: string): void;
126
+ closeVError(): void;
127
+ createVEnd(): void;
128
+ closeVEnd(): void;
129
+ closeVCall(): void;
130
+ createVCall(): void;
131
+ closeVKeyboard(): void;
132
+ createVKeyboard(show: boolean): void;
133
+
134
+ // SIP methods
135
+ sipRegister(
136
+ sip_uri_: string,
137
+ sip_password_: string,
138
+ ws_uri_: string,
139
+ show: boolean,
140
+ ext_num: string,
141
+ direction: boolean,
142
+ floatWindowState: boolean,
143
+ position: number,
144
+ positionX: string,
145
+ positionY: string,
146
+ ringtoneStream?: string,
147
+ hangupStream?: string
148
+ ): void;
149
+
150
+ sipUnRegister(): void;
151
+ sipCall(sip_phone_number_: string): void;
152
+ sipAnswer(): void;
153
+ sipHangUp(): void;
154
+
155
+ // Utility methods
156
+ findName(value: string): string;
157
+ sipInitAddress(list: UserListItem[]): void;
158
+ sipMute(): void;
159
+ sipUnmute(): void;
160
+ sipMuteAudio(): void;
161
+ sipUnmuteAudio(): void;
162
+ sipLogout(): void;
163
+ sipShowHidden(): void;
164
+ sipCloseFloat(): void;
165
+
166
+ // SharedWorker methods
167
+ initSharework(address: string): void;
168
+ visibilityListen(address: string): void;
169
+ closeShareWork(): void;
170
+ closeAllPage(state: boolean): void;
171
+ }
172
+
173
+ /**
174
+ * Main SurfLion object
175
+ */
176
+ declare const SurfLion: SurfLionInterface;
177
+
178
+ export default SurfLion;
package/surflion.js CHANGED
@@ -1,5 +1,13 @@
1
1
  import JsSIP from 'jssip'
2
- var SurfLion = {
2
+
3
+ const CallTypeEnum = {
4
+ INIT: 0,
5
+ PREDICTIVE_OUTBOUND: 10,
6
+ APP_OUT_CALL: 11,
7
+ API_OUT_CALL: 12,
8
+ };
9
+
10
+ const SurfLion = {
3
11
  version: process.env.PACKAGE_VERSION,
4
12
  showAll: true,
5
13
  outgoingSession: null,
@@ -39,7 +47,51 @@ var SurfLion = {
39
47
  phoneToward: 'in',
40
48
  phoneCallingTime: '0',
41
49
  phoneResult: false,
50
+ phoneAnswerTime: '',
42
51
  worker: null,
52
+ CallType: CallTypeEnum.INIT,
53
+ XUuid: '',
54
+ preferOpus: function(sdp) {
55
+ var sdpLines = sdp.split('\r\n');
56
+ var mLineIndex = -1;
57
+ for (var i = 0; i < sdpLines.length; i++) {
58
+ if (sdpLines[i].search('m=audio') !== -1) {
59
+ mLineIndex = i;
60
+ break;
61
+ }
62
+ }
63
+ if (mLineIndex === -1) return sdp;
64
+
65
+ for (var i = 0; i < sdpLines.length; i++) {
66
+ if (sdpLines[i].search('opus/48000') !== -1) {
67
+ var opusPayload = extractPayloadType(sdpLines[i]);
68
+ if (opusPayload) {
69
+ sdpLines[mLineIndex] = removePayloadType(sdpLines[mLineIndex], opusPayload);
70
+ var parts = sdpLines[mLineIndex].split(' ');
71
+ parts.splice(3, 0, opusPayload);
72
+ sdpLines[mLineIndex] = parts.join(' ');
73
+ }
74
+ }
75
+ }
76
+ return sdpLines.join('\r\n');
77
+
78
+ function extractPayloadType(line) {
79
+ var pattern = /a=rtpmap:(\d+) opus\/48000/;
80
+ var result = line.match(pattern);
81
+ return (result && result.length == 2) ? result[1] : null;
82
+ }
83
+
84
+ function removePayloadType(line, payload) {
85
+ var parts = line.split(' ');
86
+ for (var i = 3; i < parts.length; i++) {
87
+ if (parts[i] == payload) {
88
+ parts.splice(i, 1);
89
+ i--;
90
+ }
91
+ }
92
+ return parts.join(' ');
93
+ }
94
+ },
43
95
  onRegister: function () {
44
96
  },
45
97
  onUnRegister: function () {
@@ -236,7 +288,7 @@ var SurfLion = {
236
288
  let seconds = 0;
237
289
  let minutes = 0;
238
290
  let hours = 0;
239
-
291
+ SurfLion.phoneAnswerTime = Date.now();
240
292
  SurfLion.vCallTimerId = setInterval(function () {
241
293
  seconds++;
242
294
 
@@ -1080,7 +1132,7 @@ var SurfLion = {
1080
1132
  })
1081
1133
  },
1082
1134
  addVKeydown(event){
1083
- var keyPressed = event.key;
1135
+ const keyPressed = event.key;
1084
1136
  if (keyPressed >= '0' && keyPressed <= '9') {
1085
1137
  SurfLion.addToPhoneNumber(keyPressed)
1086
1138
  }
@@ -1353,7 +1405,6 @@ var SurfLion = {
1353
1405
  CallNumber : e.request.from._display_name
1354
1406
  }
1355
1407
 
1356
-
1357
1408
  if(SurfLion.ext_num == e.request.from._display_name) {
1358
1409
  SurfLion.endReason = 'Cannot call oneself '
1359
1410
  SurfLion.sipHangUp()
@@ -1363,6 +1414,15 @@ var SurfLion = {
1363
1414
  SurfLion.createVAnswer(callInfo)
1364
1415
  }
1365
1416
 
1417
+ const CallType = e.request.getHeader('Call-Type');
1418
+ if (CallType) {
1419
+ SurfLion.CallType = +CallType || 0;
1420
+ }
1421
+ const XUuid = e.request.getHeader('X-Uuid');
1422
+ if (XUuid) {
1423
+ SurfLion.XUuid = XUuid;
1424
+ }
1425
+
1366
1426
  window.localStorage.setItem("surflion_registered", '3');
1367
1427
  const event = new Event('localStorageSurflionChange');
1368
1428
  window.dispatchEvent(event);
@@ -1435,6 +1495,10 @@ var SurfLion = {
1435
1495
 
1436
1496
  SurfLion.microphone = true
1437
1497
  SurfLion.outgoing = true
1498
+
1499
+ SurfLion.CallType = CallTypeEnum.INIT;
1500
+ SurfLion.XUuid = '';
1501
+
1438
1502
  window.localStorage.setItem("surflion_registered", '1');
1439
1503
  const event = new Event('localStorageSurflionChange');
1440
1504
  window.localStorage.setItem("localStorageSurflionCall", '0');
@@ -1480,14 +1544,13 @@ var SurfLion = {
1480
1544
  document.body.appendChild(SurfLion.hangupStream);
1481
1545
  }
1482
1546
 
1483
- var socket = new JsSIP.WebSocketInterface(ws_uri_);
1484
- var configuration = {
1547
+ const socket = new JsSIP.WebSocketInterface(ws_uri_);
1548
+ const configuration = {
1485
1549
  sockets: [socket],
1486
1550
  uri: sip_uri_,
1487
1551
  password: sip_password_,
1488
1552
  register: true,
1489
1553
  session_timers: false,
1490
- iceServers: [],
1491
1554
  contact_uri: sip_uri_ + ';transport=wss'
1492
1555
  };
1493
1556
 
@@ -1520,6 +1583,14 @@ var SurfLion = {
1520
1583
  });
1521
1584
  SurfLion.userAgent.on('newRTCSession', function (data) {
1522
1585
 
1586
+ // Force the use of OPUS encoding as the preferred method.
1587
+ const session = data.session;
1588
+ session.on('sdp', function(e) {
1589
+ if (e.originator === 'local') {
1590
+ e.sdp = SurfLion.preferOpus(e.sdp);
1591
+ }
1592
+ });
1593
+
1523
1594
  if (data.originator == 'remote') {
1524
1595
  if (!SurfLion.canIncoming){
1525
1596
  return
@@ -1629,9 +1700,18 @@ var SurfLion = {
1629
1700
 
1630
1701
  sipAnswer: function () {
1631
1702
  if (SurfLion.incomingSession) {
1632
- SurfLion.incomingSession.answer({
1633
- 'mediaConstraints': {'audio': true, 'video': false},
1634
- });
1703
+ try {
1704
+ // Check if session is already ended or not in a valid state
1705
+ if (SurfLion.incomingSession.isEnded()) {
1706
+ console.warn('SurfLion: Session already ended, cannot answer.');
1707
+ return;
1708
+ }
1709
+ SurfLion.incomingSession.answer({
1710
+ 'mediaConstraints': {'audio': true, 'video': false},
1711
+ });
1712
+ } catch (error) {
1713
+ console.error('SurfLion: Error answering call:', error);
1714
+ }
1635
1715
  }
1636
1716
  },
1637
1717
  sipHangUp: function () {