Skip to content

feat: Replace socket.io-client #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 56 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
5b879be
Initial test
gismya Apr 18, 2023
24828db
Comments
gismya Apr 18, 2023
67f6ee3
Fetch error handling
gismya Apr 18, 2023
e83367d
Separate handle methods
gismya Apr 18, 2023
f82e685
Comments and code clarity
gismya Apr 18, 2023
ee02b81
Fetch timeout
gismya Apr 18, 2023
ca3335c
Add error event handler
gismya Apr 18, 2023
19e57b7
Change error handler to use handleClose
gismya Apr 18, 2023
176a79b
Added error packet type handler
gismya Apr 18, 2023
3144260
Setup connect event
gismya Apr 18, 2023
cd01dbb
accidentally removed the initialization
gismya Apr 18, 2023
698e989
Few tests, some working some not
gismya Apr 18, 2023
0d34757
rename
gismya Apr 18, 2023
296e94b
rename
gismya Apr 18, 2023
91c24d0
Optional chaining
gismya Apr 18, 2023
d20f3b3
Add https version of needed endpoint
gismya Apr 18, 2023
c91be00
Export packet_types for use in tests
gismya Apr 18, 2023
e6468ac
Round of test writing
gismya Apr 19, 2023
d6b1db0
DRYer code
gismya Apr 19, 2023
476cc63
Improve comments
gismya Apr 19, 2023
c834a91
Further test improvements
gismya Apr 19, 2023
b685485
A bunch more tests
gismya Apr 19, 2023
5c739b5
Remove non working attempt to setup a mock websocket server
gismya Apr 19, 2023
8da3169
Include external isomorphic-ws
gismya Apr 19, 2023
46a30bc
Move ws to peer dependencies
gismya Apr 19, 2023
0f4e38d
Add tsdoc comments
gismya Apr 19, 2023
9111ff6
DRYer msw server
gismya Apr 19, 2023
4b37c54
Start of event hub tests
gismya Apr 19, 2023
5cdbb8f
Temporarily re-add WS to regular dependencies
gismya Apr 19, 2023
b5aab44
Remove accidental test script
gismya Apr 19, 2023
840ca66
Move ws dependencies around
gismya Apr 19, 2023
1d4d94d
Remove commonjs build plugin
gismya Apr 19, 2023
4ba1185
peerDependenciesMeta
gismya Apr 19, 2023
64b72d5
Implement simple event queue
gismya Apr 19, 2023
3b6184b
Improve reconnection logic
gismya Apr 20, 2023
c6dd1ce
Update the reconnect documentation
gismya Apr 20, 2023
3220751
Add disconnect method
gismya Apr 20, 2023
353451b
Add off method
gismya Apr 20, 2023
fd7068e
Add tests for new functionality
gismya Apr 20, 2023
9ca5847
Slight readability changes
gismya Apr 21, 2023
7e82176
Reconnect if no heartbeat recieved. [wip]
gismya Apr 21, 2023
1ab12d8
Improved naming
gismya Apr 28, 2023
cae48f4
Cont. heartbeattimeout
gismya Apr 28, 2023
cc00cdf
Create factory method to reuse connection if one already exists.
gismya Apr 28, 2023
9bb84b0
Added option to force new instance
gismya Apr 28, 2023
04feff1
Reconnect WIP
gismya May 12, 2023
96ae6bf
chore(deps): update dependency prettier to v2.8.8 (#102)
renovate[bot] May 4, 2023
453ba50
chore(deps): update dependency vite-plugin-dts to v1.7.3 (#103)
renovate[bot] May 4, 2023
f733d34
Fixed the reconnect test
gismya May 12, 2023
230b9fc
Add a tsdoc
gismya May 12, 2023
7c9fff7
cleanup
gismya May 15, 2023
3bf55f4
Improve backwards compatibility
gismya May 19, 2023
3f4f3e8
Updated tests
gismya May 19, 2023
a7834e5
Change open to a getter
gismya May 19, 2023
3491353
Merge remote-tracking branch 'origin/main' into rewrite-socketio-client
gismya May 23, 2023
f9a0bd8
Upgrade
gismya May 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
lib/
socket.io-websocket-only.js
doc/resource
coverage/
build/
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ package.tgz
!.yarn/releases
!.yarn/sdks
!.yarn/versions
.DS_Store
27 changes: 18 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
"dist"
],
"devDependencies": {
"@rollup/plugin-commonjs": "^25.0.0",
"@types/uuid": "^9.0.0",
"cross-fetch": "^3.1.5",
"@types/uuid": "^9.0.1",
"cross-fetch": "^3.1.6",
"dayjs": "^1.11.7",
"eslint": "^8.33.0",
"eslint": "^8.41.0",
"eslint-config-react-app": "^7.0.1",
"jsdom": "^21.1.0",
"lint-staged": "^13.1.0",
"msw": "^1.0.0",
"prettier": "^2.8.3",
"jsdom": "^22.0.0",
"lint-staged": "^13.2.2",
"msw": "^1.2.1",
"prettier": "^2.8.8",
"typescript": "^5.0.4",
"vite": "^4.3.8",
"vite-plugin-dts": "^2.3.0",
"vitest": "^0.31.1"
"vitest": "^0.31.1",
"ws": "^8.13.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove unrelated dependency upgrades and make them in a separate PR

},
"repository": {
"type": "git",
Expand All @@ -54,10 +54,19 @@
},
"homepage": "http://ftrack.com",
"dependencies": {
"isomorphic-ws": "^5.0.0",
"loglevel": "^1.8.1",
"moment": "^2.29.4",
"uuid": "^9.0.0"
},
"peerDependencies": {
"ws": "^8.13.0"
},
"peerDependenciesMeta": {
"ws": {
"optional": true
}
},
"lint-staged": {
"*.js": "eslint --cache --fix",
"*.{js,css,md,json,jsx,scss,yml}": "prettier --write"
Expand Down
8 changes: 4 additions & 4 deletions source/event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// :copyright: Copyright (c) 2016 ftrack
import { v4 as uuidV4 } from "uuid";

import { EventSource } from "./event_hub.js";
/**
* ftrack API Event class.
*/
Expand All @@ -11,7 +11,7 @@ export class Event {
target: string;
inReplyToEvent: string | null;
id: string;
source?: any;
source?: EventSource;
};

/**
Expand All @@ -37,12 +37,12 @@ export class Event {
}

/** Return event data. */
getData(): { [key: string]: any } {
getData() {
return this._data;
}

/** Add source to event data. */
addSource(source: any): void {
addSource(source: EventSource): void {
this._data.source = source;
}
}
26 changes: 8 additions & 18 deletions source/event_hub.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// :copyright: Copyright (c) 2016 ftrack
import { v4 as uuidV4 } from "uuid";
import loglevel from "loglevel";
import * as io from "./socket.io-websocket-only.js";
import io from "./simple_socketio.js";
import { Event } from "./event.js";
import {
EventServerConnectionTimeoutError,
Expand Down Expand Up @@ -72,11 +72,11 @@ export type EventPayload =
| UpdateEventPayload;

export interface EventSource {
clientToken: string;
clientToken?: string;
applicationId: string;
user: {
username: string;
id: string;
id?: string;
};
id: string;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ export class EventHub {
};
private _unsentEvents: ConnectionCallback[];
private _subscribers: Subscriber[];
private _socketIo: io.SocketIO | null;
private _socketIo: io | null;

/**
* Construct EventHub instance with API credentials.
Expand Down Expand Up @@ -177,17 +177,7 @@ export class EventHub {

/** Connect to the event server. */
connect(): void {
this._socketIo = io.connect(this._serverUrl, {
"max reconnection attempts": Infinity,
"reconnection limit": 10000,
"reconnection delay": 5000,
transports: ["websocket"],
query: new URLSearchParams({
api_user: this._apiUser,
api_key: this._apiKey,
}).toString(),
});

this._socketIo = io.connect(this._serverUrl, this._apiUser, this._apiKey);
this._socketIo.on("connect", this._onSocketConnected);
this._socketIo.on("ftrack.event", this._handle);
}
Expand All @@ -197,7 +187,7 @@ export class EventHub {
* @return {Boolean}
*/
isConnected(): boolean {
return (this._socketIo && this._socketIo.socket.connected) || false;
return this._socketIo?.isConnected() || false;
}

/**
Expand Down Expand Up @@ -247,7 +237,7 @@ export class EventHub {
*
* If timeout is non-zero, the promise will be rejected if the event is not
* sent before the timeout is reached. Should be specified as seconds and
* will default to 10.
* will default to 30.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a breaking change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was simply my noticing that the comment was incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah okay. All good then!

*
* @param {Event} event Event instance to publish
* @param {Function} [options.onReply] Function to be invoked when a reply
Expand Down Expand Up @@ -368,7 +358,7 @@ export class EventHub {
// Force reconnect socket if not automatically reconnected. This
// happens for example in Adobe After Effects when rendering a
// sequence takes longer than ~30s and the JS thread is blocked.
this._socketIo.socket.reconnect();
this._socketIo.reconnect();
}
} else {
callback();
Expand Down
Loading