From d03bea97afcd07c33acd630d07d9d23f8bb7d6eb Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Sun, 29 Sep 2013 22:52:40 -0500 Subject: [PATCH] Rooms can now expire Rooms send |expire| when they expire; this means that the room no longer exists server-side but the client might want to leave the room open. --- js/client-chat.js | 5 ++++- js/client.js | 13 +++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/js/client-chat.js b/js/client-chat.js index 295c60531..043298660 100644 --- a/js/client-chat.js +++ b/js/client-chat.js @@ -23,7 +23,10 @@ updateUser: function() { var name = app.user.get('name'); var userid = app.user.get('userid'); - if (!name) { + if (this.expired) { + this.$chatAdd.html('This room is expired'); + this.$chatbox = null; + } else if (!name) { this.$chatAdd.html('Connecting...'); this.$chatbox = null; } else if (!app.user.get('named')) { diff --git a/js/client.js b/js/client.js index f386a5a5f..04e495e10 100644 --- a/js/client.js +++ b/js/client.js @@ -782,8 +782,21 @@ } else { this.joinRoom(roomid, roomType, true); } + } else if ((data+'|').substr(0,8) === '|expire|') { + var room = this.rooms[roomid]; + if (room) { + room.expired = true; + if (room.updateUser) room.updateUser(); + } + return; } else if ((data+'|').substr(0,8) === '|deinit|' || (data+'|').substr(0,8) === '|noinit|') { if (!roomid) roomid = 'lobby'; + + if (this.rooms[roomid] && this.rooms[roomid].expired) { + // expired rooms aren't closed when left + return; + } + var isdeinit = (data.charAt(1) === 'd'); data = data.substr(8); var pipeIndex = data.indexOf('|');