Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(private readonly baseUrl: string, public accessTokenStore: AccessTokenStore) {
super();
this.connectionState = ConnectionState.UNDEFINED;
this.logger = logdown('@wireapp/api-client/http/HttpClient', {
logger: console,
markdown: false,
});
this.requestQueue = new PriorityQueue({
maxRetries: 0,
retryDelay: TimeUtil.TimeInMillis.SECOND,
});
// Log all failing HTTP requests
axios.interceptors.response.use(undefined, (error: AxiosError) => {
let backendResponse = '';
if (error.response) {
try {
backendResponse = JSON.stringify(error.response.data);
} finally {
this.logger.error(
`HTTP Error (${error.response.status}) on '${error.response.config.url}': ${error.message} (${backendResponse})`,
);
}
}
(async () => {
const CONVERSATION_ID = program.conversationId || process.env.WIRE_CONVERSATION_ID;
const MESSAGE_TIMER = TimeUtil.TimeInMillis.SECOND * 5;
const login = {
clientType: ClientType.TEMPORARY,
email: process.env.WIRE_EMAIL,
password: process.env.WIRE_PASSWORD,
};
const backend = process.env.WIRE_BACKEND === 'staging' ? APIClient.BACKEND.STAGING : APIClient.BACKEND.PRODUCTION;
const engine = new FileEngine(path.join(__dirname, '.tmp', 'sender'));
await engine.init(undefined, {fileExtension: '.json'});
const apiClient = new APIClient({store: engine, urls: backend});
const account = new Account(apiClient);
await account.login(login);
await account.listen();
export class ReconnectingWebsocket {
private static readonly RECONNECTING_OPTIONS: Options = {
WebSocket: typeof window !== 'undefined' ? WebSocket : NodeWebSocket,
connectionTimeout: TimeUtil.TimeInMillis.SECOND * 4,
debug: false,
maxReconnectionDelay: TimeUtil.TimeInMillis.SECOND * 10,
maxRetries: Infinity,
minReconnectionDelay: TimeUtil.TimeInMillis.SECOND * 4,
reconnectionDelayGrowFactor: 1.3,
};
private readonly logger: logdown.Logger;
private socket?: RWS;
private pingerId?: NodeJS.Timeout;
private readonly PING_INTERVAL = TimeUtil.TimeInMillis.SECOND * 20;
private hasUnansweredPing: boolean;
private onOpen?: (event: Event) => void;
private onMessage?: (data: string) => void;
private onError?: (error: ErrorEvent) => void;
private onClose?: (event: CloseEvent) => void;
constructor(
private readonly onReconnect: () => Promise,
options: {
pingInterval?: number;
} = {},
) {
this.logger = logdown('@wireapp/api-client/tcp/ReconnectingWebsocket', {
logger: console,
markdown: false,
async function sendAndDeleteMessage() {
const deleteTextPayload = account.service.conversation.messageBuilder
.createText(CONVERSATION_ID, 'Delete me!')
.build();
const {id: messageId} = await account.service.conversation.send(deleteTextPayload);
const fiveSecondsInMillis = TimeUtil.TimeInMillis.SECOND * 5;
setTimeout(async () => {
await account.service.conversation.deleteMessageEveryone(CONVERSATION_ID, messageId);
}, fiveSecondsInMillis);
}
export enum WEBSOCKET_STATE {
CONNECTING = 0,
OPEN = 1,
CLOSING = 2,
CLOSED = 3,
}
export enum PingMessage {
PING = 'ping',
PONG = 'pong',
}
export class ReconnectingWebsocket {
private static readonly RECONNECTING_OPTIONS: Options = {
WebSocket: typeof window !== 'undefined' ? WebSocket : NodeWebSocket,
connectionTimeout: TimeUtil.TimeInMillis.SECOND * 4,
debug: false,
maxReconnectionDelay: TimeUtil.TimeInMillis.SECOND * 10,
maxRetries: Infinity,
minReconnectionDelay: TimeUtil.TimeInMillis.SECOND * 4,
reconnectionDelayGrowFactor: 1.3,
};
private readonly logger: logdown.Logger;
private socket?: RWS;
private pingerId?: NodeJS.Timeout;
private readonly PING_INTERVAL = TimeUtil.TimeInMillis.SECOND * 20;
private hasUnansweredPing: boolean;
private onOpen?: (event: Event) => void;
private onMessage?: (data: string) => void;
private onError?: (error: ErrorEvent) => void;