zhyz-cloudrender-v5 1.0.6 → 1.0.9
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/cloudRender.es.js +6728 -575
- package/cloudRender.js +6728 -575
- package/cloudRender.umd.js +6728 -575
- package/package.json +3 -6
- package/tip.png +0 -0
- package/websocket-worker.js +98 -0
package/package.json
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zhyz-cloudrender-v5",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "cloudrender zhyz",
|
|
5
5
|
"main": "cloudRender.es.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
8
|
},
|
|
9
9
|
"author": "",
|
|
10
|
-
"license": "ISC"
|
|
11
|
-
|
|
12
|
-
"_from": "zhyz-cloudrender-v4@1.0.0",
|
|
13
|
-
"_resolved": "https://registry.npmmirror.com/zhyz-cloudrender-v4/-/zhyz-cloudrender-v4-1.3.87.tgz"
|
|
14
|
-
}
|
|
10
|
+
"license": "ISC"
|
|
11
|
+
}
|
package/tip.png
ADDED
|
Binary file
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// websocket-worker.js
|
|
2
|
+
let ws = null;
|
|
3
|
+
let time = 2000;
|
|
4
|
+
let replayCount = 0;
|
|
5
|
+
let maxReplayCount = 100;
|
|
6
|
+
let lockReconnect = false;
|
|
7
|
+
let replayFn = null;
|
|
8
|
+
|
|
9
|
+
// 监听主线程发来的消息
|
|
10
|
+
self.onmessage = function(e) {
|
|
11
|
+
const { type, data } = e.data;
|
|
12
|
+
|
|
13
|
+
switch(type) {
|
|
14
|
+
case 'init':
|
|
15
|
+
initWebSocket(data);
|
|
16
|
+
break;
|
|
17
|
+
case 'mouseEvent':
|
|
18
|
+
case 'keyEvent':
|
|
19
|
+
case 'wheelEvent':
|
|
20
|
+
sendMessage(type, data);
|
|
21
|
+
break;
|
|
22
|
+
case 'close':
|
|
23
|
+
closeWebSocket();
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function initWebSocket({ remoteIp, wsPort, streamId, isClient }) {
|
|
29
|
+
const ishttps = 'https:' === self.location.protocol;
|
|
30
|
+
const url = isClient
|
|
31
|
+
? `${ishttps ? 'wss' : 'ws'}://${remoteIp}:${wsPort}/websocket/request/`
|
|
32
|
+
: `${ishttps ? 'wss' : 'ws'}://${remoteIp}:${wsPort}/cloudRenderInput/proxy/${streamId}`;
|
|
33
|
+
|
|
34
|
+
ws = new WebSocket(url);
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
ws.onopen = function() {
|
|
38
|
+
console.log('WebSocket connection opened');
|
|
39
|
+
self.postMessage({ type: 'status', status: 'open' });
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
ws.onclose = function() {
|
|
43
|
+
console.log('WebSocket connection closed');
|
|
44
|
+
self.postMessage({ type: 'status', status: 'close' });
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
ws.onerror = function(error) {
|
|
48
|
+
console.log('websocket已断开', error);
|
|
49
|
+
|
|
50
|
+
if (lockReconnect) return;
|
|
51
|
+
|
|
52
|
+
if (replayFn) clearTimeout(replayFn);
|
|
53
|
+
lockReconnect = true;
|
|
54
|
+
|
|
55
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
56
|
+
ws.close();
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
replayFn = setTimeout(() => {
|
|
60
|
+
if (replayCount < maxReplayCount) {
|
|
61
|
+
self.postMessage({
|
|
62
|
+
type: 'status',
|
|
63
|
+
status: 'reconnecting',
|
|
64
|
+
count: replayCount,
|
|
65
|
+
nextTime: time
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
initWebSocket({ remoteIp, wsPort, streamId, isClient });
|
|
69
|
+
time = time * 2;
|
|
70
|
+
replayCount++;
|
|
71
|
+
}
|
|
72
|
+
}, time);
|
|
73
|
+
|
|
74
|
+
self.postMessage({ type: 'error', error: error.toString() });
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function sendMessage(eventType, data) {
|
|
79
|
+
if (ws && ws.readyState === WebSocket.OPEN) {
|
|
80
|
+
ws.send(JSON.stringify(data));
|
|
81
|
+
} else {
|
|
82
|
+
self.postMessage({
|
|
83
|
+
type: 'warning',
|
|
84
|
+
message: 'WebSocket未连接,消息未发送',
|
|
85
|
+
eventType,
|
|
86
|
+
data
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function closeWebSocket() {
|
|
92
|
+
if (ws) {
|
|
93
|
+
ws.close();
|
|
94
|
+
}
|
|
95
|
+
if (replayFn) {
|
|
96
|
+
clearTimeout(replayFn);
|
|
97
|
+
}
|
|
98
|
+
}
|