@momo2555/koppeliajs 0.0.101 → 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,6 +33,7 @@ export declare class KoppeliaWebsocket {
33
33
  * @param callback
34
34
  */
35
35
  onOpen(callback: () => void): void;
36
+ private _connectWebsocket;
36
37
  /**
37
38
  * Handle a websocket response
38
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.socket = new WebSocket(websocketUrl);
17
+ this._connectWebsocket(websocketUrl);
18
18
  console.log("Open new Koppelia websocket connection successfully with url ", websocketUrl);
19
19
  this._setupEvents();
20
20
  }
@@ -62,6 +62,9 @@ export class KoppeliaWebsocket {
62
62
  this.openCallback = callback;
63
63
  }
64
64
  /* ------ PRIVATE ------ */
65
+ _connectWebsocket(websockerUrl) {
66
+ this.socket = new WebSocket(websockerUrl);
67
+ }
65
68
  /**
66
69
  * Handle a websocket response
67
70
  * - Execute a callback of a reception if a request was send before (by checking ongoing request)
@@ -109,6 +112,11 @@ export class KoppeliaWebsocket {
109
112
  let data = JSON.parse(e.data);
110
113
  this._handleWebsocketResponse(data);
111
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
+ };
112
120
  }
113
121
  /**
114
122
  * Timeout the request if there is no response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@momo2555/koppeliajs",
3
- "version": "0.0.101",
3
+ "version": "0.0.102",
4
4
  "scripts": {
5
5
  "dev": "vite dev",
6
6
  "build": "vite build && npm run package",