@jay-framework/editor-client 0.6.3 → 0.6.5

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/dist/index.cjs CHANGED
@@ -28,8 +28,8 @@ class ConnectionManager {
28
28
  this.scanTimeout = options.scanTimeout || 5e3;
29
29
  this.retryAttempts = options.retryAttempts || 3;
30
30
  this.editorId = options.editorId || uuid.v4();
31
- this.autoReconnect = options.autoReconnect ?? true;
32
- this.reconnectDelay = options.reconnectDelay ?? 1e3;
31
+ this.autoReconnect = options.autoReconnect || true;
32
+ this.reconnectDelay = options.reconnectDelay || 1e3;
33
33
  }
34
34
  async connect() {
35
35
  if (this.connectionState === "connected" || this.isConnecting) {
@@ -118,6 +118,7 @@ class ConnectionManager {
118
118
  async discoverServer() {
119
119
  const [startPort, endPort] = this.portRange;
120
120
  const ports = Array.from({ length: endPort - startPort + 1 }, (_, i) => startPort + i);
121
+ const errors = [];
121
122
  for (let attempt = 0; attempt < this.retryAttempts; attempt++) {
122
123
  for (const port of ports) {
123
124
  try {
@@ -126,13 +127,17 @@ class ConnectionManager {
126
127
  return port;
127
128
  }
128
129
  } catch (error) {
130
+ errors.push(`tried port ${port} with error ${error?.message}`);
129
131
  }
130
132
  }
131
133
  if (attempt < this.retryAttempts - 1) {
132
134
  await new Promise((resolve) => setTimeout(resolve, 1e3));
133
135
  }
134
136
  }
135
- throw new Error(`No editor server found in port range ${startPort}-${endPort}`);
137
+ throw new Error(
138
+ `No editor server found in port range ${startPort}-${endPort}:
139
+ ${errors.join("\n")}`
140
+ );
136
141
  }
137
142
  async checkPort(port) {
138
143
  return new Promise((resolve, reject) => {
@@ -149,10 +154,17 @@ class ConnectionManager {
149
154
  }
150
155
  throw new Error(`HTTP ${response.status}`);
151
156
  }).then((data) => {
152
- if (data.status === "init" || data.id === this.editorId) {
157
+ if (data.status === "init" || data.id === this.editorId && data.status === "match") {
153
158
  resolve(data);
154
159
  } else {
155
- resolve(null);
160
+ if (data.id)
161
+ reject(
162
+ new Error(
163
+ `failed to match on editorId ${this.editorId} !== port's ${data.id}`
164
+ )
165
+ );
166
+ else
167
+ reject(new Error(`failed to match on editorId ${this.editorId}`));
156
168
  }
157
169
  }).catch((error) => {
158
170
  clearTimeout(timeout);
@@ -241,6 +253,9 @@ class EditorClient {
241
253
  async hasImage(params) {
242
254
  return this.connectionManager.sendMessage(params);
243
255
  }
256
+ async send(params) {
257
+ return this.connectionManager.sendMessage(params);
258
+ }
244
259
  // Get access to the underlying connection manager if needed
245
260
  getConnectionManager() {
246
261
  return this.connectionManager;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _jay_framework_editor_protocol from '@jay-framework/editor-protocol';
2
- import { ConnectionState, PublishMessage, SaveImageMessage, HasImageMessage, PublishResponse, SaveImageResponse, HasImageResponse, EditorProtocol } from '@jay-framework/editor-protocol';
2
+ import { ConnectionState, PublishMessage, SaveImageMessage, HasImageMessage, PublishResponse, SaveImageResponse, HasImageResponse, EditorProtocol, EditorProtocolMessageTypes, EditorProtocolResponseTypes } from '@jay-framework/editor-protocol';
3
3
 
4
4
  interface ConnectionManagerOptions {
5
5
  portRange?: [number, number];
@@ -52,6 +52,7 @@ declare class EditorClient implements EditorProtocol {
52
52
  publish(params: PublishMessage): Promise<PublishResponse>;
53
53
  saveImage(params: SaveImageMessage): Promise<SaveImageResponse>;
54
54
  hasImage(params: HasImageMessage): Promise<HasImageResponse>;
55
+ send(params: EditorProtocolMessageTypes): Promise<EditorProtocolResponseTypes>;
55
56
  getConnectionManager(): ConnectionManager;
56
57
  }
57
58
  declare function createEditorClient(options?: EditorClientOptions): EditorClient;
package/dist/index.js CHANGED
@@ -26,8 +26,8 @@ class ConnectionManager {
26
26
  this.scanTimeout = options.scanTimeout || 5e3;
27
27
  this.retryAttempts = options.retryAttempts || 3;
28
28
  this.editorId = options.editorId || v4();
29
- this.autoReconnect = options.autoReconnect ?? true;
30
- this.reconnectDelay = options.reconnectDelay ?? 1e3;
29
+ this.autoReconnect = options.autoReconnect || true;
30
+ this.reconnectDelay = options.reconnectDelay || 1e3;
31
31
  }
32
32
  async connect() {
33
33
  if (this.connectionState === "connected" || this.isConnecting) {
@@ -116,6 +116,7 @@ class ConnectionManager {
116
116
  async discoverServer() {
117
117
  const [startPort, endPort] = this.portRange;
118
118
  const ports = Array.from({ length: endPort - startPort + 1 }, (_, i) => startPort + i);
119
+ const errors = [];
119
120
  for (let attempt = 0; attempt < this.retryAttempts; attempt++) {
120
121
  for (const port of ports) {
121
122
  try {
@@ -124,13 +125,17 @@ class ConnectionManager {
124
125
  return port;
125
126
  }
126
127
  } catch (error) {
128
+ errors.push(`tried port ${port} with error ${error?.message}`);
127
129
  }
128
130
  }
129
131
  if (attempt < this.retryAttempts - 1) {
130
132
  await new Promise((resolve) => setTimeout(resolve, 1e3));
131
133
  }
132
134
  }
133
- throw new Error(`No editor server found in port range ${startPort}-${endPort}`);
135
+ throw new Error(
136
+ `No editor server found in port range ${startPort}-${endPort}:
137
+ ${errors.join("\n")}`
138
+ );
134
139
  }
135
140
  async checkPort(port) {
136
141
  return new Promise((resolve, reject) => {
@@ -147,10 +152,17 @@ class ConnectionManager {
147
152
  }
148
153
  throw new Error(`HTTP ${response.status}`);
149
154
  }).then((data) => {
150
- if (data.status === "init" || data.id === this.editorId) {
155
+ if (data.status === "init" || data.id === this.editorId && data.status === "match") {
151
156
  resolve(data);
152
157
  } else {
153
- resolve(null);
158
+ if (data.id)
159
+ reject(
160
+ new Error(
161
+ `failed to match on editorId ${this.editorId} !== port's ${data.id}`
162
+ )
163
+ );
164
+ else
165
+ reject(new Error(`failed to match on editorId ${this.editorId}`));
154
166
  }
155
167
  }).catch((error) => {
156
168
  clearTimeout(timeout);
@@ -239,6 +251,9 @@ class EditorClient {
239
251
  async hasImage(params) {
240
252
  return this.connectionManager.sendMessage(params);
241
253
  }
254
+ async send(params) {
255
+ return this.connectionManager.sendMessage(params);
256
+ }
242
257
  // Get access to the underlying connection manager if needed
243
258
  getConnectionManager() {
244
259
  return this.connectionManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/editor-client",
3
- "version": "0.6.3",
3
+ "version": "0.6.5",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -27,14 +27,14 @@
27
27
  "test:watch": "vitest"
28
28
  },
29
29
  "dependencies": {
30
- "@jay-framework/editor-protocol": "^0.6.3",
30
+ "@jay-framework/editor-protocol": "^0.6.5",
31
31
  "get-port": "^7.0.0",
32
32
  "socket.io-client": "^4.7.4",
33
33
  "uuid": "^9.0.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@jay-framework/dev-environment": "^0.6.3",
37
- "@jay-framework/jay-cli": "^0.6.3",
36
+ "@jay-framework/dev-environment": "^0.6.5",
37
+ "@jay-framework/jay-cli": "^0.6.5",
38
38
  "@types/node": "^22.15.21",
39
39
  "@types/uuid": "^9.0.7",
40
40
  "rimraf": "^5.0.5",