Skip to content

Commit

Permalink
fix(): fixed issue with client indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Izak88 committed Oct 13, 2017
1 parent f08d586 commit 6ae0a0a
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/api/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ export class SocketServer {
};
logger.next(msg);

const clientIndex = this.clients.length - 1;

// send server time for sync
conn.next({ type: 'time', data: new Date().getTime() });

Expand All @@ -90,11 +88,11 @@ export class SocketServer {
let imageBuilderSub: Subscription;

conn.subscribe(event => {
const clientIndex = this.clients.findIndex(client => client.connection === conn);
if (event.type === 'disconnected') {
const index = this.clients.findIndex(client => client.connection === conn);
const session = this.clients[index].session;
const username = this.clients[index].username;
this.clients.splice(index, 1);
const session = this.clients[clientIndex].session;
const username = this.clients[clientIndex].username;
this.clients.splice(clientIndex, 1);

const msg: LogMessageType = {
message: `[socket]: user ${session.userId} (${username}) disconnected`,
Expand Down

0 comments on commit 6ae0a0a

Please sign in to comment.