bulbul-chat
Advanced tools
Comparing version 2.8.0 to 2.8.1
@@ -90,4 +90,7 @@ export declare type ChatMessageType = 'plaintext' | 'image' | 'video' | 'audio' | 'document' | 'location' | 'contact' | 'file' | 'url' | 'card'; | ||
private currentUser?; | ||
private isDisconnected; | ||
private lastJoinedChannelId; | ||
constructor(endpoint: string, token: string); | ||
listen(): void; | ||
listenToAppEvents(): void; | ||
connect(): void; | ||
@@ -94,0 +97,0 @@ joinChannel(channelId: string): void; |
@@ -88,2 +88,4 @@ "use strict"; | ||
this.users = {}; | ||
this.isDisconnected = false; | ||
this.lastJoinedChannelId = null; | ||
this.endpoint = endpoint; | ||
@@ -94,2 +96,3 @@ this.token = token; | ||
autoConnect: false, | ||
forceNew: true, | ||
transports: ['websocket'], | ||
@@ -103,4 +106,13 @@ query: { | ||
var _this = this; | ||
this.listenToAppEvents(); | ||
this.socket.on('connect', function () { | ||
// ... | ||
if (_this.isDisconnected) { | ||
setTimeout(function () { | ||
if (_this.lastJoinedChannelId) { | ||
_this.joinChannel(_this.lastJoinedChannelId); | ||
} | ||
}, 5000); | ||
_this.isDisconnected = false; | ||
} | ||
_this.eventRegistry.emit('connect', {}); | ||
@@ -112,4 +124,28 @@ }); | ||
this.socket.on('disconnect', function (data) { | ||
_this.isDisconnected = true; | ||
}); | ||
// Listen on IO events | ||
this.socket.io.on('error', function (e) { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect', function (attempt) { | ||
setTimeout(function () { return _this.eventRegistry.emit('reconnect', {}); }, 3000); | ||
}); | ||
this.socket.io.on('reconnect_attempt', function (attempt) { | ||
if (attempt === MAX_RETRY_ATTEMPS) { | ||
_this.eventRegistry.emit('maxRetryAttemptsReached', {}); | ||
} | ||
}); | ||
this.socket.io.on('reconnect_error', function (e) { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_failed', function () { | ||
// ... | ||
}); | ||
this.socket.io.on('ping', function () { | ||
// ... | ||
}); | ||
}; | ||
ChatClient.prototype.listenToAppEvents = function () { | ||
var _this = this; | ||
this.socket.on('message', function (data) { | ||
@@ -160,33 +196,2 @@ _this.eventRegistry.emit('message', data); | ||
}); | ||
// | ||
// Listen on IO events | ||
this.socket.io.on('connect_timeout', function (data) { | ||
// ... | ||
}); | ||
this.socket.io.on('error', function (e) { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect', function (attempts) { | ||
setTimeout(function () { return _this.eventRegistry.emit('reconnect', {}); }, 3000); | ||
}); | ||
this.socket.io.on('reconnect_attempt', function (attempts) { | ||
if (attempts === MAX_RETRY_ATTEMPS) { | ||
_this.eventRegistry.emit('maxRetryAttemptsReached', {}); | ||
} | ||
}); | ||
this.socket.io.on('reconnecting', function (data) { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_error', function (e) { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_failed', function (e) { | ||
// ... | ||
}); | ||
this.socket.io.on('ping', function (data) { | ||
// ... | ||
}); | ||
this.socket.io.on('pong', function (data) { | ||
// ... | ||
}); | ||
}; | ||
@@ -198,5 +203,7 @@ ChatClient.prototype.connect = function () { | ||
ChatClient.prototype.joinChannel = function (channelId) { | ||
this.lastJoinedChannelId = channelId; | ||
this.socket.emit('join-channel', { id: channelId }); | ||
}; | ||
ChatClient.prototype.leaveChannel = function (channelId) { | ||
this.lastJoinedChannelId = null; | ||
this.socket.emit('leave-channel', { id: channelId }); | ||
@@ -203,0 +210,0 @@ }; |
{ | ||
"name": "bulbul-chat", | ||
"version": "2.8.0", | ||
"version": "2.8.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -123,2 +123,6 @@ import * as qs from 'qs'; | ||
private isDisconnected: boolean = false; | ||
private lastJoinedChannelId: string | null = null; | ||
constructor(endpoint: string, token: string) { | ||
@@ -130,2 +134,3 @@ this.endpoint = endpoint; | ||
autoConnect: false, | ||
forceNew: true, | ||
transports: ['websocket'], | ||
@@ -139,4 +144,16 @@ query: { | ||
listen() { | ||
this.listenToAppEvents(); | ||
this.socket.on('connect', () => { | ||
// ... | ||
if (this.isDisconnected) { | ||
setTimeout(() => { | ||
if (this.lastJoinedChannelId) { | ||
this.joinChannel(this.lastJoinedChannelId); | ||
} | ||
}, 5000); | ||
this.isDisconnected = false; | ||
} | ||
this.eventRegistry.emit('connect', {}); | ||
@@ -150,5 +167,35 @@ }); | ||
this.socket.on('disconnect', (data: any) => { | ||
this.isDisconnected = true; | ||
}); | ||
// Listen on IO events | ||
this.socket.io.on('error', (e: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect', (attempt: any) => { | ||
setTimeout(() => this.eventRegistry.emit('reconnect', {}), 3000); | ||
}); | ||
this.socket.io.on('reconnect_attempt', (attempt: any) => { | ||
if (attempt === MAX_RETRY_ATTEMPS) { | ||
this.eventRegistry.emit('maxRetryAttemptsReached', {}); | ||
} | ||
}); | ||
this.socket.io.on('reconnect_error', (e: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_failed', () => { | ||
// ... | ||
}); | ||
this.socket.io.on('ping', () => { | ||
// ... | ||
}); | ||
} | ||
listenToAppEvents() { | ||
this.socket.on('message', (data: any) => { | ||
@@ -219,44 +266,2 @@ this.eventRegistry.emit('message', data); | ||
}); | ||
// | ||
// Listen on IO events | ||
this.socket.io.on('connect_timeout', (data: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('error', (e: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect', (attempts: any) => { | ||
setTimeout(() => this.eventRegistry.emit('reconnect', {}), 3000); | ||
}); | ||
this.socket.io.on('reconnect_attempt', (attempts: number) => { | ||
if (attempts === MAX_RETRY_ATTEMPS) { | ||
this.eventRegistry.emit('maxRetryAttemptsReached', {}); | ||
} | ||
}); | ||
this.socket.io.on('reconnecting', (data: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_error', (e: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('reconnect_failed', (e: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('ping', (data: any) => { | ||
// ... | ||
}); | ||
this.socket.io.on('pong', (data: any) => { | ||
// ... | ||
}); | ||
} | ||
@@ -270,2 +275,3 @@ | ||
joinChannel(channelId: string) { | ||
this.lastJoinedChannelId = channelId; | ||
this.socket.emit('join-channel', { id: channelId }); | ||
@@ -275,2 +281,3 @@ } | ||
leaveChannel(channelId: string) { | ||
this.lastJoinedChannelId = null; | ||
this.socket.emit('leave-channel', { id: channelId }); | ||
@@ -277,0 +284,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
244745
4450