Skip to content
This repository has been archived by the owner on Jan 24, 2024. It is now read-only.

Adds retry strategy #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 33 additions & 33 deletions build/Channel.d.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
import { UEventCallback } from './types';
import { SFSocket } from './SFSocket';
import { ConnectionManagerEventMap } from './connection/ConnectionManager';
export declare enum ChannelStatus {
CLOSED = "closed",
JOINING = "joining",
JOINED = "joined",
LEAVING = "leaving",
ERROR = "error"
}
export default class Channel {
private readonly selfName;
private channelStatus;
private socket;
private cMgr;
private enabled;
constructor(name: string, socket: SFSocket);
get status(): ChannelStatus;
get name(): string;
get isActive(): boolean;
join(): void;
subscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>): void;
unsubscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>): void;
leave(): void;
private onConnect;
private onDisconnect;
private onJoin;
private onLeft;
private onJoinFailed;
private sendJoinCommand;
private startListening;
private stopListening;
}
import { UEventCallback } from './types';
import { SFSocket } from './SFSocket';
import { ConnectionManagerEventMap } from './connection/ConnectionManager';
export declare enum ChannelStatus {
CLOSED = "closed",
JOINING = "joining",
JOINED = "joined",
LEAVING = "leaving",
ERROR = "error"
}
export default class Channel {
private readonly selfName;
private channelStatus;
private socket;
private cMgr;
private enabled;
constructor(name: string, socket: SFSocket);
get status(): ChannelStatus;
get name(): string;
get isActive(): boolean;
join(): void;
subscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>): void;
unsubscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>): void;
leave(): void;
private onConnect;
private onDisconnect;
private onJoin;
private onLeft;
private onJoinFailed;
private sendJoinCommand;
private startListening;
private stopListening;
}
//# sourceMappingURL=Channel.d.ts.map
112 changes: 57 additions & 55 deletions build/SFSocket.d.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,58 @@
import { UEventCallback } from './types';
import Channel from './Channel';
import ConnectionManager, { ConnectionManagerEventMap } from './connection/ConnectionManager';
export interface IChannels {
[name: string]: Channel;
}
export declare enum SFSocketEventType {
CONNECTING = "sfSocket:connecting",
MESSAGE = "sfSocket:message",
CHANNEL_JOINED = "channel_joined",
CHANNEL_JOIN_FAILED = "channel_join_failed",
CHANNEL_LEFT = "channel_left",
CHANNEL_LEAVE_FAILED = "channel_leave_failed",
ERROR = "sfSocket:error",
CLOSED = "sfSocket:closed"
}
export interface ISFSocketConfig {
host: string;
port: string | number;
path: string;
queryParams?: {
[key: string]: string;
};
unavailableTimeout?: number;
useTLS?: boolean;
retryTimeout?: number;
}
export interface ISFSocketEvent {
type: SFSocketEventType;
data: string | null;
error: string | null;
context?: {
channel?: string;
code?: string | number;
} | null;
}
export declare class SFSocket {
static instances: SFSocket[];
static isReady: boolean;
static ready(): void;
private config;
private channels;
cMgr: ConnectionManager;
constructor(options?: ISFSocketConfig);
connect(): void;
disconnect(): void;
sendCommand(cmdName: string, data: any): boolean;
joinChannelList(channelsNames: string[]): void;
leaveChannelList(channelNames: string[]): void;
subscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>, channel?: string): ConnectionManager;
unsubscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>, channel?: string): ConnectionManager;
joinChannel(chanelName: string, dontJoin?: boolean): Channel;
leaveChannel(chanelName: string): Channel;
getChannel(name: string): Channel;
}
import { UEventCallback } from './types';
import Channel from './Channel';
import ConnectionManager, { ConnectionManagerEventMap } from './connection/ConnectionManager';
import { RetryStrategy } from './connection/types';
export interface IChannels {
[name: string]: Channel;
}
export declare enum SFSocketEventType {
CONNECTING = "sfSocket:connecting",
MESSAGE = "sfSocket:message",
CHANNEL_JOINED = "channel_joined",
CHANNEL_JOIN_FAILED = "channel_join_failed",
CHANNEL_LEFT = "channel_left",
CHANNEL_LEAVE_FAILED = "channel_leave_failed",
ERROR = "sfSocket:error",
CLOSED = "sfSocket:closed"
}
export interface ISFSocketConfig {
host: string;
port: string | number;
path: string;
queryParams?: {
[key: string]: string;
};
unavailableTimeout?: number;
useTLS?: boolean;
retryTimeout?: number;
retryStrategy?: RetryStrategy;
}
export interface ISFSocketEvent {
type: SFSocketEventType;
data: string | null;
error: string | null;
context?: {
channel?: string;
code?: string | number;
} | null;
}
export declare class SFSocket {
static instances: SFSocket[];
static isReady: boolean;
static ready(): void;
private config;
private channels;
cMgr: ConnectionManager;
constructor(options?: ISFSocketConfig);
connect(): void;
disconnect(): void;
sendCommand(cmdName: string, data: any): boolean;
joinChannelList(channelsNames: string[]): void;
leaveChannelList(channelNames: string[]): void;
subscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>, channel?: string): ConnectionManager;
unsubscribe<K extends keyof ConnectionManagerEventMap>(eventName: K, callback: UEventCallback<ConnectionManagerEventMap, K>, channel?: string): ConnectionManager;
joinChannel(chanelName: string, dontJoin?: boolean): Channel;
leaveChannel(chanelName: string): Channel;
getChannel(name: string): Channel;
}
//# sourceMappingURL=SFSocket.d.ts.map
2 changes: 1 addition & 1 deletion build/SFSocket.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions build/autobind.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export declare function autobind(target: any, key: string | symbol, descriptor: PropertyDescriptor): {
configurable: boolean;
get(): any;
set(value: any): void;
};
export declare function autobind(target: any, key: string | symbol, descriptor: PropertyDescriptor): {
configurable: boolean;
get(): any;
set(value: any): void;
};
//# sourceMappingURL=autobind.d.ts.map
68 changes: 34 additions & 34 deletions build/connection/Connection.d.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
import EventsDispatcher from '../eventdispatcher/EventsDispatcher';
import { ISFSocketEvent } from '../SFSocket';
import TransportConnection from '../transport/TransportConnection';
import { NamesDict } from '../eventdispatcher/events';
export interface ConnectionEventMap {
[NamesDict.CLOSED]: ISFSocketEvent;
[NamesDict.ERROR]: ISFSocketEvent;
[NamesDict.MESSAGE]: ISFSocketEvent;
[NamesDict.CHANNEL_JOIN_FAILED]: string[];
[NamesDict.CHANNEL_JOINED]: string[];
[NamesDict.CHANNEL_LEFT]: string[];
}
export declare enum ConnectionCommands {
JOIN = "join",
LEAVE = "leave"
}
export declare const SystemCommands: Set<string>;
export interface EventWithCode {
context: {
code: string;
};
}
export default class Connection extends EventsDispatcher<ConnectionEventMap> {
id: string;
transport: TransportConnection | null;
constructor(id: string, transport: TransportConnection);
send(data: string): boolean;
sendCommand(commandName: string, payload: any): boolean;
sendJoin(channels: string[]): void;
sendLeave(channels: string[]): void;
close(): void;
private bindListeners;
private handleCloseEvent;
}
import EventsDispatcher from '../eventdispatcher/EventsDispatcher';
import { ISFSocketEvent } from '../SFSocket';
import TransportConnection from '../transport/TransportConnection';
import { NamesDict } from '../eventdispatcher/events';
export interface ConnectionEventMap {
[NamesDict.CLOSED]: ISFSocketEvent;
[NamesDict.ERROR]: ISFSocketEvent;
[NamesDict.MESSAGE]: ISFSocketEvent;
[NamesDict.CHANNEL_JOIN_FAILED]: string[];
[NamesDict.CHANNEL_JOINED]: string[];
[NamesDict.CHANNEL_LEFT]: string[];
}
export declare enum ConnectionCommands {
JOIN = "join",
LEAVE = "leave"
}
export declare const SystemCommands: Set<string>;
export interface EventWithCode {
context: {
code: string;
};
}
export default class Connection extends EventsDispatcher<ConnectionEventMap> {
id: string;
transport: TransportConnection | null;
constructor(id: string, transport: TransportConnection);
send(data: string): boolean;
sendCommand(commandName: string, payload: any): boolean;
sendJoin(channels: string[]): void;
sendLeave(channels: string[]): void;
close(): void;
private bindListeners;
private handleCloseEvent;
}
//# sourceMappingURL=Connection.d.ts.map
97 changes: 49 additions & 48 deletions build/connection/ConnectionManager.d.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,50 @@
import EventsDispatcher from '../eventdispatcher/EventsDispatcher';
import { ISFSocketConfig, ISFSocketEvent } from '../SFSocket';
import { NamesDict } from '../eventdispatcher/events';
export declare type ConnectionState = 'initialized' | NamesDict.UNAVAILABLE | NamesDict.CONNECTING | NamesDict.CONNECTED | NamesDict.DISCONNECTED;
export interface ConnectionManagerEventMap {
[NamesDict.CONNECTING]: ISFSocketEvent;
[NamesDict.DISCONNECTED]: undefined;
[NamesDict.CONNECTED]: undefined;
[NamesDict.CHANNEL_JOINED]: string[];
[NamesDict.CHANNEL_JOIN_FAILED]: string[];
[NamesDict.CHANNEL_LEFT]: string[];
[NamesDict.ERROR]: ISFSocketEvent;
[NamesDict.MESSAGE]: ISFSocketEvent;
[NamesDict.CLOSED]: ISFSocketEvent;
[NamesDict.UNAVAILABLE]: undefined;
}
export default class ConnectionManager extends EventsDispatcher<ConnectionManagerEventMap> {
private options;
state: ConnectionState;
private connection;
private unavailableTimer;
private retryTimer;
private transport;
private runner;
private errorCallbacks;
private connectionCallbacks;
constructor(options: ISFSocketConfig);
connect(): void;
send(data: string): boolean;
sendCommand(name: string, data: any): boolean;
sendJoin(channels: string[]): boolean;
sendLeave(channels: string[]): boolean;
disconnect(): void;
isConnected(): boolean;
private startConnecting;
private abortConnecting;
private disconnectInternally;
private retryIn;
private clearRetryTimer;
private setUnavailableTimer;
private clearUnavailableTimer;
private buildConnectionCallbacks;
private buildErrorCallbacks;
private setConnection;
private abandonConnection;
private updateState;
private shouldRetry;
}
import EventsDispatcher from '../eventdispatcher/EventsDispatcher';
import { ISFSocketConfig, ISFSocketEvent } from '../SFSocket';
import { NamesDict } from '../eventdispatcher/events';
export declare type ConnectionState = 'initialized' | NamesDict.UNAVAILABLE | NamesDict.CONNECTING | NamesDict.CONNECTED | NamesDict.DISCONNECTED;
export interface ConnectionManagerEventMap {
[NamesDict.CONNECTING]: ISFSocketEvent;
[NamesDict.DISCONNECTED]: undefined;
[NamesDict.CONNECTED]: undefined;
[NamesDict.CHANNEL_JOINED]: string[];
[NamesDict.CHANNEL_JOIN_FAILED]: string[];
[NamesDict.CHANNEL_LEFT]: string[];
[NamesDict.ERROR]: ISFSocketEvent;
[NamesDict.MESSAGE]: ISFSocketEvent;
[NamesDict.CLOSED]: ISFSocketEvent;
[NamesDict.UNAVAILABLE]: undefined;
}
export default class ConnectionManager extends EventsDispatcher<ConnectionManagerEventMap> {
private options;
state: ConnectionState;
private connection;
private unavailableTimer;
private retryTimer;
private retryState;
private transport;
private runner;
private errorCallbacks;
private connectionCallbacks;
constructor(options: ISFSocketConfig);
connect(): void;
send(data: string): boolean;
sendCommand(name: string, data: any): boolean;
sendJoin(channels: string[]): boolean;
sendLeave(channels: string[]): boolean;
disconnect(): void;
isConnected(): boolean;
private startConnecting;
private abortConnecting;
private disconnectInternally;
private retryIn;
private clearRetryTimer;
private setUnavailableTimer;
private clearUnavailableTimer;
private buildConnectionCallbacks;
private buildErrorCallbacks;
private setConnection;
private abandonConnection;
private updateState;
private shouldRetry;
}
//# sourceMappingURL=ConnectionManager.d.ts.map
Loading