ping pong check, fix to channel status, explicit channel removal option added for custom channels
This commit is contained in:
parent
3b98db62a2
commit
030fb62b38
@ -115,7 +115,9 @@ class ChannelManager {
|
|||||||
|
|
||||||
purgeEmptyChannels() {
|
purgeEmptyChannels() {
|
||||||
for (const channel of this.channels) {
|
for (const channel of this.channels) {
|
||||||
if (channel.clients.length === 0 && channel.id !== 'default') {
|
logger.accessLog.info(`Purging empty channels...`);
|
||||||
|
|
||||||
|
if (channel.clients.length === 0 && channel.explicitRemoval === false) {
|
||||||
const index = this.channels.indexOf(channel);
|
const index = this.channels.indexOf(channel);
|
||||||
this.channels.splice(index, 1);
|
this.channels.splice(index, 1);
|
||||||
logger.accessLog.info(`channel removed: ${channel.id}`);
|
logger.accessLog.info(`channel removed: ${channel.id}`);
|
||||||
|
@ -9,6 +9,7 @@ class ChannelBase {
|
|||||||
clients: any[] = [];
|
clients: any[] = [];
|
||||||
broadcastConditions: string = "true";
|
broadcastConditions: string = "true";
|
||||||
channelContent: JSON = JSON.parse('{}');
|
channelContent: JSON = JSON.parse('{}');
|
||||||
|
explicitRemoval: boolean = false;
|
||||||
|
|
||||||
constructor(id: string) {
|
constructor(id: string) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
@ -10,6 +10,7 @@ class CustomChannel extends ChannelBase {
|
|||||||
if (custom) {
|
if (custom) {
|
||||||
this.broadcastConditions = custom.broadcastConditions;
|
this.broadcastConditions = custom.broadcastConditions;
|
||||||
this.channelContent = custom.channelContent;
|
this.channelContent = custom.channelContent;
|
||||||
|
this.explicitRemoval = custom.explicitRemoval;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,8 @@ class ClientBase {
|
|||||||
roles: string[];
|
roles: string[];
|
||||||
messageListener: (data: any) => void;
|
messageListener: (data: any) => void;
|
||||||
closeListener: () => void;
|
closeListener: () => void;
|
||||||
|
pongListener: () => void;
|
||||||
|
heartbeat: any;
|
||||||
|
|
||||||
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
|
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
|
||||||
this.ws = ws;
|
this.ws = ws;
|
||||||
@ -42,8 +44,14 @@ class ClientBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.clientManager.removeClient(this.id);
|
this.clientManager.removeClient(this.id);
|
||||||
|
clearInterval(this.heartbeat);
|
||||||
logger.accessLog.info(`closed connection for client ${this.id}`);
|
logger.accessLog.info(`closed connection for client ${this.id}`);
|
||||||
};
|
};
|
||||||
|
this.pongListener = () => {
|
||||||
|
logger.accessLog.info(`client (${this.id}) ponged.`);
|
||||||
|
this.ws.pong();
|
||||||
|
}
|
||||||
|
this.heartbeat = setInterval(() => { this.ws.ping('ping') }, 30000);
|
||||||
|
|
||||||
logger.accessLog.info('Client Created', {data});
|
logger.accessLog.info('Client Created', {data});
|
||||||
}
|
}
|
||||||
@ -64,6 +72,8 @@ class ClientBase {
|
|||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
this.ws.on('message', this.messageListener);
|
this.ws.on('message', this.messageListener);
|
||||||
this.ws.on('close', this.closeListener);
|
this.ws.on('close', this.closeListener);
|
||||||
|
this.ws.on('pong', this.pongListener);
|
||||||
|
this.heartbeat;
|
||||||
}
|
}
|
||||||
|
|
||||||
messageTransaction(message: any) {
|
messageTransaction(message: any) {
|
||||||
|
@ -46,21 +46,21 @@ function connectionManager() {
|
|||||||
|
|
||||||
if (data.channel_type == 'custom') {
|
if (data.channel_type == 'custom') {
|
||||||
const channel = channelManager.channelExists(data.channel);
|
const channel = channelManager.channelExists(data.channel);
|
||||||
const connectionResponse = {
|
let connectionResponse = {
|
||||||
message_type: 'channelStatus',
|
message_type: 'channelStatus',
|
||||||
content: channel.channelContent
|
content: channel.channelContent
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.user_roles.includes('super')) {
|
if (data.user_roles.includes('super')) {
|
||||||
channelManager.updateChannelContent(channel, data.custom.channelContent);
|
channelManager.updateChannelContent(channel, data.custom.channelContent);
|
||||||
channel.broadcastMessage(connectionResponse);
|
connectionResponse['content'] = channel.channelContent;
|
||||||
|
channel.broadcastMessage(client, connectionResponse);
|
||||||
} else {
|
} else {
|
||||||
client.directMessage(connectionResponse);
|
client.directMessage(connectionResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.accessLog.info(`Purging empty channels...`);
|
|
||||||
channelManager.purgeEmptyChannels();
|
channelManager.purgeEmptyChannels();
|
||||||
|
|
||||||
ws.send(`Hi there, welcome to braid, Measures Web Socket server. Connecting all our services!\nYou are currently in channel: ${data.channel}`);
|
ws.send(`Hi there, welcome to braid, Measures Web Socket server. Connecting all our services!\nYou are currently in channel: ${data.channel}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user