From 7d5c6e1f8a52b7738f5c8d6cb241efdb133a2b90 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 4 Nov 2015 00:04:29 -0500 Subject: [PATCH 01/32] comment-box: remove unused code (superseded by md-selected) --- src/app/shared/comment-box/comment-box.controller.js | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index 6e553d0f..0f075e22 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -34,16 +34,5 @@ vm.goToProfile = function(steamId) { window.open('http://steamcommunity.com/profiles/' + steamId, '_blank'); }; - - $rootScope.$on('$stateChangeStart', - function(event, toState) { - if (toState.name==='lobby-page') { - vm.currentTab = 1; - } else { - vm.currentTab = 0; - } - } - ); - } })(); From 0dfbfdf604a5b9df5483315438e47704dac3f25b Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 4 Nov 2015 03:14:34 -0500 Subject: [PATCH 02/32] Make the unique filter more general purpose --- src/app/app.filter.js | 4 ++-- src/app/pages/lobby/page/spectators.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/app.filter.js b/src/app/app.filter.js index a4ac0fdc..c553a212 100644 --- a/src/app/app.filter.js +++ b/src/app/app.filter.js @@ -74,12 +74,12 @@ /** @ngInject */ function unique() { - return function (array) { + return function (array, uniqueKey) { var uniqueArray = []; for (var key in array) { var existsInArray = false; for (var j in uniqueArray) { - if (uniqueArray[j].steamid === array[key].steamid) { + if (uniqueArray[j][uniqueKey] === array[key][uniqueKey]) { existsInArray = true; } } diff --git a/src/app/pages/lobby/page/spectators.html b/src/app/pages/lobby/page/spectators.html index a34acc97..ddfc83cd 100644 --- a/src/app/pages/lobby/page/spectators.html +++ b/src/app/pages/lobby/page/spectators.html @@ -3,7 +3,7 @@

Spectators

- {{::spectator.name}} @@ -21,4 +21,4 @@

- \ No newline at end of file + From 501ff4a08404c8785bf047cd4d81d023d056b47f Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 4 Nov 2015 03:16:42 -0500 Subject: [PATCH 03/32] track lobby leave/join events --- src/app/pages/lobby/lobby.factory.js | 48 +++++++++-- src/app/shared/websocket.factory.js | 117 ++++++++++++++------------- 2 files changed, 104 insertions(+), 61 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 550c8f50..747e9c6a 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -4,11 +4,13 @@ angular.module('tf2stadium.services').factory('LobbyService', LobbyService); /** @ngInject */ - function LobbyService($rootScope, $state, $mdDialog, $timeout, $interval, Websocket, Notifications) { + function LobbyService($rootScope, $state, $mdDialog, $timeout, $interval, + Websocket, Notifications, User) { var factory = {}; factory.lobbyList = {}; factory.lobbySpectated = {}; + factory.lobbyJoinedId = -1; factory.lobbyJoinInformation = {}; var playerPreReady = false; @@ -81,7 +83,11 @@ 'class': position }; - Websocket.emitJSON('lobbyJoin', payload); + Websocket.emitJSON('lobbyJoin', payload, function (response) { + if (response.success) { + $rootScope.$emit('lobby-joined', lobby); + } + }); }; factory.goToLobby = function(lobby) { @@ -176,15 +182,47 @@ $rootScope.$emit('lobby-list-updated'); }); - Websocket.onJSON('lobbyData', function(data) { + Websocket.onJSON('lobbyData', function(newLobby) { var oldLobbyId = factory.lobbySpectated.id; - factory.lobbySpectated = data; - if (data.id !== oldLobbyId) { + factory.lobbySpectated = newLobby; + + // A lobbyData sent before the initialization messages have + // finished must be a lobby we're already joined to + if (!Websocket.isInitialized()) { + $rootScope.$emit('lobby-joined', newLobby.id); + } + + // Deduce user state changes from lobbyData (if we got kicked, etc.) + if (angular.isDefined($rootScope.userProfile) + && angular.isDefined($rootScope.userProfile.steamid)) { + var ourSteamId = $rootScope.userProfile.steamid; + var slots = newLobby.classes; + var inNewLobby = _(_.isArray(slots)? slots : []) + .map(_.partialRight(_.pick, ['red', 'blu'])) + .map(_.values) + .flatten() + .filter(_.partialRight(_.pluck, 'filled')) + .map(_.partialRight(_.pluck, 'steamid')) + .contains(ourSteamId); + + if (newLobby.id === factory.lobbyJoinedId && !inNewLobby) { + $rootScope.$emit('lobby-left', newLobby.id); + } else if (newLobby.id !== factory.lobbyJoinedId && inNewLobby) { + $rootScope.$emit('lobby-left', factory.lobbyJoinedId); + $rootScope.$emit('lobby-joined', newLobby.id); + } + } + + if (newLobby.id !== oldLobbyId) { $rootScope.$emit('lobby-spectated-changed'); } $rootScope.$emit('lobby-spectated-updated'); }); + $rootScope.$on('lobby-joined', function (e, lobbyId) { + factory.lobbyJoinedId = lobbyId; + }); + return factory; } diff --git a/src/app/shared/websocket.factory.js b/src/app/shared/websocket.factory.js index 50dbe0d6..78030a26 100644 --- a/src/app/shared/websocket.factory.js +++ b/src/app/shared/websocket.factory.js @@ -66,69 +66,74 @@ data); if (!queuedMessages[name]) { queuedMessages[name] = []; - } + } - queuedMessages[name].push(data); - } - }; - - var factory = {}; - factory.onJSON = function(name, callback) { - callback = asyncAngularify(callback || angular.noop); - - // Dispatch queued messages for the initialization - // workaround. Technically it is possible for messages to arrive - // out of order by doing this, but it should be negligible (a - // message would have to arrive and be delivered to the socket - // between when this function completes and the 0-delay timeout of - // asyncAngularify). We can't skip the timeout here because event - // handlers are not generally defined with the intention of being - // called before their enclosing scope finishes executing. - registeredHandlers[name] = true; - if (queuedMessages[name]) { - asyncAngularify(function () { - queuedMessages[name].forEach(function (data) { - console.log('Received: ' + name, data); - callback(data); - }); - })(); - } + queuedMessages[name].push(data); + } + }; - socket.On(name, function (data) { - console.log('Received: ' + name, data); - callback(data); - }); - }; - - function emitJSON(name, data, callback) { - console.log('Sending ' + name, data); - data.request = name; - - socket.Emit(data, function(jsonIn) { - var data = JSON.parse(jsonIn); - console.log('Response to ' + name, data); - console.log(data); - if (!data.success) { - Notifications.toast({message: data.message, error: true}); + var factory = {}; + factory.onJSON = function(name, callback) { + callback = asyncAngularify(callback || angular.noop); + + // Dispatch queued messages for the initialization + // workaround. Technically it is possible for messages to arrive + // out of order by doing this, but it should be negligible (a + // message would have to arrive and be delivered to the socket + // between when this function completes and the 0-delay timeout of + // asyncAngularify). We can't skip the timeout here because event + // handlers are not generally defined with the intention of being + // called before their enclosing scope finishes executing. + registeredHandlers[name] = true; + if (queuedMessages[name]) { + asyncAngularify(function () { + queuedMessages[name].forEach(function (data) { + console.log('Received: ' + name, data); + callback(data); + }); + })(); } - callback(data); - }); - } - factory.emitJSON = function(name, data, callback) { - callback = asyncAngularify(callback || angular.noop); + socket.On(name, function (data) { + console.log('Received: ' + name, data); + callback(data); + }); + }; + - if (connected) { - emitJSON(name, data, callback); - } else { - var deregister = $rootScope.$on('socket-opened', function() { - emitJSON(name, data, callback); - deregister(); + factory.isInitialized = function () { + return connected; + }; + + function emitJSON(name, data, callback) { + console.log('Sending ' + name, data); + data.request = name; + + socket.Emit(data, function(jsonIn) { + var data = JSON.parse(jsonIn); + console.log('Response to ' + name, data); + console.log(data); + if (!data.success) { + Notifications.toast({message: data.message, error: true}); + } + callback(data); }); } - }; - return factory; -} + factory.emitJSON = function(name, data, callback) { + callback = asyncAngularify(callback || angular.noop); + + if (connected) { + emitJSON(name, data, callback); + } else { + var deregister = $rootScope.$on('socket-opened', function() { + emitJSON(name, data, callback); + deregister(); + }); + } + }; + + return factory; + } })(); From 071f70eabc64a09bbbe98136e3b519ac97f7ea11 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 4 Nov 2015 03:17:05 -0500 Subject: [PATCH 04/32] chatbox: support 3 tabs: global/spectated/joined Note: lodash dependency added --- src/app/shared/comment-box/chat.service.js | 62 +++++++++++----- .../comment-box/comment-box.controller.js | 11 +-- src/app/shared/comment-box/comment-box.html | 70 ++++++++----------- 3 files changed, 79 insertions(+), 64 deletions(-) diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index acf48335..7817241e 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -3,20 +3,39 @@ angular.module('tf2stadium.services').factory('ChatService', ChatService); + // Persistent map of room id -> messages list + var chatRoomLogs = {}; + + function ChatRoom(id) { + this.changeRoom(angular.isDefined(id)? id : -1); + } + + ChatRoom.prototype.changeRoom = function chageRoom(id) { + if (id !== this.id) { + this.id = id; + if (chatRoomLogs.hasOwnProperty(id)) { + this.messages = chatRoomLogs[id]; + } else { + this.messages = chatRoomLogs[id] = []; + } + } + }; + + ChatRoom.prototype.leave = function leave() { + this.changeRoom(-1); + }; + /** @ngInject */ function ChatService(Websocket, $rootScope, LobbyService) { - var factory = {}; - var rooms = { - general: { - id: 0, - messages: [] - }, - lobbySpectated: { - id: -1, - messages: [] - } - }; + + var globalChatRoom = new ChatRoom(0); + var spectatedChatRoom = new ChatRoom(); + var joinedChatRoom = new ChatRoom(); + + joinedChatRoom.joined = true; + + var rooms = [globalChatRoom, spectatedChatRoom, joinedChatRoom]; factory.getRooms = function() { return rooms; @@ -29,20 +48,31 @@ }); }; + $rootScope.$on('lobby-joined', function (e, id) { + joinedChatRoom.changeRoom(id); + }); + + $rootScope.$on('lobby-left', function (e, id) { + joinedChatRoom.leave(); + }); + $rootScope.$on('lobby-spectated-changed', function() { - rooms.lobbySpectated.id = LobbyService.getLobbySpectated().id; + var spectatedLobby = LobbyService.getLobbySpectated(); + + spectatedChatRoom.changeRoom(spectatedLobby.id); }); Websocket.onJSON('chatReceive', function (message) { - if (message.room === 0) { - rooms.general.messages.push(message); + if (chatRoomLogs.hasOwnProperty(message.room)) { + chatRoomLogs[message.room].push(message); } else { - rooms.lobbySpectated.messages.push(message); + chatRoomLogs[message.room] = [message]; } }); + // TODO: I think this message isn't needed Websocket.onJSON('chatHistoryClear', function() { - rooms.lobbySpectated.messages = []; + // spectatedChatRoom.clear(); }); return factory; diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index 0f075e22..072980f4 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -13,22 +13,15 @@ vm.currentTab = 0; vm.sendMessage = function(event) { - if (vm.messageBox === "" || event.keyCode !== 13) { - return false; - } - - var room = 0; - - if (vm.currentTab !== 0) { - room = vm.rooms.lobbySpectated.id; + return; } + var room = vm.rooms[vm.currentTab].id; ChatService.send(vm.messageBox, room); vm.messageBox = ''; event.preventDefault(); - }; vm.goToProfile = function(steamId) { diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index 21a44548..11027b9a 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -1,49 +1,35 @@
-
- - - Chat +
+ + + + {{room.id === 0? 'CHAT' : ('Lobby #' + room.id)}} + -
- - +
+ + {{::message.player.name}}: - - Steam profile - - - - - {{::message.message}} -
- - - - - Lobby #{{commentBox.rooms.lobbySpectated.id}} - - -
- - - {{::message.player.name}}: - - - - + Steam profile @@ -54,10 +40,16 @@ + + - +
From 3cdb1959fe9e127212ca30e994e4a18821123264 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 4 Nov 2015 10:43:04 -0500 Subject: [PATCH 05/32] fix lobby leave/join tracking --- src/app/pages/lobby/lobby.factory.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 747e9c6a..2a5b72e7 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -201,15 +201,18 @@ .map(_.partialRight(_.pick, ['red', 'blu'])) .map(_.values) .flatten() - .filter(_.partialRight(_.pluck, 'filled')) - .map(_.partialRight(_.pluck, 'steamid')) + .filter(_.property('filled')) + .pluck('player.steamid') .contains(ourSteamId); if (newLobby.id === factory.lobbyJoinedId && !inNewLobby) { + factory.lobbyJoinedId = -1; $rootScope.$emit('lobby-left', newLobby.id); + console.log('lobby-left ' + newLobby.id); } else if (newLobby.id !== factory.lobbyJoinedId && inNewLobby) { - $rootScope.$emit('lobby-left', factory.lobbyJoinedId); + factory.lobbyJoinedId = newLobby.id; $rootScope.$emit('lobby-joined', newLobby.id); + console.log('lobby-joined ' + newLobby.id); } } @@ -219,10 +222,6 @@ $rootScope.$emit('lobby-spectated-updated'); }); - $rootScope.$on('lobby-joined', function (e, lobbyId) { - factory.lobbyJoinedId = lobbyId; - }); - return factory; } From 378a8102b6bc24d2b532f291ddae7e5cf6d7b609 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Fri, 6 Nov 2015 22:10:13 -0500 Subject: [PATCH 06/32] Use new server lobbyJoin/Leave messages rather than deducing these from lobbyData messsages --- src/app/pages/lobby/lobby.factory.js | 60 ++++++++++++++-------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 2a5b72e7..f992702e 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -85,7 +85,10 @@ Websocket.emitJSON('lobbyJoin', payload, function (response) { if (response.success) { - $rootScope.$emit('lobby-joined', lobby); + // lobbyJoin is now handled later in a dedicated lobbyJoin + // event message handler (a separate event, not the response + // to this lobbyJoin request) + // $rootScope.$emit('lobby-joined', lobby); } }); }; @@ -137,7 +140,7 @@ }, bindToController: true }) - .then(function(response) { + .then(function(response) { if (response.readyUp) { Websocket.emitJSON('playerReady', {}); localStorage.setItem('tabCommunication', ''); @@ -148,7 +151,7 @@ localStorage.setItem('tabCommunication', ''); localStorage.setItem('tabCommunication', 'closeDialog'); } - ); + ); Notifications.notifyBrowser({ title: 'Click here to ready up!', body: 'All the slots are filled, ready up to start', @@ -182,39 +185,38 @@ $rootScope.$emit('lobby-list-updated'); }); - Websocket.onJSON('lobbyData', function(newLobby) { - var oldLobbyId = factory.lobbySpectated.id; - factory.lobbySpectated = newLobby; - - // A lobbyData sent before the initialization messages have - // finished must be a lobby we're already joined to - if (!Websocket.isInitialized()) { - $rootScope.$emit('lobby-joined', newLobby.id); + Websocket.onJSON('lobbyLeave', function(data) { + if (angular.isDefined($rootScope.userProfile) + && angular.isDefined($rootScope.userProfile.steamid)) { + var ourSteamId = $rootScope.userProfile.steamid; + if (data.player_id === ourSteamId) { + factory.lobbyJoinedId = -1; + $rootScope.$emit('lobby-left', data.lobby_id); + console.log('lobby-left ' + data.lobby_id); + } } + }); - // Deduce user state changes from lobbyData (if we got kicked, etc.) + // Handling lobbyJoin here instead of the response to our + // lobbyJoin requests properly captures lobbyJoins from other + // browsers of the same logged in user, and also gets the state of + // the user when a user in a lobby connects in a fresh browser + // session. + Websocket.onJSON('lobbyJoin', function(data) { if (angular.isDefined($rootScope.userProfile) && angular.isDefined($rootScope.userProfile.steamid)) { var ourSteamId = $rootScope.userProfile.steamid; - var slots = newLobby.classes; - var inNewLobby = _(_.isArray(slots)? slots : []) - .map(_.partialRight(_.pick, ['red', 'blu'])) - .map(_.values) - .flatten() - .filter(_.property('filled')) - .pluck('player.steamid') - .contains(ourSteamId); - - if (newLobby.id === factory.lobbyJoinedId && !inNewLobby) { - factory.lobbyJoinedId = -1; - $rootScope.$emit('lobby-left', newLobby.id); - console.log('lobby-left ' + newLobby.id); - } else if (newLobby.id !== factory.lobbyJoinedId && inNewLobby) { - factory.lobbyJoinedId = newLobby.id; - $rootScope.$emit('lobby-joined', newLobby.id); - console.log('lobby-joined ' + newLobby.id); + if (data.player_id === ourSteamId) { + factory.lobbyJoinedId = data.lobby_id; + $rootScope.$emit('lobby-joined', data.lobby_id); + console.log('lobby-joined ' + data.lobby_id); } } + }); + + Websocket.onJSON('lobbyData', function(newLobby) { + var oldLobbyId = factory.lobbySpectated.id; + factory.lobbySpectated = newLobby; if (newLobby.id !== oldLobbyId) { $rootScope.$emit('lobby-spectated-changed'); From 42ca98e55afe49d2ad857a818270c9bf2e0b9c17 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Fri, 6 Nov 2015 22:14:02 -0500 Subject: [PATCH 07/32] use consistently named lobbyId/playerId property names --- src/app/pages/lobby/lobby.factory.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index f992702e..5b46fb11 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -189,10 +189,10 @@ if (angular.isDefined($rootScope.userProfile) && angular.isDefined($rootScope.userProfile.steamid)) { var ourSteamId = $rootScope.userProfile.steamid; - if (data.player_id === ourSteamId) { + if (data.playerId === ourSteamId) { factory.lobbyJoinedId = -1; - $rootScope.$emit('lobby-left', data.lobby_id); - console.log('lobby-left ' + data.lobby_id); + $rootScope.$emit('lobby-left', data.lobbyId); + console.log('lobby-left ' + data.lobbyId); } } }); @@ -206,10 +206,10 @@ if (angular.isDefined($rootScope.userProfile) && angular.isDefined($rootScope.userProfile.steamid)) { var ourSteamId = $rootScope.userProfile.steamid; - if (data.player_id === ourSteamId) { - factory.lobbyJoinedId = data.lobby_id; - $rootScope.$emit('lobby-joined', data.lobby_id); - console.log('lobby-joined ' + data.lobby_id); + if (data.playerId === ourSteamId) { + factory.lobbyJoinedId = data.lobbyId; + $rootScope.$emit('lobby-joined', data.lobbyId); + console.log('lobby-joined ' + data.lobbyId); } } }); From d7cd74ae0715ad7f1bab3ea06b9652822fa4ed8d Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Sat, 7 Nov 2015 20:04:11 -0500 Subject: [PATCH 08/32] Fix things broken by previous merge --- src/app/app.filter.js | 1 + src/app/pages/lobby/lobby.factory.js | 4 ++++ src/app/shared/comment-box/chat.service.js | 12 ++++++------ src/app/shared/comment-box/comment-box.html | 6 +++--- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/app/app.filter.js b/src/app/app.filter.js index a8c6635a..c553a212 100644 --- a/src/app/app.filter.js +++ b/src/app/app.filter.js @@ -8,6 +8,7 @@ app.filter('slotNameToClassName', slotNameToClassName); app.filter('stripSlotNameNumber', stripSlotNameNumber); app.filter('secondsToMinutes', secondsToMinutes); + app.filter('unique', unique); /** @ngInject */ function capitalize() { diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 012308d4..598c9a9e 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -29,6 +29,10 @@ return factory.lobbySpectated; }; + factory.getLobbyJoined = function() { + return factory.lobbyJoined; + }; + factory.getPlayerPreReady = function() { return playerPreReady; }; diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index 7817241e..d08be5cf 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -48,18 +48,18 @@ }); }; - $rootScope.$on('lobby-joined', function (e, id) { - joinedChatRoom.changeRoom(id); + $rootScope.$on('lobby-joined', function () { + var joinedLobbyId = LobbyService.getLobbyJoined().id; + joinedChatRoom.changeRoom(joinedLobbyId); }); - $rootScope.$on('lobby-left', function (e, id) { + $rootScope.$on('lobby-left', function () { joinedChatRoom.leave(); }); $rootScope.$on('lobby-spectated-changed', function() { - var spectatedLobby = LobbyService.getLobbySpectated(); - - spectatedChatRoom.changeRoom(spectatedLobby.id); + var spectatedLobbyId = LobbyService.getLobbySpectated().id; + spectatedChatRoom.changeRoom(spectatedLobbyId); }); Websocket.onJSON('chatReceive', function (message) { diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index 11027b9a..88e4b659 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -8,10 +8,10 @@ md-selected="commentBox.currentTab" md-stretch-tabs="always"> + ng-if="room.id > -1"> - {{room.id === 0? 'CHAT' : ('Lobby #' + room.id)}} + {{room.id === 0? + 'CHAT' : ((room.joined? 'Your':'This') + ' Lobby #' + room.id)}} From e1300e90a03d710fbdead53a78aa6b2796ab3bf4 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Mon, 16 Nov 2015 13:02:19 -0500 Subject: [PATCH 09/32] Consistent lobbyData handling Even when receiving lobbyData for rooms other than the currently spectated lobby. Also, explicitly handle blank lobby data, rather than working with undefined values and hoping it works. --- package.json | 2 +- .../pages/lobby/list/lobby-list.controller.js | 4 + src/app/pages/lobby/lobby.factory.js | 76 ++++++++++++++----- src/app/pages/lobby/page/header.controller.js | 19 +++-- .../pages/lobby/page/lobby-page.controller.js | 2 +- .../pages/lobby/page/spectators.controller.js | 4 +- src/app/shared/comment-box/chat.service.js | 19 ++--- src/app/shared/comment-box/comment-box.html | 2 +- src/app/shared/current-lobby.controller.js | 4 +- 9 files changed, 92 insertions(+), 40 deletions(-) diff --git a/package.json b/package.json index d4e06c4a..4f271db9 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "GPL-3.0", "repository": "https://github.com/TF2Stadium/Frontend", "readme": "readme.md", - "version": "0.2.1", + "version": "0.2.0", "dependencies": { "del": "~1.2.0", "uglify-save-license": "~0.4.1", diff --git a/src/app/pages/lobby/list/lobby-list.controller.js b/src/app/pages/lobby/list/lobby-list.controller.js index b98729ed..6c25d43b 100644 --- a/src/app/pages/lobby/list/lobby-list.controller.js +++ b/src/app/pages/lobby/list/lobby-list.controller.js @@ -11,6 +11,10 @@ vm.lobbies=LobbyService.getList(); + // When we navigate to the main lobby list page, leave the + // spectator spot for whatever lobby we were just in. + LobbyService.leaveSpectatedLobby(); + vm.join = function (lobby, team, position, event) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 3805735e..13cedfbb 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -9,8 +9,13 @@ var factory = {}; factory.lobbyList = {}; - factory.lobbySpectated = {}; - factory.lobbyJoined = {}; + + // map lobby id -> last seen data + factory.lobbyData = Object.create(null); + + factory.lobbySpectatedId = -1; + factory.lobbyJoinedId = -1; + factory.lobbyJoinInformation = {}; var playerPreReady = false; @@ -25,12 +30,34 @@ return factory.lobbyList; }; + // Will return undefined when a lobby is not currently being + // spectated factory.getLobbySpectated = function() { - return factory.lobbySpectated; + return factory.lobbyData[factory.lobbySpectatedId]; + }; + + // Will return -1 when a lobby is not currently being + // spectated + factory.getLobbySpectatedId = function() { + return factory.lobbySpectatedId; + }; + + factory.leaveSpectatedLobby = function() { + factory.lobbySpectatedId = -1; + $rootScope.$emit('lobby-spectated-changed'); + $rootScope.$emit('lobby-spectated-updated'); }; + // Will return undefined when not currently joined in any + // lobby factory.getLobbyJoined = function() { - return factory.lobbyJoined; + return factory.lobbyData[factory.lobbyJoinedId]; + }; + + // Will return -1 when not currently joined in any + // lobby + factory.getLobbyJoinedId = function() { + return factory.lobbyJoinedId; }; factory.getPlayerPreReady = function() { @@ -107,6 +134,14 @@ if($state.current.name === 'lobby-page') { $state.go('lobby-list'); } + } else { + var oldLobbyId = factory.lobbySpectatedId; + factory.lobbySpectatedId = lobby; + + if (lobby !== oldLobbyId) { + $rootScope.$emit('lobby-spectated-changed'); + } + $rootScope.$emit('lobby-spectated-updated'); } }); }; @@ -157,8 +192,7 @@ Websocket.emitJSON('playerNotReady', {}); localStorage.setItem('tabCommunication', ''); localStorage.setItem('tabCommunication', 'closeDialog'); - } - ); + }); Notifications.notifyBrowser({ title: 'Click here to ready up!', body: 'All the slots are filled, ready up to start', @@ -173,7 +207,7 @@ Websocket.onJSON('lobbyStart', function(data) { factory.lobbyJoinInformation = data; - $state.go('lobby-page', {lobbyID: factory.lobbySpectated.id}); + $state.go('lobby-page', {lobbyID: factory.lobbySpectatedId}); $rootScope.$emit('lobby-start'); Notifications.notifyBrowser({ title: 'Lobby is starting!', @@ -191,43 +225,47 @@ factory.lobbyList = data.lobbies; $rootScope.$emit('lobby-list-updated'); - if (!factory.lobbyJoined.id) { + if (factory.lobbyJoinedId === -1) { return; } + factory.lobbyList.forEach(function(lobby) { - if (lobby.id === factory.lobbyJoined.id) { - factory.lobbyJoined.players = lobby.players; - factory.lobbyJoined.maxPlayers = lobby.maxPlayers; + if (lobby.id === factory.lobbyJoinedId) { + factory.getLobbyJoined().players = lobby.players; + factory.getLobbyJoined().maxPlayers = lobby.maxPlayers; } }); $rootScope.$emit('lobby-joined-updated'); }); Websocket.onJSON('lobbyData', function(newLobby) { - var oldLobbyId = factory.lobbySpectated.id; - factory.lobbySpectated = newLobby; + factory.lobbyData[newLobby.id] = newLobby; - if (newLobby.id !== oldLobbyId) { - $rootScope.$emit('lobby-spectated-changed'); + if (newLobby.id === factory.lobbySpectatedId) { + $rootScope.$emit('lobby-spectated-updated'); + } + + if (newLobby.id === factory.lobbyJoinedId) { + $rootScope.$emit('lobby-joined-updated'); } - $rootScope.$emit('lobby-spectated-updated'); }); Websocket.onJSON('lobbyJoined', function(data) { - factory.lobbyJoined = data; + factory.lobbyJoinedId = data.id; + factory.lobbyData[data.id] = data; $rootScope.$emit('lobby-joined'); $rootScope.$emit('lobby-joined-updated'); }); Websocket.onJSON('lobbyLeft', function(data) { - factory.lobbyJoined = {}; + factory.lobbyJoinedId = -1; factory.lobbyJoinInformation = {}; $rootScope.$emit('lobby-joined-updated'); $rootScope.$emit('lobby-left'); }); Websocket.onJSON('lobbyClosed', function(data) { - factory.lobbySpectated = {}; + factory.lobbySpectatedId = -1; if($state.current.name === 'lobby-page') { $state.go('lobby-list'); } diff --git a/src/app/pages/lobby/page/header.controller.js b/src/app/pages/lobby/page/header.controller.js index 4c69c614..b4bcfb99 100644 --- a/src/app/pages/lobby/page/header.controller.js +++ b/src/app/pages/lobby/page/header.controller.js @@ -20,16 +20,25 @@ }; vm.shouldShowLobbyInformation = function() { - return !error && (vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID)); + return !error && (vm.lobbyInformation && vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID)); }; vm.shouldShowLobbyControls = function() { - return vm.lobbyInformation.state < 5 && - $rootScope.userProfile.steamid === vm.lobbyInformation.leader.steamid || $rootScope.userProfile.role == 'administrator'; + if (!vm.lobbyInformation || vm.lobbyInformation.state >= 5) { + return false; + } + + if (typeof $rootScope.userProfile === 'undefined') { + return false; + } + + var user = $rootScope.userProfile; + var leader = vm.lobbyInformation.leader; + return user.steamid === leader.steamid || user.role === 'administrator'; }; vm.shouldShowProgress = function() { - return !error && !(vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID)); + return !error && !(vm.lobbyInformation && vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID)); }; vm.shouldShowError = function() { @@ -38,4 +47,4 @@ } -})(); \ No newline at end of file +})(); diff --git a/src/app/pages/lobby/page/lobby-page.controller.js b/src/app/pages/lobby/page/lobby-page.controller.js index efe89bf9..7ea4cc26 100644 --- a/src/app/pages/lobby/page/lobby-page.controller.js +++ b/src/app/pages/lobby/page/lobby-page.controller.js @@ -87,7 +87,7 @@ }; vm.shouldShowLobbyInformation = function() { - return vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID); + return vm.lobbyInformation && vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID); }; LobbyService.spectate(parseInt($state.params.lobbyID)); diff --git a/src/app/pages/lobby/page/spectators.controller.js b/src/app/pages/lobby/page/spectators.controller.js index bb5aa5dd..2e6ae0a9 100644 --- a/src/app/pages/lobby/page/spectators.controller.js +++ b/src/app/pages/lobby/page/spectators.controller.js @@ -27,8 +27,8 @@ }; vm.shouldShowSpectators = function() { - return vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID); + return vm.lobbyInformation && vm.lobbyInformation.id && vm.lobbyInformation.id === parseInt($state.params.lobbyID); }; } -})(); \ No newline at end of file +})(); diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index d08be5cf..bbea6acd 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -30,8 +30,9 @@ var factory = {}; var globalChatRoom = new ChatRoom(0); - var spectatedChatRoom = new ChatRoom(); - var joinedChatRoom = new ChatRoom(); + + var spectatedChatRoom = new ChatRoom(LobbyService.getLobbySpectatedId()); + var joinedChatRoom = new ChatRoom(LobbyService.getLobbyJoinedId()); joinedChatRoom.joined = true; @@ -49,8 +50,7 @@ }; $rootScope.$on('lobby-joined', function () { - var joinedLobbyId = LobbyService.getLobbyJoined().id; - joinedChatRoom.changeRoom(joinedLobbyId); + joinedChatRoom.changeRoom(LobbyService.getLobbyJoinedId()); }); $rootScope.$on('lobby-left', function () { @@ -58,8 +58,7 @@ }); $rootScope.$on('lobby-spectated-changed', function() { - var spectatedLobbyId = LobbyService.getLobbySpectated().id; - spectatedChatRoom.changeRoom(spectatedLobbyId); + spectatedChatRoom.changeRoom(LobbyService.getLobbySpectatedId()); }); Websocket.onJSON('chatReceive', function (message) { @@ -70,9 +69,11 @@ } }); - // TODO: I think this message isn't needed - Websocket.onJSON('chatHistoryClear', function() { - // spectatedChatRoom.clear(); + Websocket.onJSON('chatHistoryClear', function(data) { + // Note: ChatRooms may have pointers to the arrays in + // chatRoomLogs, so we have to mutate the actual logs rather + // than just assign a new empty array. + chatRoomLogs[data.room].length = 0; }); return factory; diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index 70c3129f..f7080119 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -11,7 +11,7 @@ ng-if="room.id > -1"> {{room.id === 0? - 'CHAT' : ((room.joined? 'Your':'This') + ' Lobby #' + room.id)}} + 'CHAT' : ((room.joined? 'YOUR':'THIS') + ' Lobby #' + room.id)}} diff --git a/src/app/shared/current-lobby.controller.js b/src/app/shared/current-lobby.controller.js index b9cd782b..505d84ef 100644 --- a/src/app/shared/current-lobby.controller.js +++ b/src/app/shared/current-lobby.controller.js @@ -12,12 +12,12 @@ vm.lobbyInformation = LobbyService.getLobbyJoined(); vm.checkVisible = function() { - vm.visible = vm.lobbyInformation.id && vm.lobbyInformation.id !== parseInt($state.params.lobbyID); + vm.visible = !!vm.lobbyInformation && vm.lobbyInformation.id && vm.lobbyInformation.id !== parseInt($state.params.lobbyID); }; LobbyService.subscribe('lobby-joined-updated', $scope, function() { vm.lobbyInformation = LobbyService.getLobbyJoined(); - vm.visible = vm.lobbyInformation.id; + vm.visible = !!vm.lobbyInformation && vm.lobbyInformation.id; vm.checkVisible(); }); From 08afef2bd9eb426c8ce4702e72d9eb9d7ed06a4e Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 25 Nov 2015 00:39:46 -0500 Subject: [PATCH 10/32] fix clearing the scrollback of a new chatroom --- src/app/shared/comment-box/chat.service.js | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index bbea6acd..ae4b3f65 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -4,7 +4,13 @@ angular.module('tf2stadium.services').factory('ChatService', ChatService); // Persistent map of room id -> messages list - var chatRoomLogs = {}; + var chatRoomLogs = Object.create(null); + function getChatRoom(id) { + if (!angular.isDefined(chatRoomLogs[id])) { + chatRoomLogs[id] = []; + } + return chatRoomLogs[id]; + } function ChatRoom(id) { this.changeRoom(angular.isDefined(id)? id : -1); @@ -13,11 +19,7 @@ ChatRoom.prototype.changeRoom = function chageRoom(id) { if (id !== this.id) { this.id = id; - if (chatRoomLogs.hasOwnProperty(id)) { - this.messages = chatRoomLogs[id]; - } else { - this.messages = chatRoomLogs[id] = []; - } + this.messages = getChatRoom(id); } }; @@ -62,18 +64,14 @@ }); Websocket.onJSON('chatReceive', function (message) { - if (chatRoomLogs.hasOwnProperty(message.room)) { - chatRoomLogs[message.room].push(message); - } else { - chatRoomLogs[message.room] = [message]; - } + getChatRoom(message.room).push(message); }); Websocket.onJSON('chatHistoryClear', function(data) { // Note: ChatRooms may have pointers to the arrays in // chatRoomLogs, so we have to mutate the actual logs rather // than just assign a new empty array. - chatRoomLogs[data.room].length = 0; + getChatRoom(data.room).length = 0; }); return factory; From bbb3c02e674dc5d3b6a1161d6f4fbe74563fe714 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Wed, 25 Nov 2015 15:15:27 -0500 Subject: [PATCH 11/32] retain dev-branch UI behavior on lobby close --- src/app/pages/lobby/lobby.factory.js | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 0f2deab4..b79f872f 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -279,13 +279,6 @@ }); Websocket.onJSON('lobbyClosed', function(data) { - factory.lobbySpectatedId = -1; - if($state.current.name === 'lobby-page') { - $state.go('lobby-list'); - } - $rootScope.$emit('lobby-spectated-updated'); - $rootScope.$emit('lobby-spectated-changed'); - Notifications.toast({message: 'The lobby was closed'}); $rootScope.$emit('lobby-closed'); }); From dbb488f7da21cd180a9672840a0d02677b201dbb Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Thu, 26 Nov 2015 02:51:21 -0500 Subject: [PATCH 12/32] Fix joined lobby chat not working after page load --- src/app/shared/comment-box/comment-box.controller.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index 05fb767c..48f7403e 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -22,7 +22,16 @@ return; } - var room = vm.rooms[vm.currentTab].id; + var tabId = vm.currentTab; + if (tabId === 1 && vm.rooms[1].id === -1) { + // If we're on the main screen, and we're joined in a lobby + // but not spectating one, then the only two visible tabs will + // be general chat and "your lobby" chat, so the 2nd displayed + // tab is the normally 3rd tab + tabId = 2; + } + + var room = vm.rooms[tabId].id; ChatService.send(vm.messageBox, room); vm.messageBox = ''; From d304256549550f8e44d21ada191b2479bb646144 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Thu, 26 Nov 2015 04:13:49 -0500 Subject: [PATCH 13/32] put an asterisk in inactive chat tabs w/ new msgs --- src/app/shared/comment-box/chat.service.js | 1 + .../comment-box/comment-box.controller.js | 59 +++++++++++++++---- src/app/shared/comment-box/comment-box.html | 5 +- 3 files changed, 51 insertions(+), 14 deletions(-) diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index ae4b3f65..d8db1476 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -65,6 +65,7 @@ Websocket.onJSON('chatReceive', function (message) { getChatRoom(message.room).push(message); + $rootScope.$emit('chat-message', message); }); Websocket.onJSON('chatHistoryClear', function(data) { diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index 48f7403e..0fdd9342 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -6,11 +6,54 @@ .controller('CommentBoxController', CommentBoxController); /** @ngInject */ - function CommentBoxController ($rootScope, Websocket, ChatService, Notifications) { + function CommentBoxController ($rootScope, $scope, + ChatService, Notifications) { var vm = this; vm.rooms = ChatService.getRooms(); - vm.currentTab = 0; + vm.lastSeenIds = Object.create(null); + + $scope.currentTab = 0; + + // The three tabs are: + // 0 - global chat + // 1 - spectated lobby chat + // 2 - joined lobby chat + // however, not all these tabs exist at all times, so + // just directly reading currentTab isn't sufficient + function currentTabId() { + var tabId = $scope.currentTab; + if (tabId === 1 && vm.rooms[1].id === -1) { + // If we're on the main screen, and we're joined in a lobby + // but not spectating one, then the only two visible tabs will + // be general chat and "your lobby" chat, so the 2nd displayed + // tab is the normally 3rd tab + tabId = 2; + } + + return tabId; + } + + $rootScope.$on('chat-message', function (e, message) { + var room = message.room; + if (!angular.isDefined(vm.lastSeenIds[room])) { + vm.lastSeenIds[room] = 0; + } + + if (room === vm.rooms[currentTabId()].id) { + vm.lastSeenIds[room] = Math.max(vm.lastSeenIds[room], message.id); + } + }); + + $scope.$watch('currentTab', function (newVal, oldVal) { + console.log('tab', newVal, oldVal, $scope.currentTab); + var room = vm.rooms[currentTabId()]; + var msgs = room.messages; + + if (msgs.length > 0) { + vm.lastSeenIds[room.id] = msgs[msgs.length - 1].id; + } + }); vm.sendMessage = function(event) { if (vm.messageBox === "" || event.keyCode !== 13) { @@ -22,17 +65,7 @@ return; } - var tabId = vm.currentTab; - if (tabId === 1 && vm.rooms[1].id === -1) { - // If we're on the main screen, and we're joined in a lobby - // but not spectating one, then the only two visible tabs will - // be general chat and "your lobby" chat, so the 2nd displayed - // tab is the normally 3rd tab - tabId = 2; - } - - var room = vm.rooms[tabId].id; - ChatService.send(vm.messageBox, room); + ChatService.send(vm.messageBox, vm.rooms[currentTabId()].id); vm.messageBox = ''; event.preventDefault(); diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index f7080119..c688eb0f 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -5,11 +5,14 @@ ng-controller="CommentBoxController as commentBox"> + {{room.messages.length > 0 + && room.messages[room.messages.length - 1].id > commentBox.lastSeenIds[room.id]? + '*' : ''}} {{room.id === 0? 'CHAT' : ((room.joined? 'YOUR':'THIS') + ' Lobby #' + room.id)}} From 32f72241a785901f51155d208b3007d7c9ca3146 Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 19:21:10 +0100 Subject: [PATCH 14/32] Moved spectated lobby leaving logic to LobbyService. --- src/app/pages/lobby/list/lobby-list.controller.js | 4 ---- src/app/pages/lobby/lobby.factory.js | 6 ++++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/pages/lobby/list/lobby-list.controller.js b/src/app/pages/lobby/list/lobby-list.controller.js index 4c25cc4a..acf10de5 100644 --- a/src/app/pages/lobby/list/lobby-list.controller.js +++ b/src/app/pages/lobby/list/lobby-list.controller.js @@ -14,10 +14,6 @@ vm.lobbies = LobbyService.getList(); }); - // When we navigate to the main lobby list page, leave the - // spectator spot for whatever lobby we were just in. - LobbyService.leaveSpectatedLobby(); - vm.join = function (lobby, team, position, event) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index b79f872f..883410bc 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -176,6 +176,12 @@ }, 1000); }; + $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) { + if (fromState.name === 'lobby-page') { + factory.leaveSpectatedLobby(); + } + }); + Websocket.onJSON('lobbyReadyUp', function(data) { $rootScope.$emit('lobby-ready-up'); if (playerPreReady) { From e69a2e71f0da0d225e827eb7a7dc84b3985a3579 Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 19:22:40 +0100 Subject: [PATCH 15/32] LobbyService: removed empty callback. --- src/app/pages/lobby/lobby.factory.js | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 883410bc..ae9881e6 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -119,14 +119,7 @@ 'class': position }; - Websocket.emitJSON('lobbyJoin', payload, function (response) { - if (response.success) { - // lobbyJoin is now handled later in a dedicated lobbyJoin - // event message handler (a separate event, not the response - // to this lobbyJoin request) - // $rootScope.$emit('lobby-joined', lobby); - } - }); + Websocket.emitJSON('lobbyJoin', payload); }; factory.goToLobby = function(lobby) { From 0fe75c4aa2f40fa7748a952a4063ac3dcb670dc3 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Thu, 26 Nov 2015 13:45:24 -0500 Subject: [PATCH 16/32] leave spectator whenever we leave lobby-page state --- src/app/pages/lobby/list/lobby-list.controller.js | 4 ---- src/app/pages/lobby/page/lobby-page.controller.js | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/app/pages/lobby/list/lobby-list.controller.js b/src/app/pages/lobby/list/lobby-list.controller.js index 4c25cc4a..acf10de5 100644 --- a/src/app/pages/lobby/list/lobby-list.controller.js +++ b/src/app/pages/lobby/list/lobby-list.controller.js @@ -14,10 +14,6 @@ vm.lobbies = LobbyService.getList(); }); - // When we navigate to the main lobby list page, leave the - // spectator spot for whatever lobby we were just in. - LobbyService.leaveSpectatedLobby(); - vm.join = function (lobby, team, position, event) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/src/app/pages/lobby/page/lobby-page.controller.js b/src/app/pages/lobby/page/lobby-page.controller.js index 7ea4cc26..43911f18 100644 --- a/src/app/pages/lobby/page/lobby-page.controller.js +++ b/src/app/pages/lobby/page/lobby-page.controller.js @@ -54,6 +54,10 @@ vm.preReadyUpTimer = LobbyService.getPreReadyUpTimer(); }); + $scope.$on("$destroy",function(){ + LobbyService.leaveSpectatedLobby(); + }); + vm.join = function (lobby, team, position) { LobbyService.join(lobby, team, position); }; From aa6d3acac925e1cc9d376cca9b235ee41ba3ad66 Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 22:03:41 +0100 Subject: [PATCH 17/32] LobbyService: removed re-routing on bad request. --- src/app/pages/lobby/lobby.factory.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index ae9881e6..5eba5e8f 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -128,11 +128,7 @@ factory.spectate = function(lobby) { Websocket.emitJSON('lobbySpectatorJoin', {id: lobby}, function(response) { - if (!response.success) { - if($state.current.name === 'lobby-page') { - $state.go('lobby-list'); - } - } else { + if (response.success) { var oldLobbyId = factory.lobbySpectatedId; factory.lobbySpectatedId = lobby; @@ -140,7 +136,7 @@ $rootScope.$emit('lobby-spectated-changed'); } $rootScope.$emit('lobby-spectated-updated'); - } + } }); }; From 3e499047715fb498015adf76ef40253a3f9c5c2d Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 22:08:39 +0100 Subject: [PATCH 18/32] Revert "Moved spectated lobby leaving logic to LobbyService." This reverts commit 32f72241a785901f51155d208b3007d7c9ca3146. --- src/app/pages/lobby/list/lobby-list.controller.js | 4 ++++ src/app/pages/lobby/lobby.factory.js | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/app/pages/lobby/list/lobby-list.controller.js b/src/app/pages/lobby/list/lobby-list.controller.js index acf10de5..4c25cc4a 100644 --- a/src/app/pages/lobby/list/lobby-list.controller.js +++ b/src/app/pages/lobby/list/lobby-list.controller.js @@ -14,6 +14,10 @@ vm.lobbies = LobbyService.getList(); }); + // When we navigate to the main lobby list page, leave the + // spectator spot for whatever lobby we were just in. + LobbyService.leaveSpectatedLobby(); + vm.join = function (lobby, team, position, event) { event.preventDefault(); event.stopImmediatePropagation(); diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 5eba5e8f..f7d3a6d9 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -165,12 +165,6 @@ }, 1000); }; - $rootScope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState) { - if (fromState.name === 'lobby-page') { - factory.leaveSpectatedLobby(); - } - }); - Websocket.onJSON('lobbyReadyUp', function(data) { $rootScope.$emit('lobby-ready-up'); if (playerPreReady) { From 1ad8cef477739e32cd4d623827d0eaf479d515dd Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 23:30:41 +0100 Subject: [PATCH 19/32] Comment-box: add autoselect tab feature, close tf2stadium/qa#13. --- src/app/shared/comment-box/chat.service.js | 2 +- src/app/shared/comment-box/comment-box.controller.js | 8 ++++++-- src/app/shared/comment-box/comment-box.html | 2 ++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/app/shared/comment-box/chat.service.js b/src/app/shared/comment-box/chat.service.js index ae4b3f65..fa953374 100644 --- a/src/app/shared/comment-box/chat.service.js +++ b/src/app/shared/comment-box/chat.service.js @@ -38,7 +38,7 @@ joinedChatRoom.joined = true; - var rooms = [globalChatRoom, spectatedChatRoom, joinedChatRoom]; + var rooms = [globalChatRoom, joinedChatRoom, spectatedChatRoom]; factory.getRooms = function() { return rooms; diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index 05fb767c..997f9929 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -6,10 +6,14 @@ .controller('CommentBoxController', CommentBoxController); /** @ngInject */ - function CommentBoxController ($rootScope, Websocket, ChatService, Notifications) { + function CommentBoxController ($rootScope, Websocket, ChatService, Notifications, $timeout) { var vm = this; - vm.rooms = ChatService.getRooms(); + //The $timeout makes sure the last tab (lobbyJoined tab) + //will get selected on load thanks to md-autoselect + $timeout(function(){ + vm.rooms = ChatService.getRooms(); + }, 0); vm.currentTab = 0; vm.sendMessage = function(event) { diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index f7080119..5d84995e 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -6,6 +6,8 @@ From ff3ba994d9d2ac614a4eda11b8ac1d57937004d4 Mon Sep 17 00:00:00 2001 From: Capu Date: Thu, 26 Nov 2015 23:49:03 +0100 Subject: [PATCH 20/32] LobbyService: don't save useless lobbyData. --- src/app/pages/lobby/lobby.factory.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index f7d3a6d9..28404f52 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -10,8 +10,8 @@ factory.lobbyList = {}; - // map lobby id -> last seen data - factory.lobbyData = Object.create(null); + factory.lobbySpectated = Object.create(null); + factory.lobbyJoined = Object.create(null); factory.lobbySpectatedId = -1; factory.lobbyJoinedId = -1; @@ -38,7 +38,7 @@ // Will return undefined when a lobby is not currently being // spectated factory.getLobbySpectated = function() { - return factory.lobbyData[factory.lobbySpectatedId]; + return factory.lobbySpectated; }; // Will return -1 when a lobby is not currently being @@ -49,6 +49,7 @@ factory.leaveSpectatedLobby = function() { factory.lobbySpectatedId = -1; + factory.lobbySpectated = {}; $rootScope.$emit('lobby-spectated-changed'); $rootScope.$emit('lobby-spectated-updated'); }; @@ -56,7 +57,7 @@ // Will return undefined when not currently joined in any // lobby factory.getLobbyJoined = function() { - return factory.lobbyData[factory.lobbyJoinedId]; + return factory.lobbyJoined; }; // Will return -1 when not currently joined in any @@ -129,6 +130,17 @@ factory.spectate = function(lobby) { Websocket.emitJSON('lobbySpectatorJoin', {id: lobby}, function(response) { if (response.success) { + /* + This code assumes that the only way we'll ever spectate + a lobby is when we asked the backend to let us do it. + + However, the backend might have some ideas of its own and + force us to spectate a lobby (for example, on websocket connection). + + This code needs to be moved to the lobbyData handler, but the backend + is sending us bogus lobbyData on lobbyJoin that makes the page stutter, + so it stays here for the moment. + */ var oldLobbyId = factory.lobbySpectatedId; factory.lobbySpectatedId = lobby; @@ -242,7 +254,7 @@ }); Websocket.onJSON('lobbyData', function(newLobby) { - factory.lobbyData[newLobby.id] = newLobby; + factory.lobbySpectated = newLobby; if (newLobby.id === factory.lobbySpectatedId) { $rootScope.$emit('lobby-spectated-updated'); @@ -255,13 +267,14 @@ Websocket.onJSON('lobbyJoined', function(data) { factory.lobbyJoinedId = data.id; - factory.lobbyData[data.id] = data; + factory.lobbyJoined = data; $rootScope.$emit('lobby-joined'); $rootScope.$emit('lobby-joined-updated'); }); Websocket.onJSON('lobbyLeft', function(data) { factory.lobbyJoinedId = -1; + factory.lobbyJoined = {}; factory.lobbyJoinInformation = {}; $rootScope.$emit('lobby-joined-updated'); $rootScope.$emit('lobby-left'); From 6c9f89e54156db28945b27e50cd659cf1fc0b7a0 Mon Sep 17 00:00:00 2001 From: Capu Date: Sun, 29 Nov 2015 13:39:02 +0100 Subject: [PATCH 21/32] Style: fix :focus outline moving .sheet elements. --- src/scss/main/__helpers.scss | 7 +++++++ src/scss/main/_theme.scss | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/scss/main/__helpers.scss b/src/scss/main/__helpers.scss index 461440ce..af0ab3a2 100644 --- a/src/scss/main/__helpers.scss +++ b/src/scss/main/__helpers.scss @@ -67,6 +67,13 @@ &:not(.flat):focus { @extend %md-whiteframe-z3; + + &:after { + @extend .fill-parent; + content: ''; + border-radius: 3px; + box-sizing: border-box; + } } &.clickable { diff --git a/src/scss/main/_theme.scss b/src/scss/main/_theme.scss index aca06915..64006da2 100644 --- a/src/scss/main/_theme.scss +++ b/src/scss/main/_theme.scss @@ -76,7 +76,7 @@ $themes-list: ( background-color: $hover-color; } - &:not(.flat):focus { + &:not(.flat):focus:after { border: 2px solid $main-color; } } From d3b7628e8ec02366af80e93ce1a03f26c63c2a70 Mon Sep 17 00:00:00 2001 From: Capu Date: Sun, 29 Nov 2015 21:13:32 +0100 Subject: [PATCH 22/32] Comment-box: fix bad controller behavior. --- .../comment-box/comment-box.controller.js | 31 +++++++++---------- src/app/shared/comment-box/comment-box.html | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index cb973859..e54f2aaa 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -14,10 +14,24 @@ //will get selected on load thanks to md-autoselect $timeout(function(){ vm.rooms = ChatService.getRooms(); + + $scope.$watch('currentTab', function (newVal) { + if (angular.isUndefined(newVal)) { + // On initialization, this callback will be called with + // newVal === oldVal === undefined + return; + } + + var room = vm.rooms[currentTabId()]; + var msgs = room.messages; + + if (msgs.length > 0) { + vm.lastSeenIds[room.id] = msgs[msgs.length - 1].id; + } + }); }, 0); vm.lastSeenIds = Object.create(null); - vm.currentTab = 0; // The three tabs are: // 0 - global chat @@ -50,21 +64,6 @@ }); $scope.$on('$destroy', clearChatMessage); - $scope.$watch('currentTab', function (newVal) { - if (angular.isUndefined(newVal)) { - // On initialization, this callback will be called with - // newVal === oldVal === undefined - return; - } - - var room = vm.rooms[currentTabId()]; - var msgs = room.messages; - - if (msgs.length > 0) { - vm.lastSeenIds[room.id] = msgs[msgs.length - 1].id; - } - }); - vm.sendMessage = function (event) { if (vm.messageBox === '' || event.keyCode !== 13) { return; diff --git a/src/app/shared/comment-box/comment-box.html b/src/app/shared/comment-box/comment-box.html index 7fa70b6f..1694f148 100644 --- a/src/app/shared/comment-box/comment-box.html +++ b/src/app/shared/comment-box/comment-box.html @@ -5,7 +5,7 @@ ng-controller="CommentBoxController as commentBox"> From 3946c985005f21844df28996825c2d7863009a0b Mon Sep 17 00:00:00 2001 From: Capu Date: Mon, 30 Nov 2015 20:37:12 +0100 Subject: [PATCH 23/32] Notifications: first draft for sounds. --- bower.json | 3 ++- src/app/app.module.js | 3 ++- src/app/app.notifications.js | 6 +++++- src/app/pages/lobby/lobby.factory.js | 2 ++ 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/bower.json b/bower.json index 5bed4947..411e0c5e 100644 --- a/bower.json +++ b/bower.json @@ -7,8 +7,9 @@ "version": "0.0.0", "dependencies": { "angular": "~1.4.7", - "angular-material": "1.0.0-rc4", "angular-animate": "~1.4.0", + "angular-audio": "~1.7.1", + "angular-material": "1.0.0-rc4", "angular-scroll-glue": "~2.0.6", "angular-ui-router": "~0.2.15", "clipboard": "~1.5.3", diff --git a/src/app/app.module.js b/src/app/app.module.js index ce5b4827..0d51bfff 100644 --- a/src/app/app.module.js +++ b/src/app/app.module.js @@ -6,7 +6,8 @@ 'ngAnimate', 'ui.router', 'ngMaterial', - 'luegg.directives' + 'luegg.directives', + 'ngAudio' ]); angular.module('tf2stadium.services', []); diff --git a/src/app/app.notifications.js b/src/app/app.notifications.js index 432a8450..0ec9bd0e 100644 --- a/src/app/app.notifications.js +++ b/src/app/app.notifications.js @@ -6,7 +6,7 @@ .controller('NotificationsController', NotificationsController); /** @ngInject */ - function NotificationsFactory($mdToast, $document, $timeout, $log) { + function NotificationsFactory($mdToast, $document, $timeout, $log, ngAudio) { var notificationsService = {}; @@ -77,6 +77,10 @@ options.icon = options.icon || '/assets/img/logo-no-text.png'; options.tag = options.tag || 'tf2stadium'; + if (options.soundFile) { + ngAudio.play(options.soundFile); + } + var html5notification = new Notification(options.title, options); if (options.timeout) { diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 594549a3..d9f49884 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -185,6 +185,7 @@ Notifications.notifyBrowser({ title: 'Click here to ready up!', body: 'All the slots are filled, ready up to start', + soundFile: '/assets/sound/lobby-readyup.wav', timeout: 30, callbacks: { onclick: function () { @@ -201,6 +202,7 @@ Notifications.notifyBrowser({ title: 'Lobby is starting!', body: 'Come back to the site to join the server', + soundFile: '/assets/sound/lobby-start.wav', timeout: 5, callbacks: { onclick: function () { From fbffd93a2e2f2875ece7fe8c6f20fce4d2b1b357 Mon Sep 17 00:00:00 2001 From: Capu Date: Mon, 30 Nov 2015 21:17:59 +0100 Subject: [PATCH 24/32] Notifications, Settings: add sound volume settings. --- src/app/app.notifications.js | 2 +- src/app/app.settings.js | 4 ++++ src/app/pages/lobby/lobby.factory.js | 24 ++++++++++++--------- src/app/pages/settings/section-sound.html | 4 ++++ src/app/pages/settings/settings.provider.js | 4 +++- src/scss/main/_theme.scss | 5 +++++ src/scss/pages/settings/_settings.scss | 4 ++++ 7 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 src/app/pages/settings/section-sound.html diff --git a/src/app/app.notifications.js b/src/app/app.notifications.js index 0ec9bd0e..f2427602 100644 --- a/src/app/app.notifications.js +++ b/src/app/app.notifications.js @@ -78,7 +78,7 @@ options.tag = options.tag || 'tf2stadium'; if (options.soundFile) { - ngAudio.play(options.soundFile); + ngAudio.play(options.soundFile).volume = options.soundVolume; } var html5notification = new Notification(options.title, options); diff --git a/src/app/app.settings.js b/src/app/app.settings.js index 14381be4..d4f8c283 100644 --- a/src/app/app.settings.js +++ b/src/app/app.settings.js @@ -53,6 +53,10 @@ dark: {name: 'TF2Stadium Dark', selector: 'dark-theme'} }; + SettingsProvider.constants.sound = { + soundVolume: {name: 'Notifications volume'} + }; + function setDefaultValues() { SettingsProvider.settings.currentTheme = 'default-theme'; diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index d9f49884..baf67ce1 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -6,7 +6,7 @@ /** @ngInject */ function LobbyService($rootScope, $state, $mdDialog, $timeout, $interval, - $window, Websocket, Notifications) { + $window, Websocket, Notifications, Settings) { var factory = {}; factory.lobbyList = {}; @@ -186,6 +186,7 @@ title: 'Click here to ready up!', body: 'All the slots are filled, ready up to start', soundFile: '/assets/sound/lobby-readyup.wav', + soundVolume: settings.soundVolume * 0.01, timeout: 30, callbacks: { onclick: function () { @@ -199,16 +200,19 @@ factory.lobbyJoinInformation = data; $state.go('lobby-page', {lobbyID: factory.lobbySpectated.id}); $rootScope.$emit('lobby-start'); - Notifications.notifyBrowser({ - title: 'Lobby is starting!', - body: 'Come back to the site to join the server', - soundFile: '/assets/sound/lobby-start.wav', - timeout: 5, - callbacks: { - onclick: function () { - $window.focus(); + Settings.getSettings(function (settings) { + Notifications.notifyBrowser({ + title: 'Lobby is starting!', + body: 'Come back to the site to join the server', + soundFile: '/assets/sound/lobby-start.wav', + soundVolume: settings.soundVolume * 0.01, + timeout: 5, + callbacks: { + onclick: function () { + $window.focus(); + } } - } + }); }); }); diff --git a/src/app/pages/settings/section-sound.html b/src/app/pages/settings/section-sound.html new file mode 100644 index 00000000..ee266220 --- /dev/null +++ b/src/app/pages/settings/section-sound.html @@ -0,0 +1,4 @@ +
+

Notification volume

+ +
\ No newline at end of file diff --git a/src/app/pages/settings/settings.provider.js b/src/app/pages/settings/settings.provider.js index 27e43abb..037b8dab 100644 --- a/src/app/pages/settings/settings.provider.js +++ b/src/app/pages/settings/settings.provider.js @@ -12,7 +12,8 @@ */ SettingsPageProvider.sections = [ 'theme', - 'filters' + 'filters', + 'sound' ]; for (var settingSectionKey in SettingsPageProvider.sections) { @@ -40,6 +41,7 @@ var settingsPageService = function (Settings) { settingsPageProvider.sections.theme = Settings.getConstants('themesList'); settingsPageProvider.sections.filters = Settings.getConstants('filters'); + settingsPageProvider.sections.sound = Settings.getConstants('sound'); settingsPageService.getSections = function () { return settingsPageProvider.sections; diff --git a/src/scss/main/_theme.scss b/src/scss/main/_theme.scss index 4746ac5a..c308b565 100644 --- a/src/scss/main/_theme.scss +++ b/src/scss/main/_theme.scss @@ -303,5 +303,10 @@ $themes-list: ( background-color: $sheet-color; } + //SLIDER + .md-thumb-text { + color: white; + } + } } \ No newline at end of file diff --git a/src/scss/pages/settings/_settings.scss b/src/scss/pages/settings/_settings.scss index 03550ce3..68688839 100644 --- a/src/scss/pages/settings/_settings.scss +++ b/src/scss/pages/settings/_settings.scss @@ -8,4 +8,8 @@ @extend .sheet; padding: 0 $padding-medium $padding-medium!important; margin-top: $padding-medium; + + .md-track-ticks { + display: none; + } } \ No newline at end of file From 3d5f560768182e779050796002744441d61444a6 Mon Sep 17 00:00:00 2001 From: Capu Date: Mon, 30 Nov 2015 21:30:13 +0100 Subject: [PATCH 25/32] Settings: added sound test button. --- src/app/pages/settings/section-sound.html | 9 ++++++++- src/app/pages/settings/settings.controller.js | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/pages/settings/section-sound.html b/src/app/pages/settings/section-sound.html index ee266220..fa7c1d90 100644 --- a/src/app/pages/settings/section-sound.html +++ b/src/app/pages/settings/section-sound.html @@ -1,4 +1,11 @@

Notification volume

- + + + + Test sound +
\ No newline at end of file diff --git a/src/app/pages/settings/settings.controller.js b/src/app/pages/settings/settings.controller.js index 26af5a4d..4775c91e 100644 --- a/src/app/pages/settings/settings.controller.js +++ b/src/app/pages/settings/settings.controller.js @@ -6,7 +6,7 @@ .controller('SettingsPageController', SettingsPageController); /** @ngInject */ - function SettingsPageController(SettingsPage, Settings) { + function SettingsPageController(SettingsPage, Settings, ngAudio) { var vm = this; vm.sections = SettingsPage.getSections(); @@ -19,6 +19,12 @@ vm.current = key; }; + vm.playSoundSample = function () { + Settings.getSettings(function (settings) { + ngAudio.play('/assets/sound/lobby-readyup.wav').volume = settings.soundVolume / 100; + }); + }; + /* Iterates through all the settings in the list and compares them to the stored settings. @@ -37,6 +43,7 @@ Settings.getSettings(function (response) { populateFilters(response); + vm.soundVolume = response.soundVolume; }); } From 9ce0ffb9491b587c9cb9e47150cf543636d678cb Mon Sep 17 00:00:00 2001 From: Capu Date: Mon, 30 Nov 2015 21:36:52 +0100 Subject: [PATCH 26/32] LobbyService: fix missing wrapper function. --- src/app/pages/lobby/lobby.factory.js | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index baf67ce1..ec893db6 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -180,20 +180,21 @@ Websocket.emitJSON('playerNotReady', {}); localStorage.setItem('tabCommunication', ''); localStorage.setItem('tabCommunication', 'closeDialog'); - } - ); - Notifications.notifyBrowser({ - title: 'Click here to ready up!', - body: 'All the slots are filled, ready up to start', - soundFile: '/assets/sound/lobby-readyup.wav', - soundVolume: settings.soundVolume * 0.01, - timeout: 30, - callbacks: { - onclick: function () { - $window.focus(); + }); + Settings.getSettings(function (settings) { + Notifications.notifyBrowser({ + title: 'Click here to ready up!', + body: 'All the slots are filled, ready up to start', + soundFile: '/assets/sound/lobby-readyup.wav', + soundVolume: settings.soundVolume * 0.01, + timeout: 30, + callbacks: { + onclick: function () { + $window.focus(); + } } - } - }); + }); + } }); Websocket.onJSON('lobbyStart', function (data) { From dd6053736713b097488faaf4d10ca6140d6a9044 Mon Sep 17 00:00:00 2001 From: Capu Date: Mon, 30 Nov 2015 21:43:28 +0100 Subject: [PATCH 27/32] LobbyService: fixed it 4real. --- src/app/pages/lobby/lobby.factory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index ec893db6..16763a52 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -180,7 +180,7 @@ Websocket.emitJSON('playerNotReady', {}); localStorage.setItem('tabCommunication', ''); localStorage.setItem('tabCommunication', 'closeDialog'); - }); + }); Settings.getSettings(function (settings) { Notifications.notifyBrowser({ title: 'Click here to ready up!', @@ -194,7 +194,7 @@ } } }); - } + }); }); Websocket.onJSON('lobbyStart', function (data) { From 193135c7b40df832842900d1d85c8cafa28c6201 Mon Sep 17 00:00:00 2001 From: gpittarelli Date: Mon, 30 Nov 2015 16:56:55 -0500 Subject: [PATCH 28/32] gulp lint-fix --- src/app/pages/lobby/lobby.factory.js | 16 ++++++++-------- .../shared/comment-box/comment-box.controller.js | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index f49db5db..2fa8b2f1 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -38,7 +38,7 @@ // Will return undefined when a lobby is not currently being // spectated - factory.getLobbySpectated = function() { + factory.getLobbySpectated = function () { return factory.lobbySpectated; }; @@ -57,7 +57,7 @@ // Will return undefined when not currently joined in any // lobby - factory.getLobbyJoined = function() { + factory.getLobbyJoined = function () { return factory.lobbyJoined; }; @@ -148,16 +148,16 @@ $state.go('lobby-page', {lobbyID: lobby}); }; - factory.spectate = function(lobby) { - Websocket.emitJSON('lobbySpectatorJoin', {id: lobby}, function(response) { + factory.spectate = function (lobby) { + Websocket.emitJSON('lobbySpectatorJoin', {id: lobby}, function (response) { if (response.success) { /* This code assumes that the only way we'll ever spectate a lobby is when we asked the backend to let us do it. - + However, the backend might have some ideas of its own and force us to spectate a lobby (for example, on websocket connection). - + This code needs to be moved to the lobbyData handler, but the backend is sending us bogus lobbyData on lobbyJoin that makes the page stutter, so it stays here for the moment. @@ -169,7 +169,7 @@ $rootScope.$emit('lobby-spectated-changed'); } $rootScope.$emit('lobby-spectated-updated'); - } + } }); }; @@ -278,7 +278,7 @@ $rootScope.$emit('lobby-joined-updated'); }); - Websocket.onJSON('lobbyData', function(newLobby) { + Websocket.onJSON('lobbyData', function (newLobby) { factory.lobbySpectated = newLobby; if (newLobby.id === factory.lobbySpectatedId) { diff --git a/src/app/shared/comment-box/comment-box.controller.js b/src/app/shared/comment-box/comment-box.controller.js index e54f2aaa..bb2dcb60 100644 --- a/src/app/shared/comment-box/comment-box.controller.js +++ b/src/app/shared/comment-box/comment-box.controller.js @@ -6,13 +6,13 @@ .controller('CommentBoxController', CommentBoxController); /** @ngInject */ - function CommentBoxController ($rootScope, $scope, $window, $log, $timeout, + function CommentBoxController($rootScope, $scope, $window, $log, $timeout, ChatService, Notifications) { var vm = this; //The $timeout makes sure the last tab (lobbyJoined tab) //will get selected on load thanks to md-autoselect - $timeout(function(){ + $timeout(function (){ vm.rooms = ChatService.getRooms(); $scope.$watch('currentTab', function (newVal) { From aaa44b0e1cb105480dc76e3da2e84befa8a1290c Mon Sep 17 00:00:00 2001 From: Capu Date: Tue, 1 Dec 2015 15:14:32 +0100 Subject: [PATCH 29/32] LobbyService: add lobbySpectatorLeave request. --- src/app/pages/lobby/lobby.factory.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 2fa8b2f1..3d48bce8 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -49,8 +49,13 @@ }; factory.leaveSpectatedLobby = function () { - factory.lobbySpectatedId = -1; - factory.lobbySpectated = {}; + if (factory.lobbySpectatedId === -1) { + return; + } + Websocket.emitJSON('lobbySpectatorLeave', {id: factory.lobbySpectatedId}, function () { + factory.lobbySpectatedId = -1; + factory.lobbySpectated = {}; + }); $rootScope.$emit('lobby-spectated-changed'); $rootScope.$emit('lobby-spectated-updated'); }; From 75e8be95af72594a53870cff1b5eb61d248b7727 Mon Sep 17 00:00:00 2001 From: Capu Date: Tue, 1 Dec 2015 15:23:00 +0100 Subject: [PATCH 30/32] Add home button to navbar. --- src/index.html | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/index.html b/src/index.html index 475c6daa..7c60e5c3 100644 --- a/src/index.html +++ b/src/index.html @@ -59,6 +59,10 @@
+ + Home + {{::$root.userProfile.name}} From 8df0b11f6e9ec87caae1a6ae9d8aa6510b2aa234 Mon Sep 17 00:00:00 2001 From: Capu Date: Tue, 1 Dec 2015 15:28:23 +0100 Subject: [PATCH 31/32] LobbyService: fixed chat tabs not updating. --- src/app/pages/lobby/lobby.factory.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/app/pages/lobby/lobby.factory.js b/src/app/pages/lobby/lobby.factory.js index 3d48bce8..ba0a7add 100644 --- a/src/app/pages/lobby/lobby.factory.js +++ b/src/app/pages/lobby/lobby.factory.js @@ -55,9 +55,9 @@ Websocket.emitJSON('lobbySpectatorLeave', {id: factory.lobbySpectatedId}, function () { factory.lobbySpectatedId = -1; factory.lobbySpectated = {}; + $rootScope.$emit('lobby-spectated-changed'); + $rootScope.$emit('lobby-spectated-updated'); }); - $rootScope.$emit('lobby-spectated-changed'); - $rootScope.$emit('lobby-spectated-updated'); }; // Will return undefined when not currently joined in any From 6d5b777fce7c2ba4947cac398dc5c211f547f47a Mon Sep 17 00:00:00 2001 From: Capu Date: Tue, 1 Dec 2015 20:22:59 +0100 Subject: [PATCH 32/32] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 71a09ac6..41337645 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "license": "GPL-3.0", "repository": "https://github.com/TF2Stadium/Frontend", "readme": "readme.md", - "version": "0.3.0", + "version": "0.3.1", "dependencies": { "del": "~1.2.0", "uglify-save-license": "~0.4.1",