zhyz-cloudrender-v5 1.0.8 → 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 CHANGED
@@ -28819,6 +28819,7 @@ class CloudRender extends DefaultApi {
28819
28819
  this.p2pWs = null;
28820
28820
  this.renderWidth = 0;
28821
28821
  this.renderHeight = 0;
28822
+ this.isWss = url.includes("https");
28822
28823
  this.webscoketCallback = () => {};
28823
28824
  const init = (async () => {
28824
28825
  initBaseInfo({
@@ -29119,7 +29120,7 @@ class CloudRender extends DefaultApi {
29119
29120
  myhostname: myhostname,
29120
29121
  protooPort: protooPort,
29121
29122
  displayName: this.username,
29122
- ishttps: this.url.includes("https"),
29123
+ ishttps: this.isWss,
29123
29124
  setRenderStatus: this.setRenderStatus
29124
29125
  });
29125
29126
  this.room = room;
@@ -29151,7 +29152,7 @@ class CloudRender extends DefaultApi {
29151
29152
  console.log("客户端渲染");
29152
29153
  createWebGLContext(ele, this.renderWidth, this.renderHeight);
29153
29154
  }
29154
- let socketUrl1 = `ws://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29155
+ let socketUrl1 = `${isWss ? 'wss' : 'ws'}://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29155
29156
  let webscoket1 = new WebSocket(socketUrl1);
29156
29157
  this.serveScoket = webscoket1;
29157
29158
  webscoket1.onmessage = info => {
package/cloudRender.js CHANGED
@@ -28824,6 +28824,7 @@ Expected function or array of functions, received type ${typeof value}.`
28824
28824
  this.p2pWs = null;
28825
28825
  this.renderWidth = 0;
28826
28826
  this.renderHeight = 0;
28827
+ this.isWss = url.includes("https");
28827
28828
  this.webscoketCallback = () => {};
28828
28829
  const init = (async () => {
28829
28830
  initBaseInfo({
@@ -29124,7 +29125,7 @@ Expected function or array of functions, received type ${typeof value}.`
29124
29125
  myhostname: myhostname,
29125
29126
  protooPort: protooPort,
29126
29127
  displayName: this.username,
29127
- ishttps: this.url.includes("https"),
29128
+ ishttps: this.isWss,
29128
29129
  setRenderStatus: this.setRenderStatus
29129
29130
  });
29130
29131
  this.room = room;
@@ -29156,7 +29157,7 @@ Expected function or array of functions, received type ${typeof value}.`
29156
29157
  console.log("客户端渲染");
29157
29158
  createWebGLContext(ele, this.renderWidth, this.renderHeight);
29158
29159
  }
29159
- let socketUrl1 = `ws://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29160
+ let socketUrl1 = `${isWss ? 'wss' : 'ws'}://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29160
29161
  let webscoket1 = new WebSocket(socketUrl1);
29161
29162
  this.serveScoket = webscoket1;
29162
29163
  webscoket1.onmessage = info => {
@@ -28825,6 +28825,7 @@ Expected function or array of functions, received type ${typeof value}.`
28825
28825
  this.p2pWs = null;
28826
28826
  this.renderWidth = 0;
28827
28827
  this.renderHeight = 0;
28828
+ this.isWss = url.includes("https");
28828
28829
  this.webscoketCallback = () => {};
28829
28830
  const init = (async () => {
28830
28831
  initBaseInfo({
@@ -29125,7 +29126,7 @@ Expected function or array of functions, received type ${typeof value}.`
29125
29126
  myhostname: myhostname,
29126
29127
  protooPort: protooPort,
29127
29128
  displayName: this.username,
29128
- ishttps: this.url.includes("https"),
29129
+ ishttps: this.isWss,
29129
29130
  setRenderStatus: this.setRenderStatus
29130
29131
  });
29131
29132
  this.room = room;
@@ -29157,7 +29158,7 @@ Expected function or array of functions, received type ${typeof value}.`
29157
29158
  console.log("客户端渲染");
29158
29159
  createWebGLContext(ele, this.renderWidth, this.renderHeight);
29159
29160
  }
29160
- let socketUrl1 = `ws://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29161
+ let socketUrl1 = `${isWss ? 'wss' : 'ws'}://${this.url.split("://")[1]}websocket/${this.appliId + v4$2()}`;
29161
29162
  let webscoket1 = new WebSocket(socketUrl1);
29162
29163
  this.serveScoket = webscoket1;
29163
29164
  webscoket1.onmessage = info => {
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "zhyz-cloudrender-v5",
3
- "version": "1.0.8",
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
- "__npminstall_done": true,
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
+ }