app/assets/javascripts/presence_game.js.erb in social_stream-presence-0.13.1 vs app/assets/javascripts/presence_game.js.erb in social_stream-presence-0.13.2

- old
+ new

@@ -38,12 +38,16 @@ ///////////////////////////////// // CORE METHODS // ///////////////////////////////// - var init = function(myConnection){ - P.GAME.COMUNICATION.init(myConnection); + var init = function(){ + var enable = '<%=SocialStream::Presence.games%>'; + if(enable=="true"){ + P.GAME.INTERFACE.enableGameFeature(true); + P.GAME.COMUNICATION.init(PRESENCE.XMPPClient.getConnection()); + } }; var requestUserToPlay = function (slug,game){ if(game==null){ @@ -54,20 +58,20 @@ var gameStatus = contactsInfo[slug].gameStatus; } else { var gameStatus = null; } - if(! isUserConnected()){ + if(! PRESENCE.XMPPClient.isUserConnected()){ P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.offline")); if(gameStatus!=null){ contactsInfo[slug].gameStatus = "disconnected"; } return; } - if(! isSlugChatConnected(slug)){ - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.guestOffline", {name: getNameFromSlug(slug)})); + if(! PRESENCE.UIMANAGER.isSlugChatConnected(slug)){ + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.guestOffline", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); if(gameStatus!=null){ contactsInfo[slug].gameStatus = "disconnected"; } return; } @@ -140,36 +144,44 @@ } if(response=="yes"){ contactsInfo[slug].gameStatus = "playing"; P.GAME.INTERFACE.updateInterfaceBeforeStartGame(slug,contactsInfo[slug].game) } else if (response=="no"){ - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejected", {name: getNameFromSlug(slug)})); + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejected", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); contactsInfo[slug].gameStatus="disconnected"; } else if (response=="busy"){ - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejectedBusy", {name: getNameFromSlug(slug)})); + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.rejectedBusy", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); contactsInfo[slug].gameStatus="disconnected"; } else { - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.unknown", {name: getNameFromSlug(slug)})); + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.unknown", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); contactsInfo[slug].gameStatus="disconnected"; } } var updateLogicAfterReceivedGameRequestCancelation = function(slug,status){ if(slug in contactsInfo){ if (status == "finish") { if (contactsInfo[slug].gameStatus == "pending") { - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.cancel", {name: getNameFromSlug(slug)})); + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.cancel", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); contactsInfo[slug].gameStatus = "disconnected"; } else if (contactsInfo[slug].gameStatus == "playing") { - P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.finish", {name: getNameFromSlug(slug)})); + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug, I18n.t("chat.game.finish", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); contactsInfo[slug].gameStatus = "disconnected"; } } } else { finishGame(slug); } } + + var updateLogicAfterReceivedGameRequestError = function(slug){ + if(contactsInfo[slug].gameStatus!="waiting"){ + return true; + } + P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,I18n.t("chat.game.clientIssue", {name: PRESENCE.XMPPClient.getNameFromSlug(slug)})); + contactsInfo[slug].gameStatus="disconnected"; + } var getPlayerNameWithId = function(slug){ if(! slug in contactsInfo){ var game = contactsInfo[slug].game if((game!=null)&&(game.players!=null)){ @@ -249,17 +261,17 @@ var msg = "StartPlay error with reason: " + validationResult.reason; P.GAME.INTERFACE.updateInterfaceOnInformationMessage(slug,msg); return; } } else { - log("Warning: Missed " + game.name + " validateParams method") + PRESENCE.UTILITIES.log("Warning: Missed " + game.name + " validateParams method") } if(typeof PRESENCE.GAME[game.id].minimumRequirements == "function"){ //Check requirements } else { - log("Warning: Missed " + game.name + " minRequirements method") + PRESENCE.UTILITIES.log("Warning: Missed " + game.name + " minRequirements method") } //Add handler and remove previous if exits if(game.handler!=null){ PRESENCE.GAME.COMUNICATION.removeHandler(game.handler) @@ -299,19 +311,20 @@ finishGame(slug) } return { init: init, - game: game, - player: player, - startGame: startGame, - finishGame: finishGame, - createValidationResult: createValidationResult, - requestUserToPlay: requestUserToPlay, - responseUserToPlay: responseUserToPlay, - updateLogicAfterReceivedGameRequest: updateLogicAfterReceivedGameRequest, - updateLogicAfterReceivedGameRequestCancelation: updateLogicAfterReceivedGameRequestCancelation, - updateLogicAfterReceivedGameRequestResponse: updateLogicAfterReceivedGameRequestResponse, + game : game, + player : player, + startGame : startGame, + finishGame : finishGame, + createValidationResult : createValidationResult, + requestUserToPlay : requestUserToPlay, + responseUserToPlay : responseUserToPlay, + updateLogicAfterReceivedGameRequest : updateLogicAfterReceivedGameRequest, + updateLogicAfterReceivedGameRequestCancelation : updateLogicAfterReceivedGameRequestCancelation, + updateLogicAfterReceivedGameRequestResponse : updateLogicAfterReceivedGameRequestResponse, + updateLogicAfterReceivedGameRequestError : updateLogicAfterReceivedGameRequestError, sendAction: sendAction, userDisconnected: userDisconnected }; }) (PRESENCE, jQuery);