@momo2555/koppeliajs 0.0.100 → 0.0.102
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.
|
@@ -33,11 +33,7 @@ export declare class KoppeliaWebsocket {
|
|
|
33
33
|
* @param callback
|
|
34
34
|
*/
|
|
35
35
|
onOpen(callback: () => void): void;
|
|
36
|
-
|
|
37
|
-
* Generate a new request Id
|
|
38
|
-
* @returns (string): a nex resuest id
|
|
39
|
-
*/
|
|
40
|
-
private _generateRequestId;
|
|
36
|
+
private _connectWebsocket;
|
|
41
37
|
/**
|
|
42
38
|
* Handle a websocket response
|
|
43
39
|
* - Execute a callback of a reception if a request was send before (by checking ongoing request)
|
|
@@ -14,7 +14,7 @@ export class KoppeliaWebsocket {
|
|
|
14
14
|
*/
|
|
15
15
|
constructor(websocketUrl, timeout = DEFAULT_WS_TIMEOUT) {
|
|
16
16
|
if (!import.meta.env.SSR) {
|
|
17
|
-
this.
|
|
17
|
+
this._connectWebsocket(websocketUrl);
|
|
18
18
|
console.log("Open new Koppelia websocket connection successfully with url ", websocketUrl);
|
|
19
19
|
this._setupEvents();
|
|
20
20
|
}
|
|
@@ -62,12 +62,8 @@ export class KoppeliaWebsocket {
|
|
|
62
62
|
this.openCallback = callback;
|
|
63
63
|
}
|
|
64
64
|
/* ------ PRIVATE ------ */
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* @returns (string): a nex resuest id
|
|
68
|
-
*/
|
|
69
|
-
_generateRequestId() {
|
|
70
|
-
return crypto.randomUUID();
|
|
65
|
+
_connectWebsocket(websockerUrl) {
|
|
66
|
+
this.socket = new WebSocket(websockerUrl);
|
|
71
67
|
}
|
|
72
68
|
/**
|
|
73
69
|
* Handle a websocket response
|
|
@@ -116,6 +112,11 @@ export class KoppeliaWebsocket {
|
|
|
116
112
|
let data = JSON.parse(e.data);
|
|
117
113
|
this._handleWebsocketResponse(data);
|
|
118
114
|
});
|
|
115
|
+
// handle connection close (if an error occure)
|
|
116
|
+
this.socket.onclose = (event) => {
|
|
117
|
+
console.log(`Connection closed ${event.reason}, code=${event.code}, retry onnection ...`);
|
|
118
|
+
setTimeout(this._connectWebsocket, 1000);
|
|
119
|
+
};
|
|
119
120
|
}
|
|
120
121
|
/**
|
|
121
122
|
* Timeout the request if there is no response
|
package/dist/scripts/message.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
1
2
|
export var PeerType;
|
|
2
3
|
(function (PeerType) {
|
|
3
4
|
PeerType["MONITOR"] = "monitor";
|
|
@@ -169,8 +170,7 @@ export class Message {
|
|
|
169
170
|
this.header.from = peerToIdentify;
|
|
170
171
|
}
|
|
171
172
|
generateRequestId() {
|
|
172
|
-
this.header.id =
|
|
173
|
-
;
|
|
173
|
+
this.header.id = uuidv4();
|
|
174
174
|
}
|
|
175
175
|
getRequestId() {
|
|
176
176
|
return this.header.id;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo2555/koppeliajs",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.102",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build && npm run package",
|
|
@@ -61,6 +61,7 @@
|
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"express": "^4.21.2",
|
|
64
|
-
"fs": "^0.0.1-security"
|
|
64
|
+
"fs": "^0.0.1-security",
|
|
65
|
+
"uuid": "^11.1.0"
|
|
65
66
|
}
|
|
66
|
-
}
|
|
67
|
+
}
|