Skip to content

Commit 7fddeb6

Browse files
committed
Revert "fix: Revert "Replace socket.io-client" (#111)"
This reverts commit ca25de7.
1 parent c4eb920 commit 7fddeb6

14 files changed

+2413
-3944
lines changed

.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
lib/
2-
socket.io-websocket-only.js
32
doc/resource
43
coverage/
54
build/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,4 @@ package.tgz
5959
!.yarn/releases
6060
!.yarn/sdks
6161
!.yarn/versions
62+
.DS_Store

package.json

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"dist"
2626
],
2727
"devDependencies": {
28-
"@rollup/plugin-commonjs": "^25.0.2",
2928
"@types/uuid": "^9.0.2",
3029
"cross-fetch": "^3.1.6",
3130
"dayjs": "^1.11.8",
@@ -40,7 +39,8 @@
4039
"typescript": "^5.1.3",
4140
"vite": "^4.3.9",
4241
"vite-plugin-dts": "^2.3.0",
43-
"vitest": "^0.32.2"
42+
"vitest": "^0.32.2",
43+
"ws": "^8.13.0"
4444
},
4545
"repository": {
4646
"type": "git",
@@ -58,10 +58,19 @@
5858
},
5959
"homepage": "http://ftrack.com",
6060
"dependencies": {
61+
"isomorphic-ws": "^5.0.0",
6162
"loglevel": "^1.8.1",
6263
"moment": "^2.29.4",
6364
"uuid": "^9.0.0"
6465
},
66+
"peerDependencies": {
67+
"ws": "^8.13.0"
68+
},
69+
"peerDependenciesMeta": {
70+
"ws": {
71+
"optional": true
72+
}
73+
},
6574
"lint-staged": {
6675
"*.{js,ts}": "eslint --cache --fix --max-warnings=0",
6776
"*.{js,ts,css,md,json,jsx,scss,yml}": "prettier --write"

source/event.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// :copyright: Copyright (c) 2016 ftrack
22
import { v4 as uuidV4 } from "uuid";
3-
3+
import { EventSource } from "./event_hub.js";
44
/**
55
* ftrack API Event class.
66
*/
@@ -11,7 +11,7 @@ export class Event {
1111
target: string;
1212
inReplyToEvent: string | null;
1313
id: string;
14-
source?: any;
14+
source?: EventSource;
1515
};
1616

1717
/**
@@ -37,20 +37,20 @@ export class Event {
3737
}
3838

3939
/** Return event data. */
40-
getData(): { [key: string]: any } {
40+
getData() {
4141
return this._data;
4242
}
4343

4444
/** Add source to event data, keeping any already avalable source information */
45-
prepareSource(source: object): void {
45+
prepareSource(source: EventSource): void {
4646
this._data.source = {
4747
...source,
4848
...this._data.source,
4949
};
5050
}
5151

5252
/** Add source to event data, replacing any previous data. */
53-
addSource(source: any): void {
53+
addSource(source: EventSource): void {
5454
this._data.source = source;
5555
}
5656
}

source/event_hub.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// :copyright: Copyright (c) 2016 ftrack
22
import { v4 as uuidV4 } from "uuid";
33
import loglevel from "loglevel";
4-
import * as io from "./socket.io-websocket-only.js";
4+
import io from "./simple_socketio.js";
55
import { Event } from "./event.js";
66
import {
77
EventServerConnectionTimeoutError,
@@ -72,11 +72,11 @@ export type EventPayload =
7272
| UpdateEventPayload;
7373

7474
export interface EventSource {
75-
clientToken: string;
75+
clientToken?: string;
7676
applicationId: string;
7777
user: {
7878
username: string;
79-
id: string;
79+
id?: string;
8080
};
8181
id: string;
8282
}
@@ -132,7 +132,7 @@ export class EventHub {
132132
};
133133
private _unsentEvents: ConnectionCallback[];
134134
private _subscribers: Subscriber[];
135-
private _socketIo: io.SocketIO | null;
135+
private _socketIo: io | null;
136136

137137
/**
138138
* Construct EventHub instance with API credentials.
@@ -177,17 +177,7 @@ export class EventHub {
177177

178178
/** Connect to the event server. */
179179
connect(): void {
180-
this._socketIo = io.connect(this._serverUrl, {
181-
"max reconnection attempts": Infinity,
182-
"reconnection limit": 10000,
183-
"reconnection delay": 5000,
184-
transports: ["websocket"],
185-
query: new URLSearchParams({
186-
api_user: this._apiUser,
187-
api_key: this._apiKey,
188-
}).toString(),
189-
});
190-
180+
this._socketIo = io.connect(this._serverUrl, this._apiUser, this._apiKey);
191181
this._socketIo.on("connect", this._onSocketConnected);
192182
this._socketIo.on("ftrack.event", this._handle);
193183
}
@@ -197,7 +187,7 @@ export class EventHub {
197187
* @return {Boolean}
198188
*/
199189
isConnected(): boolean {
200-
return (this._socketIo && this._socketIo.socket.connected) || false;
190+
return this._socketIo?.isConnected() || false;
201191
}
202192

203193
/**
@@ -247,7 +237,7 @@ export class EventHub {
247237
*
248238
* If timeout is non-zero, the promise will be rejected if the event is not
249239
* sent before the timeout is reached. Should be specified as seconds and
250-
* will default to 10.
240+
* will default to 30.
251241
*
252242
* @param {Event} event Event instance to publish
253243
* @param {Function} [options.onReply] Function to be invoked when a reply
@@ -368,7 +358,7 @@ export class EventHub {
368358
// Force reconnect socket if not automatically reconnected. This
369359
// happens for example in Adobe After Effects when rendering a
370360
// sequence takes longer than ~30s and the JS thread is blocked.
371-
this._socketIo.socket.reconnect();
361+
this._socketIo.reconnect();
372362
}
373363
} else {
374364
callback();

0 commit comments

Comments
 (0)