surflion-service 1.2.1 → 1.2.3
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 +1 -1
- package/shareWork.js +66 -0
- package/surflion.js +91 -1
package/package.json
CHANGED
package/shareWork.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// sharedWorker.js
|
|
2
|
+
let connections = [];
|
|
3
|
+
|
|
4
|
+
self.onconnect = function (e) {
|
|
5
|
+
const port = e.ports[0];
|
|
6
|
+
connections.push(port);
|
|
7
|
+
|
|
8
|
+
port.addEventListener('message', function (e) {
|
|
9
|
+
console.log('Message from main thread:', e.data, e, connections);
|
|
10
|
+
|
|
11
|
+
if(e.data == 'newconnect') {
|
|
12
|
+
const index = connections.indexOf(port);
|
|
13
|
+
connections[index].postMessage('connectselect')
|
|
14
|
+
connections.forEach((connection, idx) => {
|
|
15
|
+
if (idx !== index) {
|
|
16
|
+
connection.postMessage('connectother');
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if(e.data == 'connectclose') {
|
|
22
|
+
const index = connections.indexOf(port);
|
|
23
|
+
connections.splice(index, 1);
|
|
24
|
+
if(connections.length > 0) {
|
|
25
|
+
connections[0].postMessage('changeconnect')
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if(e.data == 'normalclose') {
|
|
30
|
+
const index = connections.indexOf(port);
|
|
31
|
+
connections.splice(index, 1);
|
|
32
|
+
if(connections.length > 0) {
|
|
33
|
+
connections[0].postMessage('changeconnect')
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if(e.data == 'close') {
|
|
38
|
+
const index = connections.indexOf(port);
|
|
39
|
+
connections.splice(index, 1);
|
|
40
|
+
if(connections.length > 0) {
|
|
41
|
+
connections[0].postMessage('changeconnect')
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if(e.data == 'hangup') {
|
|
46
|
+
const index = connections.indexOf(port);
|
|
47
|
+
connections[index].postMessage('hangupselect')
|
|
48
|
+
connections.forEach((connection, idx) => {
|
|
49
|
+
if (idx !== index) {
|
|
50
|
+
connection.postMessage('hangupother');
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// if(e.data == 'otherconnect') {
|
|
56
|
+
// const index = connections.indexOf(port);
|
|
57
|
+
// connections.splice(index, 1);
|
|
58
|
+
// if(connections.length > 0) {
|
|
59
|
+
// connections[0].postMessage('changeconnect')
|
|
60
|
+
// }
|
|
61
|
+
// }
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
port.start();
|
|
65
|
+
|
|
66
|
+
};
|
package/surflion.js
CHANGED
|
@@ -21,7 +21,6 @@ var SurfLion = {
|
|
|
21
21
|
phoneEnded: false,
|
|
22
22
|
userList: [],
|
|
23
23
|
showPhoneNumber: '',
|
|
24
|
-
phoneCallingTime: '0',
|
|
25
24
|
callID:"",
|
|
26
25
|
positionX: '',
|
|
27
26
|
positionY: '',
|
|
@@ -35,6 +34,10 @@ var SurfLion = {
|
|
|
35
34
|
floatWindowState: false,
|
|
36
35
|
vPosition: 0,
|
|
37
36
|
vDirection: false,
|
|
37
|
+
phoneToward: 'in',
|
|
38
|
+
phoneCallingTime: '0',
|
|
39
|
+
phoneResult: false,
|
|
40
|
+
worker: null,
|
|
38
41
|
onRegister: function () {
|
|
39
42
|
},
|
|
40
43
|
onUnRegister: function () {
|
|
@@ -1298,6 +1301,7 @@ var SurfLion = {
|
|
|
1298
1301
|
},1000)
|
|
1299
1302
|
},
|
|
1300
1303
|
'connecting': function (e) {
|
|
1304
|
+
SurfLion.phoneToward = 'out'
|
|
1301
1305
|
window.localStorage.setItem("surflion_registered", '3');
|
|
1302
1306
|
const event = new Event('localStorageSurflionChange');
|
|
1303
1307
|
window.dispatchEvent(event);
|
|
@@ -1317,6 +1321,7 @@ var SurfLion = {
|
|
|
1317
1321
|
SurfLion.createVCall()
|
|
1318
1322
|
},
|
|
1319
1323
|
'incoming': function(e) {
|
|
1324
|
+
SurfLion.phoneToward = 'in'
|
|
1320
1325
|
SurfLion.phoneEnded = false
|
|
1321
1326
|
window.localStorage.setItem("surflion_registered", '3');
|
|
1322
1327
|
const event = new Event('localStorageSurflionChange');
|
|
@@ -1381,8 +1386,10 @@ var SurfLion = {
|
|
|
1381
1386
|
// }
|
|
1382
1387
|
if(e.cause == "Terminated") {
|
|
1383
1388
|
SurfLion.endReason = 'Call ended'
|
|
1389
|
+
SurfLion.phoneResult = true
|
|
1384
1390
|
} else {
|
|
1385
1391
|
SurfLion.endReason = e.cause
|
|
1392
|
+
SurfLion.phoneResult = false
|
|
1386
1393
|
}
|
|
1387
1394
|
SurfLion.onCallEnd()
|
|
1388
1395
|
SurfLion.hangupStream.play();
|
|
@@ -1403,6 +1410,11 @@ var SurfLion = {
|
|
|
1403
1410
|
const events = new Event('localStorageSurflionCalling');
|
|
1404
1411
|
window.dispatchEvent(events);
|
|
1405
1412
|
window.dispatchEvent(event);
|
|
1413
|
+
const endEvent = new Event('SurflionPhoneEnd');
|
|
1414
|
+
window.dispatchEvent(endEvent);
|
|
1415
|
+
if(SurfLion.worker && SurfLion.worker.port) {
|
|
1416
|
+
SurfLion.worker.port.postMessage("hangup");
|
|
1417
|
+
}
|
|
1406
1418
|
},
|
|
1407
1419
|
},
|
|
1408
1420
|
sipRegister: function (sip_uri_,sip_password_,ws_uri_,show,ext_num,direction,floatWindowState, position, positionX, positionY, ringtoneStream,hangupStream) {
|
|
@@ -1724,6 +1736,84 @@ var SurfLion = {
|
|
|
1724
1736
|
SurfLion.createVFloatWindow()
|
|
1725
1737
|
}
|
|
1726
1738
|
},
|
|
1739
|
+
initSharework: function(address) {
|
|
1740
|
+
let useAddress = address ? address : './shareWork.js'
|
|
1741
|
+
SurfLion.worker = new SharedWorker(useAddress);
|
|
1742
|
+
document.addEventListener("visibilitychange", () => SurfLion.visibilityListen(useAddress));
|
|
1743
|
+
SurfLion.worker.port.addEventListener("message", (event) => {
|
|
1744
|
+
if (event.data == "changeconnect") {
|
|
1745
|
+
window.localStorage.setItem("surflion_registered", "0");
|
|
1746
|
+
const event = new Event("localStorageSurflionChange");
|
|
1747
|
+
window.dispatchEvent(event);
|
|
1748
|
+
}
|
|
1749
|
+
if (event.data == "connectother") {
|
|
1750
|
+
try {
|
|
1751
|
+
SurfLion.sipLogout();
|
|
1752
|
+
} catch (e) {
|
|
1753
|
+
console.log("error", e);
|
|
1754
|
+
}
|
|
1755
|
+
window.localStorage.setItem("surflion_registered", '0')
|
|
1756
|
+
let event = new Event('localStorageSurflionChange');
|
|
1757
|
+
window.dispatchEvent(event);
|
|
1758
|
+
}
|
|
1759
|
+
if (event.data == "connectselect") {
|
|
1760
|
+
console.log(
|
|
1761
|
+
'window.localStorage.getItem("surflion_registered")',
|
|
1762
|
+
window.localStorage.getItem("surflion_registered")
|
|
1763
|
+
);
|
|
1764
|
+
if (window.localStorage.getItem("surflion_registered") == "3") {
|
|
1765
|
+
return;
|
|
1766
|
+
} else {
|
|
1767
|
+
window.localStorage.setItem("surflion_registered", "0");
|
|
1768
|
+
const event = new Event("localStorageSurflionChange");
|
|
1769
|
+
window.dispatchEvent(event);
|
|
1770
|
+
setTimeout(()=>{
|
|
1771
|
+
SurfLion.sipRegister(SurfLion.sip_uri_,SurfLion.sip_password_,SurfLion.ws_uri_,false,SurfLion.ext_num,SurfLion.vDirection,SurfLion.floatWindowState,SurfLion.vPosition, SurfLion.positionX, SurfLion.positionY)
|
|
1772
|
+
},3000)
|
|
1773
|
+
}
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
if (event.data == "hangupother") {
|
|
1777
|
+
if(!document.hidden) {
|
|
1778
|
+
SurfLion.worker.port.postMessage("newconnect");
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
});
|
|
1783
|
+
window.addEventListener("unload", () => {
|
|
1784
|
+
if (window.localStorage.getItem("surflion_registered") == "3") {
|
|
1785
|
+
SurfLion.worker.port.postMessage("connectclose");
|
|
1786
|
+
} else {
|
|
1787
|
+
window.localStorage.setItem("surflion_registered", "0");
|
|
1788
|
+
const event = new Event("localStorageSurflionChange");
|
|
1789
|
+
window.dispatchEvent(event);
|
|
1790
|
+
SurfLion.worker.port.postMessage("normalclose");
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
});
|
|
1794
|
+
SurfLion.worker.port.start();
|
|
1795
|
+
},
|
|
1796
|
+
|
|
1797
|
+
visibilityListen: function(address) {
|
|
1798
|
+
console.log('address', address, !document.hidden);
|
|
1799
|
+
if (!document.hidden) {
|
|
1800
|
+
setTimeout(() => {
|
|
1801
|
+
const port = SurfLion.worker.port;
|
|
1802
|
+
if (window.localStorage.getItem("surflion_registered") != "3") {
|
|
1803
|
+
port.postMessage("newconnect");
|
|
1804
|
+
} else {
|
|
1805
|
+
setTimeout(()=>{
|
|
1806
|
+
SurfLion.phoneState = 3
|
|
1807
|
+
document.getElementById('float-virtually-pic').src = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAAXNSR0IArs4c6QAAB9lJREFUWEe1WHtwVFcZ/33n7mZDCSQqZEmwo60z2tq0omIhu1FwbAatPKotWKUzljq52bshEmawPKaUxBoFCoM1ZF+xr7GjU8WpFFFx6LTg3g3FgFJfWFqpTlskaUcoSdgku/fTs8nu3r3Z3bsNcv/aPed7/M73PodwFb/mYy2NRtLoAbicIA4CePo2z+LnVtGqZKlqqVTCqdCpUe1VBl+fw0v0igLqdHtmP9VBHQk7uVcb4L8YfG0+EEQ4rSi0JrgweKwYyKsLMKbdAQOPMfg9+UGSwcDDtZ7qLR3UYeSlsTPxle6vj62fNsiXbyfQPQCWM7OYJJOwn1xzvhaZ3z5s3ctrQWYmrVebxwYtAGEWgDGw+BOXV+iR+TsuThW0v9d/45hhfA+MFZOAEMXgcjdaQeYAbD3T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I6K3yxzKp8xPLP+XGCykeG10be0oEpsButc8V+anpxMup7KyGDjJd0UuLhiffe3XULx/mUHG5whYCFAtg2cQ8CZALwkST7jrZx0o5ZX/v/x9hX/ZIdDwAAAAAElFTkSuQmCC'
|
|
1808
|
+
},200)
|
|
1809
|
+
}
|
|
1810
|
+
}, 500);
|
|
1811
|
+
}
|
|
1812
|
+
},
|
|
1813
|
+
|
|
1814
|
+
closeShareWork: function() {
|
|
1815
|
+
SurfLion.worker.port.postMessage("close");
|
|
1816
|
+
}
|
|
1727
1817
|
}
|
|
1728
1818
|
|
|
1729
1819
|
export default SurfLion
|