Skip to content

Commit

Permalink
fix(bot): add additional check preventing another WebGroup with the s…
Browse files Browse the repository at this point in the history
…ame key
  • Loading branch information
kalitine committed Sep 7, 2018
1 parent 0f48d21 commit 135d9f1
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/Bot.ts
Expand Up @@ -88,9 +88,10 @@ export class Bot {

this.webSocketServer.on('connection', (ws: WebSocket) => {
const { type, wcId, senderId, key } = this.readURLQuery((ws as any).upgradeReq.url)
let webSocketBuilder: WebSocketBuilder
if (type === Channel.WITH_MEMBER) {
const wg = new WebGroup(this.wcOptions)
let webSocketBuilder
let wg = this.webGroups.get(wcId)
if (type === Channel.WITH_MEMBER && (wg === undefined || wg.state === WebGroupState.LEFT)) {
wg = new WebGroup(this.wcOptions)
this.webGroups.set(wcId, wg)
const wc = wcs.get(wg) as WebChannel
if (this.leaveOnceAlone) {
Expand All @@ -103,10 +104,11 @@ export class Bot {
this.onWebGroup(wg)
wc.onMyId(wc.myId)
webSocketBuilder = wc.webSocketBuilder
} else if (wg !== undefined) {
webSocketBuilder = (wcs.get(wg) as WebChannel).webSocketBuilder
} else {
const wg = this.webGroups.get(wcId) as WebGroup
const wc = wcs.get(wg) as WebChannel
webSocketBuilder = wc.webSocketBuilder
ws.close()
return
}
webSocketBuilder.newWebSocket(ws, senderId, type)
})
Expand Down

0 comments on commit 135d9f1

Please sign in to comment.