Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Create factory method to reuse connection if one already exists.
  • Loading branch information
gismya committed Apr 28, 2023
commit cc00cdfde97eb037297b8fc27dec08da974b7de1
3 changes: 1 addition & 2 deletions source/event_hub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,7 @@ export class EventHub {

/** Connect to the event server. */
connect(): void {
this._socketIo = new io(this._serverUrl, this._apiUser, this._apiKey);

this._socketIo = io.connect(this._serverUrl, this._apiUser, this._apiKey);
this._socketIo.on("connect", this._onSocketConnected);
this._socketIo.on("ftrack.event", this._handle);
}
Expand Down
33 changes: 32 additions & 1 deletion source/simple_socketio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ interface Payload {
* ```
*/
export default class SimpleSocketIOClient {
// Add a static instance variable
private static instances: Map<string, SimpleSocketIOClient> = new Map();
private webSocket: WebSocket;
private handlers: EventHandlers = {};
private reconnectTimeout: ReturnType<typeof setTimeout> | undefined;
Expand All @@ -65,14 +67,43 @@ export default class SimpleSocketIOClient {
reconnect: this.reconnect.bind(this),
transport: null,
};
/**
* Connect to a websocket server, or return the existing instance if one already exists.
* @param serverUrl - The server URL.
* @param apiUser - The API user.
* @param apiKey - The API key.
* @param heartbeatTimeoutMs - The heartbeat timeout in milliseconds. Defaults to 15000
*/
public static connect(
serverUrl: string,
apiUser: string,
apiKey: string,
heartbeatTimeoutMs: number = 15000
): SimpleSocketIOClient {
const key = `${serverUrl}_${apiUser}_${apiKey}`;
let instance = this.instances.get(key);

if (!instance) {
instance = new SimpleSocketIOClient(
serverUrl,
apiUser,
apiKey,
heartbeatTimeoutMs
);
this.instances.set(key, instance);
}

return instance;
}

/**
* Constructs a new SimpleSocketIOClient instance.
* @param serverUrl - The server URL.
* @param apiUser - The API user.
* @param apiKey - The API key.
* @param heartbeatTimeoutMs - The heartbeat timeout in milliseconds. Defaults to 15000
*/
constructor(
private constructor(
serverUrl: string,
apiUser: string,
apiKey: string,
Expand Down