From 690cb6a904787d06e347663223c0e5f474b2d073 Mon Sep 17 00:00:00 2001 From: Imanol Martin Date: Mon, 21 Mar 2016 11:21:30 +0100 Subject: [PATCH] Fixed passing correct user set scopes --- src/cordova/package.json | 2 +- src/cordova/plugin.xml | 2 +- src/cordova/www/cocoon_googleplaygames.js | 2 +- src/js/cocoon_googleplaygames.js | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cordova/package.json b/src/cordova/package.json index 40e62b2..2687a8e 100644 --- a/src/cordova/package.json +++ b/src/cordova/package.json @@ -1,6 +1,6 @@ { "name": "cocoon-plugin-social-android-googleplaygames", - "version": "1.0.7", + "version": "1.0.8", "description": "Android Google Play Games API", "cordova": { "id": "cocoon-plugin-social-android-googleplaygames", diff --git a/src/cordova/plugin.xml b/src/cordova/plugin.xml index cbde99f..b77a1f1 100644 --- a/src/cordova/plugin.xml +++ b/src/cordova/plugin.xml @@ -1,6 +1,6 @@ + id="cocoon-plugin-social-android-googleplaygames" version="1.0.8"> CocoonGooglePlayGames Android Google Play Games API MPL 2.0 diff --git a/src/cordova/www/cocoon_googleplaygames.js b/src/cordova/www/cocoon_googleplaygames.js index bb61879..997a00b 100644 --- a/src/cordova/www/cocoon_googleplaygames.js +++ b/src/cordova/www/cocoon_googleplaygames.js @@ -1 +1 @@ -!function(){window.cordova&&"undefined"!=typeof require&&require("cocoon-plugin-social-common.Social");var e=window.Cocoon;e.define("Cocoon.Social",function(i){function t(e,i){return e=e||{},{access_token:e.access_token,state:e.state,error:i,expires_in:e.expirationDate?e.expirationDate-Date.now():0,player_id:e.playerId}}function a(i){return new e.Social.User(i.playerId,i.displayName,i.avatarImageUrl)}function n(i){var t=i.image?i.image.url:"";return t=t.replace(/sz=\d+/g,"sz=100"),new e.Social.User(i.id,i.displayName,t)}function s(i){return i===e.Social.ImageSize.THUMB?100:i===e.Social.ImageSize.MEDIUM?200:i===e.Social.ImageSize.LARGE?512:void 0}function o(i){var t=new e.Social.Achievement(i.id,i.name,i.description,i.revealedIconUrl,0);return t.gpAchievementData=i,t}function r(i,t){return new e.Social.Score(i.player.playerId,i.scoreValue,i.player.displayName,i.player.avatarImageUrl,t)}return i.GooglePlayGamesExtension=function(){this.serviceName="LDGooglePlayGamesPlugin",this.nativeAvailable=!!window.cordova,this.onSessionChanged=new e.Signal,this.on=this.onSessionChanged.expose(),this.auth=new e.Social.GooglePlayGamesAuthExtension(this),this.client=new e.Social.GooglePlayGamesClientExtension(this),this.defaultScopes=["https://www.googleapis.com/auth/games","https://www.googleapis.com/auth/plus.login"],this.gamesAPI="/games/v1",this.plusAPI="/plus/v1",e.Social.GooglePlayGames=this;var i=this;return this.on("sessionChanged",function(e){i.token=t(e.session,e.error),e.session&&e.session.access_token&&i.client.request({path:i.gamesAPI+"/players/me",callback:function(e){i.currentPlayer=e}})}),this},i.GooglePlayGamesExtension.prototype={token:null,settings:{},socialService:null,currentPlayer:null,initialized:!1,auth:null,client:null,init:function(i,t){if(!i||"object"!=typeof i)throw"Invalid params argument";this.settings=i,this.settings.hasOwnProperty("showAchievementNotifications")||(this.settings.showAchievementNotifications=!0),this.initialized=!0;var a=this;if(this.nativeAvailable)e.exec(this.serviceName,"setListener",[],function(e){a.onSessionChanged.emit("sessionChanged",null,[e])}),e.exec(this.serviceName,"init",[this.settings.clientId],function(e){t&&t(e)});else{var n=function(){gapi.auth.authorize({immediate:!0,scope:a.defaultScopes,client_id:a.settings.clientId},function(e){a.token=e,e&&e.access_token&&a.onSessionChanged.notifyEventListeners(e)}),t&&t()};if(window.gapi)n();else{window.onGapiLoadCallback=function(){window.setTimeout(n,1)};var s=document.createElement("script");s.src="https://apis.google.com/js/client.js?onload=onGapiLoadCallback",document.getElementsByTagName("head")[0].appendChild(s)}}},getSocialInterface:function(){if(!this.initialized)throw"You must call init() before getting the Social Interface";return this.socialService||(this.socialService=new e.Social.SocialServiceGooglePlayGames(this)),this.socialService},getMultiplayerInterface:function(){return e.Multiplayer.GooglePlayGames},share:function(){window.open(this.href,"","menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600")},submitEvent:function(i,t){this.nativeAvailable&&e.exec(this.serviceName,"submitEvent",[i,t],null,null)},loadSavedGame:function(i,t){this.nativeAvailable&&e.exec(this.serviceName,"loadSavedGame",[i],t,t)},writeSavedGame:function(i,t){this.nativeAvailable&&e.exec(this.serviceName,"writeSavedGame",[i],t,t)},showSavedGames:function(i){this.nativeAvailable&&e.exec(this.serviceName,"showSavedGames",[],i,i)}},i.GooglePlayGamesAuthExtension=function(e){return this.extension=e,this},i.GooglePlayGamesAuthExtension.prototype={authorize:function(i,a){var n=this;this.extension.nativeAvailable?e.exec(this.extension.serviceName,"authorize",[i],function(e){n.extension.token=t(e.session,e.error),a&&a(n.extension.token)}):gapi.auth.authorize(i,function(e){n.extension.token=e,n.extension.onSessionChanged.trigger("sessionChanged",[e,e?e.error:null]),a&&a(e)})},disconnect:function(i){this.extension.nativeAvailable?e.exec(this.extension.serviceName,"disconnect",[],i,i):i&&i({error:"Not implemented yet"})},init:function(e){this.extension.nativeAvailable?e():gapi.auth.init(e)},getToken:function(){return this.extension.nativeAvailable?this.extension.token:gapi.auth.getToken()},setToken:function(e){this.extension.nativeAvailable?this.extension.token=e:gapi.auth.setToken(e)}},i.GooglePlayGamesClientExtension=function(e){return this.extension=e,this},i.GooglePlayGamesClientExtension.prototype={setApiKey:function(e){this.extension.nativeAvailable||gapi.client.setApiKey(e)},request:function(i){if(this.extension.nativeAvailable){if(i.callback){var t=i.callback;return delete i.callback,e.exec(this.extension.serviceName,"request",[i],function(e){var t=e.response;e.error&&(t=e.response||{},t.error=e.error),i.callback(t)}),i.callback=t,null}var a=this;return{execute:function(t){e.exec(a.extension.serviceName,"request",[i],function(e){var i=e.response;e.error&&(i=e.response||{},i.error=e.error),t(i)})}}}return gapi.client.request(i)}},i.GooglePlayGames=new i.GooglePlayGamesExtension,i.SocialServiceGooglePlayGames=function(i){e.Social.SocialServiceGooglePlayGames.superclass.constructor.call(this),this.gapi=i;var t=this;return this.gapi.on("sessionChanged",function(e){var i=e.session||{};t.onLoginStatusChanged.emit("loginStatusChanged",null,[!!i.access_token,e.error])}),this},i.SocialServiceGooglePlayGames.prototype={isLoggedIn:function(){return this.gapi.token&&this.gapi.token.access_token?!0:!1},login:function(e){var i=this;this.gapi.auth.authorize({client_id:this.gapi.settings.clientId,scope:this.gapi.defaultScopes},function(t){e&&e(i.isLoggedIn(),t.error)})},logout:function(e){this.gapi.auth.disconnect(e)},getLoggedInUser:function(){return this.gapi.currentPlayer?a(this.gapi.currentPlayer):null},requestUser:function(e,i){var t=i||"me";this.gapi.client.request({path:this.gapi.gamesAPI+"/players/"+t,callback:function(i){var t=i&&!i.error?a(i):null;e(t,i.error)}})},requestUserImage:function(i,t,a){this.requestUser(function(t,n){if(t&&t.userImage){var o=s(a||e.Social.ImageSize.MEDIUM);-1===t.userImage.indexOf("sz=")?t.userImage+="?sz="+o:t.userImage=t.userImage.replace(/sz=\d+/g,"sz="+o)}i(t?t.userImage:null,n)},t)},requestFriends:function(e,i){var t={orderBy:"best"},a=i||"me";this.gapi.client.request({path:this.gapi.plusAPI+"/people/"+a+"/people/visible",params:t,callback:function(i){if(i&&!i.error){for(var t=[],a=0;a0){var n=t.items[0],s=new e.Social.Score(a,parseInt(n.scoreValue),"","",n.leaderboard_id);i(s,null)}else i(null,null)}})},submitScore:function(e,i,t){t=t||{};var a=t.leaderboardID||this.gapi.settings.defaultLeaderboard;if(!a)throw"leaderboardID not provided in the params. You can also set the default leaderboard in the init method";this.gapi.client.request({path:this.gapi.gamesAPI+"/leaderboards/"+a+"/scores",method:"POST",params:{score:e},callback:function(e){i&&i(e?e.error:null)}})},showLeaderboard:function(i,t){t=t||{};var a=t.leaderboardID||"";if(this.gapi.nativeAvailable){var n=t.timeScope||0;e.exec(this.gapi.serviceName,"showLeaderboard",[a,n],i,i)}else{if(!this._leaderboardsTemplate)throw"Please, provide a html template for leaderboards with the setTemplates method";var s=new e.Widget.WebDialog,o=!1;s.show(this._leaderboardsTemplate,function(e){s.closed=!0,!o&&i&&i(e)});var l=t.friends?"SOCIAL":"PUBLIC",c="ALL_TIME";t.timeScope===e.Social.TimeScope.WEEK?c="WEEKLY":t.timeScope===e.Social.TimeScope.TODAY&&(c="DAILY"),this.gapi.client.request({path:this.gapi.gamesAPI+"/leaderboards/"+a+"/window/"+l,method:"GET",params:{timeSpan:c},callback:function(e){if(!s.closed){if(e.error)return void(i&&(o=!0,i(e.error),s.close()));var t=[],n=[];e&&e.items&&(n=e.items.slice(0)),e&&e.playerScore&&n.push(e.playerScore);for(var l=0;l0){var n=t.items[0],s=new e.Social.Score(a,parseInt(n.scoreValue),"","",n.leaderboard_id);i(s,null)}else i(null,null)}})},submitScore:function(e,i,t){t=t||{};var a=t.leaderboardID||this.gapi.settings.defaultLeaderboard;if(!a)throw"leaderboardID not provided in the params. You can also set the default leaderboard in the init method";this.gapi.client.request({path:this.gapi.gamesAPI+"/leaderboards/"+a+"/scores",method:"POST",params:{score:e},callback:function(e){i&&i(e?e.error:null)}})},showLeaderboard:function(i,t){t=t||{};var a=t.leaderboardID||"";if(this.gapi.nativeAvailable){var n=t.timeScope||0;e.exec(this.gapi.serviceName,"showLeaderboard",[a,n],i,i)}else{if(!this._leaderboardsTemplate)throw"Please, provide a html template for leaderboards with the setTemplates method";var s=new e.Widget.WebDialog,o=!1;s.show(this._leaderboardsTemplate,function(e){s.closed=!0,!o&&i&&i(e)});var l=t.friends?"SOCIAL":"PUBLIC",c="ALL_TIME";t.timeScope===e.Social.TimeScope.WEEK?c="WEEKLY":t.timeScope===e.Social.TimeScope.TODAY&&(c="DAILY"),this.gapi.client.request({path:this.gapi.gamesAPI+"/leaderboards/"+a+"/window/"+l,method:"GET",params:{timeSpan:c},callback:function(e){if(!s.closed){if(e.error)return void(i&&(o=!0,i(e.error),s.close()));var t=[],n=[];e&&e.items&&(n=e.items.slice(0)),e&&e.playerScore&&n.push(e.playerScore);for(var l=0;l