'use strict'; var CommonConsts = require('common/constants'); var Data = require('util/data'); var Socket = require('socket/socket'); var Lobby = require('lobby/lobby'); var Welcome = require('lobby/welcome'); //SOCKET Socket.on('connect', function() { if (!Data.uid || !Data.auth) { Welcome.showSignin(); } }); Socket.on('disconnect', function() { if (Lobby.connectToStart(true)) { window.alert('Disconnected from server, please try joining a game again.'); } }); Socket.on('auth', function(data) { Data.username = data.name; if (data.invalid) { Welcome.showSignin(); } else {
$('#i-chat').on('input', function(event) { setChatState(this.value.length > 0); }); $('#i-chat').on('keydown', function(event) { var key = event.which || event.keyCode || event.charCode; if (key == 13 && this.value.length > 1) { require('socket/action').emit('chat', {msg: this.value}); this.value = ''; setChatState(false); } }); Socket.on('typing', function(data) { App.playerDiv(data, '.typing').toggle(data.on); }); //BUTTONS $('#voice-button').on('click', function() { if (!supportsVoiceChat()) { window.alert('Sorry, voice chat is not available through this browser. Please try using another, such as Google Chrome, if you\'d like to play with voice chat.'); return; } if (webrtc) { $(this).toggleClass('muted'); if ($(this).hasClass('muted')) { webrtc.mute(); } else { webrtc.unmute();
joinGame($(this).data('gid'), 'start'); }); //SOCKET Socket.on('lobby games stats', function(data) { if (data.games) { var hasGame = data.games.length > 0; $('#lobby-open-games').toggle(hasGame); $('#lobby-open-games-empty').toggle(!hasGame); $('#lobby-open-games').html(data.games.reduce(function(combined, game) { return combined + '<li data-gid="'+game.gid+'"><h4>'+game.size+'p Secret Hitler</h4><p>'+game.names+'</p></li>'; }, '')); } if (data.players) { var onlineCount = data.players.online; var showsDetails = onlineCount > 1; $('#lobby-count-details').toggle(showsDetails); if (showsDetails) { $('#lobby-count-playing').text(data.players.playing); $('#lobby-count-lobby').text(data.players.lobby); } $('#lobby-count-online').text(Util.pluralize(onlineCount, 'player')); } }); Socket.on('lobby game data', updateLobby); //PUBLIC