add alive check for gateway and fix webhook message event bug
This commit is contained in:
parent
e33f6f7cfd
commit
aae5ce66ca
4 changed files with 33 additions and 10 deletions
|
@ -18,6 +18,8 @@ class GatewayServer {
|
|||
...extraWebsocketServerConfig
|
||||
});
|
||||
|
||||
setInterval(this.onAliveCheck.bind(this), 30000);
|
||||
|
||||
this.wss.on("connection", (ws) => {
|
||||
this.onConnection(ws);
|
||||
ws.on("message", (data, isBinary) => {
|
||||
|
@ -25,7 +27,10 @@ class GatewayServer {
|
|||
});
|
||||
ws.on("close", (code, reason) => {
|
||||
this.onDisconnect(code, reason.toString());
|
||||
})
|
||||
});
|
||||
ws.on("pong", () => {
|
||||
this.onPong(ws);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -187,6 +192,20 @@ class GatewayServer {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
onPong(ws) {
|
||||
this._clientDispatch(ws, { type: "SET_ALIVE", alive: true });
|
||||
}
|
||||
|
||||
onAliveCheck() {
|
||||
this.wss.clients.forEach(ws => {
|
||||
if (ws.isAlive === false)
|
||||
return ws.terminate();
|
||||
|
||||
this._clientDispatch(ws, { type: "SET_ALIVE", alive: false });
|
||||
ws.ping();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export default GatewayServer;
|
||||
|
|
|
@ -59,11 +59,6 @@ class WatchedGuild extends EventEmitter {
|
|||
if (message.guild_id !== this.upstreamGuildId)
|
||||
return;
|
||||
|
||||
// TODOOOOOO: bridge user's wont get message events from other bridge users in the same channel
|
||||
const maybeKnownWebhook = this.knownWebhooks.get(message.channel_id);
|
||||
if (maybeKnownWebhook && maybeKnownWebhook.id === message.webhook_id)
|
||||
return; // ignore messages coming from our webhook
|
||||
|
||||
this.pushEvent({
|
||||
eventType: "MESSAGE_CREATE",
|
||||
message: message
|
||||
|
|
|
@ -15,6 +15,11 @@
|
|||
|
||||
function handleEvent(event) {
|
||||
if (event.eventType === "MESSAGE_CREATE") {
|
||||
// ignore messages that are seemingly coming from ourselves
|
||||
if (event.message.webhook_id && event.message.author.username === user.username) {
|
||||
return;
|
||||
}
|
||||
|
||||
const guildId = event.message.guild_id;
|
||||
const channelId = event.message.channel_id;
|
||||
|
||||
|
@ -69,13 +74,13 @@
|
|||
selectedChannel = guilds[0].channels[0];
|
||||
}
|
||||
|
||||
if (supportsWebsockets()) {
|
||||
if (supportsWebsockets() && !localStorage.getItem("f_disableWebsockets")) {
|
||||
console.log("App: browser supports WebSocket, using gateway");
|
||||
const gatewayConnection = new GatewayClient(`${ location.protocol === "https:" ? "wss://" : "ws://" }${location.host}/gateway`);
|
||||
gatewayConnection.onEvent = handleEvent;
|
||||
gatewayConnection.connect(apiClient.token);
|
||||
} else {
|
||||
console.warn("App: browser does not WebSocket, using polling");
|
||||
console.warn("App: browser does not support WebSocket, using polling");
|
||||
const { poll } = apiClient.createPollingListener(null, ({ event }) => {
|
||||
handleEvent(event);
|
||||
});
|
||||
|
|
|
@ -43,8 +43,12 @@
|
|||
|
||||
<div class="card full-card option-card">
|
||||
<span class="main-panel-header">{ title }</span>
|
||||
{#each displayedElements as element}
|
||||
<button class="button option-button" on:click={elementClicked(element.id)}>{ element.name }</button>
|
||||
{#each displayedElements as element, index}
|
||||
{#if index === 0}
|
||||
<button class="button button-selected option-button" on:click={elementClicked(element.id)}>{ element.name }</button>
|
||||
{:else}
|
||||
<button class="button option-button" on:click={elementClicked(element.id)}>{ element.name }</button>
|
||||
{/if}
|
||||
{/each}
|
||||
{#if displayedElements.length < 1}
|
||||
<div class="center-text">
|
||||
|
|
Loading…
Reference in a new issue