@digipair/skill-client-websocket 0.49.4 → 0.49.6

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/index.cjs.js CHANGED
@@ -17,6 +17,15 @@ function _extends() {
17
17
 
18
18
  const WS = typeof WebSocket === 'undefined' ? require('ws') : WebSocket;
19
19
  let ClientWebSocketService = class ClientWebSocketService {
20
+ async send(params, _pinsSettingsList, _context) {
21
+ const { websocket, message } = params;
22
+ return websocket.send(JSON.stringify(message));
23
+ }
24
+ async close(params, _pinsSettingsList, _context) {
25
+ const { websocket } = params;
26
+ websocket.cwssForceClose = true;
27
+ return websocket.close();
28
+ }
20
29
  async connect(params, _pinsSettingsList, context) {
21
30
  var _context_protected;
22
31
  const { url = '', message = [], open = [], close = [], error = [], retryInterval = 1000, maxRetries = 10 } = params;
@@ -32,15 +41,17 @@ let ClientWebSocketService = class ClientWebSocketService {
32
41
  await engine.executePinsList(open, _extends({}, context));
33
42
  };
34
43
  // Event onmessage: Réception d'un message
35
- this.ws.onmessage = async (notification)=>{
44
+ this.ws.onmessage = async (event)=>{
36
45
  await engine.executePinsList(message, _extends({}, context, {
37
- message: JSON.parse(notification)
46
+ message: JSON.parse(event.data)
38
47
  }));
39
48
  };
40
49
  // Event onclose: Déconnexion
41
50
  this.ws.onclose = async ()=>{
42
- await engine.executePinsList(close, _extends({}, context));
43
- this.reconnectWebSocket(params, _pinsSettingsList, context);
51
+ const reconnect = this.ws.cwssForceClose ? false : this.reconnectWebSocket(params, _pinsSettingsList, context);
52
+ if (!reconnect) {
53
+ await engine.executePinsList(close, _extends({}, context));
54
+ }
44
55
  };
45
56
  // Event onerror: Erreur
46
57
  this.ws.onerror = async (err)=>{
@@ -51,20 +62,25 @@ let ClientWebSocketService = class ClientWebSocketService {
51
62
  };
52
63
  return this.ws;
53
64
  }
54
- reconnectWebSocket(params, _pinsSettingsList, context) {
65
+ reconnectWebSocket(params, pinsSettingsList, context) {
55
66
  if (this.retryCount >= this.maxRetries) {
56
- return;
67
+ return false;
57
68
  }
58
69
  setTimeout(()=>{
59
70
  this.retryCount++;
60
71
  this.retryInterval *= 2; // Double l'intervalle entre les tentatives
61
- this.connect(params, _pinsSettingsList, context);
72
+ this.connect(params, pinsSettingsList, context);
62
73
  }, this.retryInterval);
74
+ return true;
63
75
  }
64
76
  constructor(){
65
77
  this.retryCount = 0;
66
78
  }
67
79
  };
68
80
  const connect = (params, pinsSettingsList, context)=>new ClientWebSocketService().connect(params, pinsSettingsList, context);
81
+ const send = (params, pinsSettingsList, context)=>new ClientWebSocketService().send(params, pinsSettingsList, context);
82
+ const close = (params, pinsSettingsList, context)=>new ClientWebSocketService().close(params, pinsSettingsList, context);
69
83
 
84
+ exports.close = close;
70
85
  exports.connect = connect;
86
+ exports.send = send;
package/index.esm.js CHANGED
@@ -23899,14 +23899,14 @@ function indent(str, spaces) {
23899
23899
  var match = parseIdentifier(input, i1, namePart) || namePart && parseAdditionalSymbol(input, i1) || maybeSpace && parseSpaces(input, i1);
23900
23900
  // match is required
23901
23901
  if (!match) {
23902
- return nextMatch = nextMatch1, tokens = tokens1, i = i1, {
23902
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, {
23903
23903
  v: nextMatch1
23904
23904
  };
23905
23905
  }
23906
23906
  var token = match.token, offset = match.offset;
23907
23907
  i1 += offset;
23908
23908
  if (token === " ") {
23909
- return nextMatch = nextMatch1, tokens = tokens1, i = i1, "continue";
23909
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23910
23910
  }
23911
23911
  tokens1 = _to_consumable_array$1(tokens1).concat([
23912
23912
  token
@@ -23925,7 +23925,7 @@ function indent(str, spaces) {
23925
23925
  if (contextKeys.some(function(el) {
23926
23926
  return el.startsWith(name);
23927
23927
  })) {
23928
- return nextMatch = nextMatch1, tokens = tokens1, i = i1, "continue";
23928
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23929
23929
  }
23930
23930
  if (dateTimeIdentifiers.some(function(el) {
23931
23931
  return el === name;
@@ -23944,9 +23944,9 @@ function indent(str, spaces) {
23944
23944
  if (dateTimeIdentifiers.some(function(el) {
23945
23945
  return el.startsWith(name);
23946
23946
  })) {
23947
- return nextMatch = nextMatch1, tokens = tokens1, i = i1, "continue";
23947
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, "continue";
23948
23948
  }
23949
- return nextMatch = nextMatch1, tokens = tokens1, i = i1, {
23949
+ return i = i1, nextMatch = nextMatch1, tokens = tokens1, {
23950
23950
  v: nextMatch1
23951
23951
  };
23952
23952
  };
@@ -27955,6 +27955,15 @@ const preparePinsSettings = async (settings, context)=>{
27955
27955
 
27956
27956
  const WS = typeof WebSocket === 'undefined' ? require('ws') : WebSocket;
27957
27957
  let ClientWebSocketService = class ClientWebSocketService {
27958
+ async send(params, _pinsSettingsList, _context) {
27959
+ const { websocket, message } = params;
27960
+ return websocket.send(JSON.stringify(message));
27961
+ }
27962
+ async close(params, _pinsSettingsList, _context) {
27963
+ const { websocket } = params;
27964
+ websocket.cwssForceClose = true;
27965
+ return websocket.close();
27966
+ }
27958
27967
  async connect(params, _pinsSettingsList, context) {
27959
27968
  var _context_protected;
27960
27969
  const { url = '', message = [], open = [], close = [], error = [], retryInterval = 1000, maxRetries = 10 } = params;
@@ -27970,15 +27979,17 @@ let ClientWebSocketService = class ClientWebSocketService {
27970
27979
  await executePinsList(open, _extends({}, context));
27971
27980
  };
27972
27981
  // Event onmessage: Réception d'un message
27973
- this.ws.onmessage = async (notification)=>{
27982
+ this.ws.onmessage = async (event)=>{
27974
27983
  await executePinsList(message, _extends({}, context, {
27975
- message: JSON.parse(notification)
27984
+ message: JSON.parse(event.data)
27976
27985
  }));
27977
27986
  };
27978
27987
  // Event onclose: Déconnexion
27979
27988
  this.ws.onclose = async ()=>{
27980
- await executePinsList(close, _extends({}, context));
27981
- this.reconnectWebSocket(params, _pinsSettingsList, context);
27989
+ const reconnect = this.ws.cwssForceClose ? false : this.reconnectWebSocket(params, _pinsSettingsList, context);
27990
+ if (!reconnect) {
27991
+ await executePinsList(close, _extends({}, context));
27992
+ }
27982
27993
  };
27983
27994
  // Event onerror: Erreur
27984
27995
  this.ws.onerror = async (err)=>{
@@ -27989,20 +28000,23 @@ let ClientWebSocketService = class ClientWebSocketService {
27989
28000
  };
27990
28001
  return this.ws;
27991
28002
  }
27992
- reconnectWebSocket(params, _pinsSettingsList, context) {
28003
+ reconnectWebSocket(params, pinsSettingsList, context) {
27993
28004
  if (this.retryCount >= this.maxRetries) {
27994
- return;
28005
+ return false;
27995
28006
  }
27996
28007
  setTimeout(()=>{
27997
28008
  this.retryCount++;
27998
28009
  this.retryInterval *= 2; // Double l'intervalle entre les tentatives
27999
- this.connect(params, _pinsSettingsList, context);
28010
+ this.connect(params, pinsSettingsList, context);
28000
28011
  }, this.retryInterval);
28012
+ return true;
28001
28013
  }
28002
28014
  constructor(){
28003
28015
  this.retryCount = 0;
28004
28016
  }
28005
28017
  };
28006
28018
  const connect = (params, pinsSettingsList, context)=>new ClientWebSocketService().connect(params, pinsSettingsList, context);
28019
+ const send = (params, pinsSettingsList, context)=>new ClientWebSocketService().send(params, pinsSettingsList, context);
28020
+ const close = (params, pinsSettingsList, context)=>new ClientWebSocketService().close(params, pinsSettingsList, context);
28007
28021
 
28008
- export { connect };
28022
+ export { close, connect, send };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digipair/skill-client-websocket",
3
- "version": "0.49.4",
3
+ "version": "0.49.6",
4
4
  "dependencies": {
5
5
  "ws": "^8.18.0"
6
6
  },
package/schema.fr.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "paths": {
11
11
  "/connect": {
12
12
  "post": {
13
- "tags": ["web", "service"],
13
+ "tags": ["service", "web", "spacial"],
14
14
  "summary": "Connexion Websocket",
15
15
  "parameters": [
16
16
  {
@@ -39,9 +39,7 @@
39
39
  "schema": {
40
40
  "type": "integer"
41
41
  }
42
- }
43
- ],
44
- "x-events": [
42
+ },
45
43
  {
46
44
  "name": "message",
47
45
  "summary": "Lors d'un message",
@@ -90,7 +88,53 @@
90
88
  }
91
89
  }
92
90
  }
93
- ]
91
+ ],
92
+ "x-events": []
93
+ }
94
+ },
95
+ "/send": {
96
+ "post": {
97
+ "tags": ["service", "web", "spacial"],
98
+ "summary": "Envoi de message",
99
+ "parameters": [
100
+ {
101
+ "name": "websocket",
102
+ "summary": "Websocket",
103
+ "required": true,
104
+ "description": "Websocket à utiliser",
105
+ "schema": {
106
+ "type": "object"
107
+ }
108
+ },
109
+ {
110
+ "name": "message",
111
+ "summary": "Message",
112
+ "required": true,
113
+ "description": "Message à envoyer",
114
+ "schema": {
115
+ "type": "object"
116
+ }
117
+ }
118
+ ],
119
+ "x-events": []
120
+ }
121
+ },
122
+ "/close": {
123
+ "post": {
124
+ "tags": ["service", "web", "spacial"],
125
+ "summary": "Fermeture Websocket",
126
+ "parameters": [
127
+ {
128
+ "name": "websocket",
129
+ "summary": "Websocket",
130
+ "required": true,
131
+ "description": "Websocket à fermer",
132
+ "schema": {
133
+ "type": "object"
134
+ }
135
+ }
136
+ ],
137
+ "x-events": []
94
138
  }
95
139
  }
96
140
  },
package/schema.json CHANGED
@@ -10,7 +10,7 @@
10
10
  "paths": {
11
11
  "/connect": {
12
12
  "post": {
13
- "tags": ["web", "service"],
13
+ "tags": ["service", "web", "spacial"],
14
14
  "summary": "Websocket server connection",
15
15
  "parameters": [
16
16
  {
@@ -39,9 +39,7 @@
39
39
  "schema": {
40
40
  "type": "integer"
41
41
  }
42
- }
43
- ],
44
- "x-events": [
42
+ },
45
43
  {
46
44
  "name": "message",
47
45
  "summary": "Upon a message",
@@ -92,6 +90,51 @@
92
90
  }
93
91
  ]
94
92
  }
93
+ },
94
+ "/send": {
95
+ "post": {
96
+ "tags": ["service", "web", "spacial"],
97
+ "summary": "Send message",
98
+ "parameters": [
99
+ {
100
+ "name": "websocket",
101
+ "summary": "Websocket",
102
+ "required": true,
103
+ "description": "Websocket to use",
104
+ "schema": {
105
+ "type": "object"
106
+ }
107
+ },
108
+ {
109
+ "name": "message",
110
+ "summary": "Message",
111
+ "required": true,
112
+ "description": "Message to send",
113
+ "schema": {
114
+ "type": "object"
115
+ }
116
+ }
117
+ ],
118
+ "x-events": []
119
+ }
120
+ },
121
+ "/close": {
122
+ "post": {
123
+ "tags": ["service", "web", "spacial"],
124
+ "summary": "Close Websocket",
125
+ "parameters": [
126
+ {
127
+ "name": "websocket",
128
+ "summary": "Websocket",
129
+ "required": true,
130
+ "description": "Websocket to close",
131
+ "schema": {
132
+ "type": "object"
133
+ }
134
+ }
135
+ ],
136
+ "x-events": []
137
+ }
95
138
  }
96
139
  },
97
140
  "components": {
@@ -1,2 +1,4 @@
1
1
  import { PinsSettings } from '@digipair/engine';
2
2
  export declare const connect: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
3
+ export declare const send: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;
4
+ export declare const close: (params: any, pinsSettingsList: PinsSettings[], context: any) => Promise<any>;