refactor
This commit is contained in:
parent
99dc38c6e0
commit
76d0a9cc5d
1 changed files with 8 additions and 4 deletions
|
@ -10,6 +10,8 @@ function urlQuery(obj: {}): string {
|
||||||
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>));
|
.reduce((a, [k, v]) => (a[k] = v, a), {} as Record<string, any>));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type AnyOf<T extends Record<any, any>> = T[keyof T];
|
||||||
|
|
||||||
type StreamEvents = {
|
type StreamEvents = {
|
||||||
_connected_: void;
|
_connected_: void;
|
||||||
_disconnected_: void;
|
_disconnected_: void;
|
||||||
|
@ -39,7 +41,9 @@ export default class Stream extends EventEmitter<StreamEvents> {
|
||||||
_t: Date.now(),
|
_t: Date.now(),
|
||||||
});
|
});
|
||||||
|
|
||||||
this.stream = new ReconnectingWebsocket(`${origin.replace('http://', 'ws://').replace('https://', 'wss://')}/streaming?${query}`, '', {
|
const wsOrigin = origin.replace('http://', 'ws://').replace('https://', 'wss://');
|
||||||
|
|
||||||
|
this.stream = new ReconnectingWebsocket(`${wsOrigin}/streaming?${query}`, '', {
|
||||||
minReconnectionDelay: 1, // https://github.com/pladaria/reconnecting-websocket/issues/91
|
minReconnectionDelay: 1, // https://github.com/pladaria/reconnecting-websocket/issues/91
|
||||||
WebSocket: options.WebSocket
|
WebSocket: options.WebSocket
|
||||||
});
|
});
|
||||||
|
@ -250,7 +254,7 @@ class Pool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class Connection<Channel extends Channels[keyof Channels] = any> extends EventEmitter<Channel['events']> {
|
abstract class Connection<Channel extends AnyOf<Channels> = any> extends EventEmitter<Channel['events']> {
|
||||||
public channel: string;
|
public channel: string;
|
||||||
protected stream: Stream;
|
protected stream: Stream;
|
||||||
public abstract id: string;
|
public abstract id: string;
|
||||||
|
@ -281,7 +285,7 @@ abstract class Connection<Channel extends Channels[keyof Channels] = any> extend
|
||||||
public abstract dispose(): void;
|
public abstract dispose(): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
class SharedConnection<Channel extends Channels[keyof Channels] = any> extends Connection<Channel> {
|
class SharedConnection<Channel extends AnyOf<Channels> = any> extends Connection<Channel> {
|
||||||
private pool: Pool;
|
private pool: Pool;
|
||||||
|
|
||||||
public get id(): string {
|
public get id(): string {
|
||||||
|
@ -303,7 +307,7 @@ class SharedConnection<Channel extends Channels[keyof Channels] = any> extends C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NonSharedConnection<Channel extends Channels[keyof Channels] = any> extends Connection<Channel> {
|
class NonSharedConnection<Channel extends AnyOf<Channels> = any> extends Connection<Channel> {
|
||||||
public id: string;
|
public id: string;
|
||||||
protected params: Channel['params'];
|
protected params: Channel['params'];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue