@jay-framework/editor-client 0.6.2 → 0.6.4

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,15 @@ 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(`No editor server found in port range ${startPort}-${endPort}:
138
+ ${errors.join("\n")}`);
136
139
  }
137
140
  async checkPort(port) {
138
141
  return new Promise((resolve, reject) => {
@@ -149,10 +152,13 @@ class ConnectionManager {
149
152
  }
150
153
  throw new Error(`HTTP ${response.status}`);
151
154
  }).then((data) => {
152
- if (data.status === "init" || data.id === this.editorId) {
155
+ if (data.status === "init" || data.id === this.editorId && data.status === "match") {
153
156
  resolve(data);
154
157
  } else {
155
- resolve(null);
158
+ if (data.id)
159
+ reject(new Error(`failed to match on editorId ${this.editorId} !== port's ${data.id}`));
160
+ else
161
+ reject(new Error(`failed to match on editorId ${this.editorId}`));
156
162
  }
157
163
  }).catch((error) => {
158
164
  clearTimeout(timeout);
@@ -241,6 +247,9 @@ class EditorClient {
241
247
  async hasImage(params) {
242
248
  return this.connectionManager.sendMessage(params);
243
249
  }
250
+ async send(params) {
251
+ return this.connectionManager.sendMessage(params);
252
+ }
244
253
  // Get access to the underlying connection manager if needed
245
254
  getConnectionManager() {
246
255
  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,15 @@ 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(`No editor server found in port range ${startPort}-${endPort}:
136
+ ${errors.join("\n")}`);
134
137
  }
135
138
  async checkPort(port) {
136
139
  return new Promise((resolve, reject) => {
@@ -147,10 +150,13 @@ class ConnectionManager {
147
150
  }
148
151
  throw new Error(`HTTP ${response.status}`);
149
152
  }).then((data) => {
150
- if (data.status === "init" || data.id === this.editorId) {
153
+ if (data.status === "init" || data.id === this.editorId && data.status === "match") {
151
154
  resolve(data);
152
155
  } else {
153
- resolve(null);
156
+ if (data.id)
157
+ reject(new Error(`failed to match on editorId ${this.editorId} !== port's ${data.id}`));
158
+ else
159
+ reject(new Error(`failed to match on editorId ${this.editorId}`));
154
160
  }
155
161
  }).catch((error) => {
156
162
  clearTimeout(timeout);
@@ -239,6 +245,9 @@ class EditorClient {
239
245
  async hasImage(params) {
240
246
  return this.connectionManager.sendMessage(params);
241
247
  }
248
+ async send(params) {
249
+ return this.connectionManager.sendMessage(params);
250
+ }
242
251
  // Get access to the underlying connection manager if needed
243
252
  getConnectionManager() {
244
253
  return this.connectionManager;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jay-framework/editor-client",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
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.2",
30
+ "@jay-framework/editor-protocol": "^0.6.4",
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.2",
37
- "@jay-framework/jay-cli": "^0.6.2",
36
+ "@jay-framework/dev-environment": "^0.6.4",
37
+ "@jay-framework/jay-cli": "^0.6.4",
38
38
  "@types/node": "^22.15.21",
39
39
  "@types/uuid": "^9.0.7",
40
40
  "rimraf": "^5.0.5",