Skip to content

Commit 20c0607

Browse files
committed
Revert "feat: Replace socket.io-client (#99)"
This reverts commit ceb68a7.
1 parent 2ef5aaa commit 20c0607

14 files changed

+4726
-2778
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
lib/
2+
socket.io-websocket-only.js
23
doc/resource
34
coverage/
45
build/

.gitignore

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

package.json

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@
2323
"dist"
2424
],
2525
"devDependencies": {
26-
"@types/uuid": "^9.0.1",
27-
"cross-fetch": "^3.1.6",
26+
"@rollup/plugin-commonjs": "^25.0.0",
27+
"@types/uuid": "^9.0.0",
28+
"cross-fetch": "^3.1.5",
2829
"dayjs": "^1.11.7",
29-
"eslint": "^8.41.0",
30+
"eslint": "^8.33.0",
3031
"eslint-config-react-app": "^7.0.1",
31-
"jsdom": "^22.0.0",
32-
"lint-staged": "^13.2.2",
33-
"msw": "^1.2.1",
34-
"prettier": "^2.8.8",
32+
"jsdom": "^21.1.0",
33+
"lint-staged": "^13.1.0",
34+
"msw": "^1.0.0",
35+
"prettier": "^2.8.3",
3536
"typescript": "^5.0.4",
3637
"vite": "^4.3.8",
3738
"vite-plugin-dts": "^2.3.0",
38-
"vitest": "^0.31.1",
39-
"ws": "^8.13.0"
39+
"vitest": "^0.31.1"
4040
},
4141
"repository": {
4242
"type": "git",
@@ -54,19 +54,10 @@
5454
},
5555
"homepage": "http://ftrack.com",
5656
"dependencies": {
57-
"isomorphic-ws": "^5.0.0",
5857
"loglevel": "^1.8.1",
5958
"moment": "^2.29.4",
6059
"uuid": "^9.0.0"
6160
},
62-
"peerDependencies": {
63-
"ws": "^8.13.0"
64-
},
65-
"peerDependenciesMeta": {
66-
"ws": {
67-
"optional": true
68-
}
69-
},
7061
"lint-staged": {
7162
"*.js": "eslint --cache --fix",
7263
"*.{js,css,md,json,jsx,scss,yml}": "prettier --write"

source/event.ts

Lines changed: 4 additions & 4 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-
import { EventSource } from "./event_hub.js";
3+
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?: EventSource;
14+
source?: any;
1515
};
1616

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

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

4444
/** Add source to event data. */
45-
addSource(source: EventSource): void {
45+
addSource(source: any): void {
4646
this._data.source = source;
4747
}
4848
}

source/event_hub.ts

Lines changed: 18 additions & 8 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 io from "./simple_socketio.js";
4+
import * as io from "./socket.io-websocket-only.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 | null;
135+
private _socketIo: io.SocketIO | null;
136136

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

178178
/** Connect to the event server. */
179179
connect(): void {
180-
this._socketIo = io.connect(this._serverUrl, this._apiUser, this._apiKey);
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+
181191
this._socketIo.on("connect", this._onSocketConnected);
182192
this._socketIo.on("ftrack.event", this._handle);
183193
}
@@ -187,7 +197,7 @@ export class EventHub {
187197
* @return {Boolean}
188198
*/
189199
isConnected(): boolean {
190-
return this._socketIo?.isConnected() || false;
200+
return (this._socketIo && this._socketIo.socket.connected) || false;
191201
}
192202

193203
/**
@@ -237,7 +247,7 @@ export class EventHub {
237247
*
238248
* If timeout is non-zero, the promise will be rejected if the event is not
239249
* sent before the timeout is reached. Should be specified as seconds and
240-
* will default to 30.
250+
* will default to 10.
241251
*
242252
* @param {Event} event Event instance to publish
243253
* @param {Function} [options.onReply] Function to be invoked when a reply
@@ -358,7 +368,7 @@ export class EventHub {
358368
// Force reconnect socket if not automatically reconnected. This
359369
// happens for example in Adobe After Effects when rendering a
360370
// sequence takes longer than ~30s and the JS thread is blocked.
361-
this._socketIo.reconnect();
371+
this._socketIo.socket.reconnect();
362372
}
363373
} else {
364374
callback();

0 commit comments

Comments
 (0)