diff --git a/deploy/node/package-lock.json b/deploy/node/package-lock.json index 318c7e3..979a8bf 100644 --- a/deploy/node/package-lock.json +++ b/deploy/node/package-lock.json @@ -1,6 +1,6 @@ { "name": "braincloud", - "version": "4.1.0", + "version": "4.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/deploy/node/package.json b/deploy/node/package.json index 8e6cc29..dc52ef7 100644 --- a/deploy/node/package.json +++ b/deploy/node/package.json @@ -1,6 +1,6 @@ { "name": "braincloud", - "version": "4.1.0", + "version": "4.3.0", "description": " brainCloud client for NodeJS", "main": "index.js", "react-native": "react-native.js", diff --git a/deploy/node/react-native.js b/deploy/node/react-native.js index 2c157cc..affa12d 100644 --- a/deploy/node/react-native.js +++ b/deploy/node/react-native.js @@ -1,7 +1,7 @@ -// Set up AsyncStorage. +//Set up AsyncStorage. var AsyncStorage = null; try { - AsyncStorage = require('@react-native-community/async-storage').default + AsyncStorage = useReactModule('@react-native-community/async-storage') } catch (er) { AsyncStorage = { getItem: function () { }, @@ -13,12 +13,18 @@ try { var BackgroundTimer = null; var customSetInterval = null; try { - BackgroundTimer = require('react-native-background-timer').default; + BackgroundTimer = useReactModule('react-native-background-timer') customSetInterval = function (func, interval) { BackgroundTimer.setInterval(func, interval); }; } catch (e) { customSetInterval = null; } +//Browserify processes only require() calls with literals, i.e. require('theplugin'); It will not include modules that can be required with functions. +//this is key because if you use regular requires, it will alwyas argue that the module is missing if it is not there and directed by a relative path. +function useReactModule(moduleName) { + require(moduleName).default; +} + /* * BrainCloudClient expect localStorage to be available as a * synchronous API, this will simulate the minimum required diff --git a/src/brainCloudBase.js b/src/brainCloudBase.js index da34111..db25691 100644 --- a/src/brainCloudBase.js +++ b/src/brainCloudBase.js @@ -20,7 +20,7 @@ function BrainCloudManager () bcm._rewardCallback = null; bcm._errorCallback = null; bcm._jsonedQueue = ""; - bcm._idleTimeout = 30; + bcm._idleTimeout = 120; bcm._heartBeatIntervalId = null; bcm._bundlerIntervalId = null; diff --git a/src/brainCloudClient-authentication.js b/src/brainCloudClient-authentication.js index 9d65268..2ef14e4 100644 --- a/src/brainCloudClient-authentication.js +++ b/src/brainCloudClient-authentication.js @@ -34,6 +34,7 @@ function BCAuthentication() { bc.authentication.AUTHENTICATION_TYPE_TWITTER = "Twitter"; bc.authentication.AUTHENTICATION_TYPE_PARSE = "Parse"; bc.authentication.AUTHENTICATION_TYPE_HANDOFF = "Handoff"; + bc.authentication.AUTHENTICATION_TYPE_SETTOP_HANDOFF = "SettopHandoff"; bc.authentication.profileId = ""; bc.authentication.anonymousId = ""; @@ -486,6 +487,25 @@ function BCAuthentication() { callback); }; + /** + * Authenticate a user with handoffCode + * + * Service Name - authenticationV2 + * Service Operation - AUTHENTICATE + * + * @param callback The method to be invoked when the server response is received + * + */ + bc.authentication.authenticateSettopHandoff= function(handoffCode, callback) { + bc.authentication.authenticate( + handoffCode, + "", + bc.authentication.AUTHENTICATION_TYPE_SETTOP_HANDOFF, + null, + false, + callback); + }; + /** Method allows a caller to authenticate with bc. Note that * callers should use the other authenticate methods in this class as * they incorporate the appropriate authenticationType and use better diff --git a/src/brainCloudClient-gamification.js b/src/brainCloudClient-gamification.js index 86e1c1c..80bed3e 100644 --- a/src/brainCloudClient-gamification.js +++ b/src/brainCloudClient-gamification.js @@ -241,6 +241,8 @@ function BCGamification() { }; /** + * @deprecated + * * Resets the specified milestones' statuses to LOCKED. * * Service Name - Gamification diff --git a/src/brainCloudClient-group.js b/src/brainCloudClient-group.js index 53e103f..fe17078 100644 --- a/src/brainCloudClient-group.js +++ b/src/brainCloudClient-group.js @@ -10,6 +10,7 @@ function BCGroup() { bc.group.OPERATION_ADD_GROUP_MEMBER = "ADD_GROUP_MEMBER"; bc.group.OPERATION_APPROVE_GROUP_JOIN_REQUEST = "APPROVE_GROUP_JOIN_REQUEST"; bc.group.OPERATION_AUTO_JOIN_GROUP = "AUTO_JOIN_GROUP"; + bc.group.OPERATION_AUTO_JOIN_GROUP_MULTI = "AUTO_JOIN_GROUP_MULTI"; bc.group.OPERATION_CANCEL_GROUP_INVITATION = "CANCEL_GROUP_INVITATION"; bc.group.OPERATION_CREATE_GROUP = "CREATE_GROUP"; bc.group.OPERATION_CREATE_GROUP_ENTITY = "CREATE_GROUP_ENTITY"; @@ -154,6 +155,34 @@ function BCGroup() { }); }; + /** + * Find and join an open group in the pool of groups in multiple group types provided as input arguments. + * + * Service Name - group + * Service Operation - AUTO_JOIN_GROUP + * + * @param groupTypes Name of the associated group type. + * @param autoJoinStrategy Selection strategy to employ when there are multiple matches + * @param where Query parameters (optional) + * @param callback The method to be invoked when the server response is received + */ + bc.group.autoJoinGroupMulti = function(groupTypes, autoJoinStrategy, where, callback) { + var message = { + groupTypes : groupTypes, + autoJoinStrategy : autoJoinStrategy + }; + + if(where) message.where = where; + + bc.brainCloudManager.sendRequest({ + service : bc.SERVICE_GROUP, + operation : bc.group.OPERATION_AUTO_JOIN_GROUP_MULTI, + data : message, + callback : callback + }); + }; + + /** * Cancel an outstanding invitation to the group. * diff --git a/src/brainCloudClient-social-leaderboards.js b/src/brainCloudClient-social-leaderboards.js index 50af648..5e0f94d 100644 --- a/src/brainCloudClient-social-leaderboards.js +++ b/src/brainCloudClient-social-leaderboards.js @@ -31,8 +31,7 @@ function BCSocialLeaderboard() { bc.socialLeaderboard.OPERATION_REMOVE_GROUP_SCORE = "REMOVE_GROUP_SCORE"; bc.socialLeaderboard.OPERATION_GET_GROUP_LEADERBOARD_VIEW = "GET_GROUP_LEADERBOARD_VIEW"; bc.socialLeaderboard.OPERATION_GET_GROUP_LEADERBOARD_VIEW_BY_VERSION = "GET_GROUP_LEADERBOARD_VIEW_BY_VERSION"; - - + bc.socialLeaderboard.OPERATION_POST_SCORE_TO_DYNAMIC_GROUP_LEADERBOARD = "POST_GROUP_SCORE_DYNAMIC" @@ -741,6 +740,42 @@ function BCSocialLeaderboard() { callback : callback }); } + + /** + * Post the group score to the given group leaderboard and dynamically create if necessary. LeaderboardType, rotationType, rotationReset, and retainedCount are required. * + * Service Name - leaderboard + * Service Operation - POST_SCORE_TO_DYNAMIC_GROUP_LEADERBOARD + * + * @param leaderboardId the id of the leaderboard + * @param groupId the group's id + * @param score the sort order + * @param data extra data + * @param leaderboardType the type + * @param rotationType the type of tournamnet rotation + * @param rotationResetTime how often to reset + * @param retainedCount + * @param callback The method to be invoked when the server response is received + */ + bc.socialLeaderboard.postScoreToDynamicGroupLeaderboard = function(leaderboardId, groupId, score, data, leaderboardType, rotationType, rotationResetTime, retainedCount, callback) { + var message = { + leaderboardId : leaderboardId, + groupId : groupId, + score : score, + data : data, + leaderboardType : leaderboardType, + rotationType : rotationType, + rotationResetTime : rotationResetTime, + retainedCount : retainedCount + }; + + bc.brainCloudManager.sendRequest({ + service : bc.SERVICE_LEADERBOARD, + operation : bc.socialLeaderboard.OPERATION_POST_SCORE_TO_DYNAMIC_GROUP_LEADERBOARD, + data : message, + callback : callback + }); + } + } BCSocialLeaderboard.apply(window.brainCloudClient = window.brainCloudClient || {}); diff --git a/src/brainCloudClient.js b/src/brainCloudClient.js index 548e324..b0fc8b1 100644 --- a/src/brainCloudClient.js +++ b/src/brainCloudClient.js @@ -1,444 +1,444 @@ -//---------------------------------------------------- -// brainCloud client source code -// Copyright 2016 bitHeads, inc. -//---------------------------------------------------- - -function BrainCloudClient() { - var bcc = this; - - bcc.name = "BrainCloudClient"; - - // If this is not the singleton, initialize it - if(window.brainCloudClient !== bcc) { - BCAbTest.apply(bcc); - BCAsyncMatch.apply(bcc); - BCAuthentication.apply(bcc); - BCChat.apply(bcc); - BCDataStream.apply(bcc); - BCEntity.apply(bcc); - BCEvents.apply(bcc); - BCFile.apply(bcc); - BCFriend.apply(bcc); - BCGamification.apply(bcc); - BCGlobalApp.apply(bcc); - BCGlobalStatistics.apply(bcc); - BCGlobalEntity.apply(bcc); - BCGroup.apply(bcc); - BCIdentity.apply(bcc); - BCItemCatalog.apply(bcc); - BCUserItems.apply(bcc); - BCLobby.apply(bcc); - BCMail.apply(bcc); - BCMatchMaking.apply(bcc); - BCMessaging.apply(bcc); - BCOneWayMatch.apply(bcc); - BCPlaybackStream.apply(bcc); - BCPlayerState.apply(bcc); - BCPlayerStatistics.apply(bcc); - BCPlayerStatisticsEvent.apply(bcc); - BCPresence.apply(bcc); - BCProducts.apply(bcc); - BCVirtualCurrency.apply(bcc); - BCAppStore.apply(bcc); - BCProfanity.apply(bcc); - BCPushNotifications.apply(bcc); - BCReasonCodes.apply(bcc); - BCRedemptionCodes.apply(bcc); - BCRTT.apply(bcc); - BCS3Handler.apply(bcc); - BCScript.apply(bcc); - BCSocialLeaderboard.apply(bcc); - BCStatusCodes.apply(bcc); - BCTime.apply(bcc); - BCTournament.apply(bcc); - BCCustomEntity.apply(bcc); - - bcc.brainCloudManager = new BrainCloudManager(); - bcc.brainCloudRttComms = new BrainCloudRttComms(this); - - bcc.brainCloudManager.abtests = bcc.abtests; - bcc.brainCloudManager.asyncMatch = bcc.asyncMatch; - bcc.brainCloudManager.authentication = bcc.authentication; - bcc.brainCloudManager.chat = bcc.chat; - bcc.brainCloudManager.dataStream = bcc.dataStream; - bcc.brainCloudManager.entity = bcc.entity; - bcc.brainCloudManager.event = bcc.event; - bcc.brainCloudManager.file = bcc.file; - bcc.brainCloudManager.friend = bcc.friend; - bcc.brainCloudManager.gamification = bcc.gamification; - bcc.brainCloudManager.globalApp = bcc.globalApp; - bcc.brainCloudManager.globalStatistics = bcc.globalStatistics; - bcc.brainCloudManager.globalEntity = bcc.globalEntity; - bcc.brainCloudManager.group = bcc.group; - bcc.brainCloudManager.identity = bcc.identity; - bcc.brainCloudManager.lobby = bcc.lobby; - bcc.brainCloudManager.mail = bcc.mail; - bcc.brainCloudManager.matchMaking = bcc.matchMaking; - bcc.brainCloudManager.messaging = bcc.messaging; - bcc.brainCloudManager.oneWayMatch = bcc.oneWayMatch; - bcc.brainCloudManager.playbackStream = bcc.playbackStream; - bcc.brainCloudManager.playerState = bcc.playerState; - bcc.brainCloudManager.playerStatistics = bcc.playerStatistics; - bcc.brainCloudManager.playerStatisticsEvent = bcc.playerStatisticsEvent; - bcc.brainCloudManager.presence = bcc.precense; - bcc.brainCloudManager.product = bcc.product; - bcc.brainCloudManager.virtualCurrency = bcc.virtualCurrency; - bcc.brainCloudManager.appStore = bcc.appStore; - bcc.brainCloudManager.profanity = bcc.profanity; - bcc.brainCloudManager.pushNotification = bcc.pushNotification; - bcc.brainCloudManager.reasonCodes = bcc.reasonCodes; - bcc.brainCloudManager.redemptionCode = bcc.redemptionCode; - bcc.brainCloudManager.rttService = bcc.rttService; - bcc.brainCloudManager.s3Handling = bcc.s3Handling; - bcc.brainCloudManager.script = bcc.script; - bcc.brainCloudManager.socialLeaderboard = bcc.socialLeaderboard; - bcc.brainCloudManager.statusCodes = bcc.statusCodes; - bcc.brainCloudManager.time = bcc.time; - bcc.brainCloudManager.tournament = bcc.tournament; - bcc.brainCloudManager.itemCatalog = bcc.itemCatalog; - bcc.brainCloudManager.userItems = bcc.userItems; - bcc.brainCloudManager.customEntity = bcc.customEntity; - - bcc.brainCloudRttComms.rtt = bcc.rtt; - bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference - - } else { - bcc.brainCloudManager = window.brainCloudManager = window.brainCloudManager || {}; - bcc.brainCloudRttComms = window.brainCloudRttComms = window.brainCloudRttComms || {}; - - bcc.brainCloudClient = window.brainCloudClient = window.brainCloudClient || {}; - - bcc.brainCloudManager.abtests = bcc.brainCloudClient.abtests = bcc.brainCloudClient.abtests || {}; - bcc.brainCloudManager.asyncMatch = bcc.brainCloudClient.asyncMatch = bcc.brainCloudClient.asyncMatch || {}; - bcc.brainCloudManager.authentication = bcc.brainCloudClient.authentication = bcc.brainCloudClient.authentication || {}; - bcc.brainCloudManager.chat = bcc.brainCloudClient.chat = bcc.brainCloudClient.chat || {}; - bcc.brainCloudManager.dataStream = bcc.brainCloudClient.dataStream = bcc.brainCloudClient.dataStream || {}; - bcc.brainCloudManager.entity = bcc.brainCloudClient.entity = bcc.brainCloudClient.entity || {}; - bcc.brainCloudManager.event = bcc.brainCloudClient.event = bcc.brainCloudClient.event || {}; - bcc.brainCloudManager.file = bcc.brainCloudClient.file = bcc.brainCloudClient.file || {}; - bcc.brainCloudManager.friend = bcc.brainCloudClient.friend = bcc.brainCloudClient.friend || {}; - bcc.brainCloudManager.gamification = bcc.brainCloudClient.gamification = bcc.brainCloudClient.gamification || {}; - bcc.brainCloudManager.globalApp = bcc.brainCloudClient.globalApp = bcc.brainCloudClient.globalApp || {}; - bcc.brainCloudManager.globalStatistics = bcc.brainCloudClient.globalStatistics = bcc.brainCloudClient.globalStatistics || {}; - bcc.brainCloudManager.globalEntity = bcc.brainCloudClient.globalEntity = bcc.brainCloudClient.globalEntity || {}; - bcc.brainCloudManager.group = bcc.brainCloudClient.group = bcc.brainCloudClient.group || {}; - bcc.brainCloudManager.identity = bcc.brainCloudClient.identity = bcc.brainCloudClient.identity || {}; - bcc.brainCloudManager.lobby = bcc.brainCloudClient.lobby = bcc.brainCloudClient.lobby || {}; - bcc.brainCloudManager.mail = bcc.brainCloudClient.mail = bcc.brainCloudClient.mail || {}; - bcc.brainCloudManager.matchMaking = bcc.brainCloudClient.matchMaking = bcc.brainCloudClient.matchMaking || {}; - bcc.brainCloudManager.messaging = bcc.brainCloudClient.messaging = bcc.brainCloudClient.messaging || {}; - bcc.brainCloudManager.oneWayMatch = bcc.brainCloudClient.oneWayMatch = bcc.brainCloudClient.oneWayMatch || {}; - bcc.brainCloudManager.playbackStream = bcc.brainCloudClient.playbackStream = bcc.brainCloudClient.playbackStream || {}; - bcc.brainCloudManager.playerState = bcc.brainCloudClient.playerState = bcc.brainCloudClient.playerState || {}; - bcc.brainCloudManager.playerStatistics = bcc.brainCloudClient.playerStatistics = bcc.brainCloudClient.playerStatistics || {}; - bcc.brainCloudManager.playerStatisticsEvent = bcc.brainCloudClient.playerStatisticsEvent = bcc.brainCloudClient.playerStatisticsEvent || {}; - bcc.brainCloudManager.presence = bcc.brainCloudClient.presence = bcc.brainCloudClient.presence || {}; - bcc.brainCloudManager.product = bcc.brainCloudClient.product = bcc.brainCloudClient.product || {}; - bcc.brainCloudManager.virtualCurrency = bcc.brainCloudClient.virtualCurrency = bcc.brainCloudClient.virtualCurrency || {}; - bcc.brainCloudManager.appStore = bcc.brainCloudClient.appStore = bcc.brainCloudClient.appStore || {}; - bcc.brainCloudManager.profanity = bcc.brainCloudClient.profanity = bcc.brainCloudClient.profanity || {}; - bcc.brainCloudManager.pushNotification = bcc.brainCloudClient.pushNotification = bcc.brainCloudClient.pushNotification || {}; - bcc.brainCloudManager.reasonCodes = bcc.brainCloudClient.reasonCodes = bcc.brainCloudClient.reasonCodes || {}; - bcc.brainCloudManager.redemptionCode = bcc.brainCloudClient.redemptionCode = bcc.brainCloudClient.redemptionCode || {}; - bcc.brainCloudManager.rttService = bcc.brainCloudClient.rttService = bcc.brainCloudClient.rttService || {}; - bcc.brainCloudManager.s3Handling = bcc.brainCloudClient.s3Handling = bcc.brainCloudClient.s3Handling || {}; - bcc.brainCloudManager.script = bcc.brainCloudClient.script = bcc.brainCloudClient.script || {}; - bcc.brainCloudManager.socialLeaderboard = bcc.brainCloudClient.socialLeaderboard = bcc.brainCloudClient.socialLeaderboard || {}; - bcc.brainCloudManager.statusCodes = bcc.brainCloudClient.statusCodes = bcc.brainCloudClient.statusCodes || {}; - bcc.brainCloudManager.time = bcc.brainCloudClient.time = bcc.brainCloudClient.time || {}; - bcc.brainCloudManager.tournament = bcc.brainCloudClient.tournament = bcc.brainCloudClient.tournament || {}; - bcc.brainCloudManager.itemCatalog = bcc.brainCloudClient.itemCatalog = bcc.brainCloudClient.itemCatalog || {}; - bcc.brainCloudManager.userItems = bcc.brainCloudClient.userItems = bcc.brainCloudClient.userItems || {}; - bcc.brainCloudManager.customEntity = bcc.brainCloudClient.customEntity = bcc.brainCloudClient.customEntity || {}; - - bcc.brainCloudRttComms.rtt = bcc.brainCloudClient.rtt = bcc.brainCloudClient.rtt || {}; - bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference - } - - - bcc.version = "4.1.3"; - bcc.countryCode; - bcc.languageCode; - - /** - * Initializes the brainCloud client with your app information. This method - * must be called before any API method is invoked. - * - * @param {string} - * appId - The app id - * @param {string} - * secret - The app secret - * @param {string} - * version - The app version (e.g. "1.0.0"). - */ - bcc.initialize = function(appId, secret, appVersion) { - function isBlank(str) { - return (!str || /^\s*$/.test(str)); - }; - - var error = null; - if (isBlank(secret)) - error = "secret was null or empty"; - else if (isBlank(appId)) - error = "appId was null or empty"; - else if (isBlank(appVersion)) - error = "appVersion was null or empty"; - if (error != null) { - console.log("ERROR | Failed to initialize brainCloud - " + error); - return; - } - - bcc.brainCloudManager.initialize(appId, secret, appVersion); - }; - - bcc.initializeWithApps = function(defaultAppId, secretMap, appVersion) { - function isBlank(str) { - return (!str || /^\s*$/.test(str)); - }; - - var appId = defaultAppId; - var secret = secretMap[appId]; - - var error = null; - if (isBlank(secret)) - error = "secret was null or empty"; - else if (isBlank(appId)) - error = "appId was null or empty"; - else if (isBlank(appVersion)) - error = "appVersion was null or empty"; - if (error != null) { - console.log("ERROR | Failed to initialize brainCloud - " + error); - return; - } - - bcc.brainCloudManager.initializeWithApps(defaultAppId, secretMap, appVersion); - }; - - /** - * Initializes the identity service with the most recently - * used profile id and saved anonymous installation id - * - * @param profileId The id of the profile id that was most recently used by the app (on this device) - * @param anonymousId The anonymous installation id that was generated for this device - */ - bcc.initializeIdentity = function(profileId, anonymousId) { - bcc.authentication.initialize(profileId, anonymousId); - }; - - /** - * Sets the brainCloud server URL. Developers should not need to change this - * value. - * - * @param serverUrl - * {string} - The server URL e.g. "https://sharedprod.braincloudservers.com" - */ - bcc.setServerUrl = function(serverUrl) { - bcc.brainCloudManager.setServerUrl(serverUrl); - }; - - /** - * Returns the app id - * - * @return {string} - The brainCloud app id. - */ - bcc.getAppId = function() { - return bcc.brainCloudManager.getAppId(); - }; - - /** - * Returns the profile Id - * - * @return {string} - The brainCloud session's profile id. - */ - bcc.getProfileId = function() { - return bcc.authentication.profileId; - }; - - /** - * Returns the session id if a connection with brainCloud has been established. - * - * @return {string} - The brainCloud session id. - */ - bcc.getSessionId = function() { - return bcc.brainCloudManager.getSessionId(); - }; - - /** - * Returns the RTT connection id. Share this with your friends to be able to join games together. - * - * @return {string} - The brainCloud RTT connection id for this user. - */ - bcc.getRTTConnectionId = function() { - return bcc.brainCloudRttComms.getRTTConnectionId(); - }; - - /** - * Sets a callback handler for any out of band messages that come from - * brainCloud (essentially any message sent from brainCloud that wasn't in - * direct response to a client request). - * - * @param eventCallback - * {function} eventCallback is a function which takes a json object as it's only parameter - * - * where jsonEvents looks like the following: - * { - * "events": [{ - * "fromPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", - * "eventId": 3967, - * "createdAt": 1441742105908, - * "gameId": "10170", - * "toPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", - * "eventType": "test", - * "eventData": {"testData": 117} - * }], - * ] - * } - * - * @see brainCloudClient.events - */ - bcc.registerEventCallback = function(eventCallback) { - bcc.brainCloudManager.registerEventCallback(eventCallback); - }; - - /** - * Deregisters the event callback. - */ - bcc.deregisterEventCallback = function() { - bcc.brainCloudManager.deregisterEventCallback(); - }; - - /** - * Sets a reward handler for any api call results that return rewards. - * - * @param in_rewardCallback The reward callback handler. - * @see The brainCloud apidocs site for more information on the return JSON - */ - bcc.registerRewardCallback = function(rewardCallback) { - bcc.brainCloudManager.registerRewardCallback(rewardCallback); - }; - - /** - * Deregisters the reward callback - */ - bcc.deregisterRewardCallback = function() { - bcc.brainCloudManager.deregisterRewardCallback(); - }; - - /** - * Sets a callback handler for any error messages that come from brainCloud. - * This will include any networking errors as well as requests from the client - * which do not register a callback handler. - * - * @param errorCallback - * {function} - The error callback - */ - bcc.setErrorCallback = function(errorCallback) { - bcc.brainCloudManager.setErrorCallback(errorCallback); - }; - - /** - * Turns on/off debugging. This will write all requests/responses - * to the javascript console log. - * - * @param debugEnabled - * {boolean} - True to enable debugging, false otherwise. - */ - bcc.enableLogging = function(enableLogging) { - bcc.brainCloudManager.setDebugEnabled(enableLogging); - bcc.brainCloudRttComms.setDebugEnabled(enableLogging); - }; - -// deprecated - bcc.setDebugEnabled = function(debugEnabled) { - bcc.brainCloudManager.setDebugEnabled(debugEnabled); - bcc.brainCloudRttComms.setDebugEnabled(debugEnabled); - }; - - /** - * Returns whether the client is initialized. - * @return True if initialized, false otherwise. - */ - bcc.isInitialized = function() { - return bcc.brainCloudManager.isInitialized(); - }; - - /** - * Returns whether the client is authenticated with the brainCloud server. - * @return True if authenticated, false otherwise. - */ - bcc.isAuthenticated = function() { - return bcc.brainCloudManager.isAuthenticated(); - }; - - bcc.resetCommunication = function() { - bcc.authentication.profileId = ""; - - bcc.brainCloudManager.resetCommunication(); - bcc.brainCloudRttComms.disableRTT(); - }; - - /** - * Inserts a marker which will tell the brainCloud comms layer - * to close the message bundle off at this point. Any messages queued - * before this method was called will likely be bundled together in - * the next send to the server. - * - * To ensure that only a single message is sent to the server you would - * do something like this: - * - * InsertEndOfMessageBundleMarker() - * SomeApiCall() - * InsertEndOfMessageBundleMarker() - * - */ - bcc.insertEndOfMessageBundleMarker = function() { - var message = { - "operation": "END_BUNDLE_MARKER" - }; - bcc.brainCloudManager.sendRequest(message); - }; - - /** - * Sets the country code sent to brainCloud when a user authenticates. - * Will override any auto detected country. - * @param countryCode ISO 3166-1 two-letter country code - */ - bcc.overrideCountryCode = function(countryCode) { - bcc.countryCode = countryCode; - } - - /** - * Sets the language code sent to brainCloud when a user authenticates. - * If the language is set to a non-ISO 639-1 standard value the app default will be used instead. - * Will override any auto detected language. - * @param languageCode ISO 639-1 two-letter language code - */ - bcc.overrideLanguageCode = function(languageCode) { - brainCloudClient.languageCode = languageCode; - } - - bcc.heartbeat = function(callback) { - bcc.brainCloudManager.sendRequest({ - service : "heartbeat", - operation : "READ", - callback : callback - }); - }; - - /** - * If the library is used through a command line nodejs app, the app need to be able to stop the heartbeat interval - * otherwise the app can never exit once it's done processing. - */ - bcc.stopHeartBeat = function() { - bcc.brainCloudManager.stopHeartBeat(); - } - - bcc.startHeartBeat = function() { - bcc.brainCloudManager.startHeartBeat(); - } -} - -/** - * @deprecated Use of the *singleton* (window.brainCloudClient) has been deprecated. We recommend that you create your own *variable* to hold an instance of the brainCloudWrapper. Explanation here: http://getbraincloud.com/apidocs/release-3-6-5/ - */ -BrainCloudClient.apply(window.brainCloudClient = window.brainCloudClient || {}); +//---------------------------------------------------- +// brainCloud client source code +// Copyright 2016 bitHeads, inc. +//---------------------------------------------------- + +function BrainCloudClient() { + var bcc = this; + + bcc.name = "BrainCloudClient"; + + // If this is not the singleton, initialize it + if(window.brainCloudClient !== bcc) { + BCAbTest.apply(bcc); + BCAsyncMatch.apply(bcc); + BCAuthentication.apply(bcc); + BCChat.apply(bcc); + BCDataStream.apply(bcc); + BCEntity.apply(bcc); + BCEvents.apply(bcc); + BCFile.apply(bcc); + BCFriend.apply(bcc); + BCGamification.apply(bcc); + BCGlobalApp.apply(bcc); + BCGlobalStatistics.apply(bcc); + BCGlobalEntity.apply(bcc); + BCGroup.apply(bcc); + BCIdentity.apply(bcc); + BCItemCatalog.apply(bcc); + BCUserItems.apply(bcc); + BCLobby.apply(bcc); + BCMail.apply(bcc); + BCMatchMaking.apply(bcc); + BCMessaging.apply(bcc); + BCOneWayMatch.apply(bcc); + BCPlaybackStream.apply(bcc); + BCPlayerState.apply(bcc); + BCPlayerStatistics.apply(bcc); + BCPlayerStatisticsEvent.apply(bcc); + BCPresence.apply(bcc); + BCProducts.apply(bcc); + BCVirtualCurrency.apply(bcc); + BCAppStore.apply(bcc); + BCProfanity.apply(bcc); + BCPushNotifications.apply(bcc); + BCReasonCodes.apply(bcc); + BCRedemptionCodes.apply(bcc); + BCRTT.apply(bcc); + BCS3Handler.apply(bcc); + BCScript.apply(bcc); + BCSocialLeaderboard.apply(bcc); + BCStatusCodes.apply(bcc); + BCTime.apply(bcc); + BCTournament.apply(bcc); + BCCustomEntity.apply(bcc); + + bcc.brainCloudManager = new BrainCloudManager(); + bcc.brainCloudRttComms = new BrainCloudRttComms(this); + + bcc.brainCloudManager.abtests = bcc.abtests; + bcc.brainCloudManager.asyncMatch = bcc.asyncMatch; + bcc.brainCloudManager.authentication = bcc.authentication; + bcc.brainCloudManager.chat = bcc.chat; + bcc.brainCloudManager.dataStream = bcc.dataStream; + bcc.brainCloudManager.entity = bcc.entity; + bcc.brainCloudManager.event = bcc.event; + bcc.brainCloudManager.file = bcc.file; + bcc.brainCloudManager.friend = bcc.friend; + bcc.brainCloudManager.gamification = bcc.gamification; + bcc.brainCloudManager.globalApp = bcc.globalApp; + bcc.brainCloudManager.globalStatistics = bcc.globalStatistics; + bcc.brainCloudManager.globalEntity = bcc.globalEntity; + bcc.brainCloudManager.group = bcc.group; + bcc.brainCloudManager.identity = bcc.identity; + bcc.brainCloudManager.lobby = bcc.lobby; + bcc.brainCloudManager.mail = bcc.mail; + bcc.brainCloudManager.matchMaking = bcc.matchMaking; + bcc.brainCloudManager.messaging = bcc.messaging; + bcc.brainCloudManager.oneWayMatch = bcc.oneWayMatch; + bcc.brainCloudManager.playbackStream = bcc.playbackStream; + bcc.brainCloudManager.playerState = bcc.playerState; + bcc.brainCloudManager.playerStatistics = bcc.playerStatistics; + bcc.brainCloudManager.playerStatisticsEvent = bcc.playerStatisticsEvent; + bcc.brainCloudManager.presence = bcc.precense; + bcc.brainCloudManager.product = bcc.product; + bcc.brainCloudManager.virtualCurrency = bcc.virtualCurrency; + bcc.brainCloudManager.appStore = bcc.appStore; + bcc.brainCloudManager.profanity = bcc.profanity; + bcc.brainCloudManager.pushNotification = bcc.pushNotification; + bcc.brainCloudManager.reasonCodes = bcc.reasonCodes; + bcc.brainCloudManager.redemptionCode = bcc.redemptionCode; + bcc.brainCloudManager.rttService = bcc.rttService; + bcc.brainCloudManager.s3Handling = bcc.s3Handling; + bcc.brainCloudManager.script = bcc.script; + bcc.brainCloudManager.socialLeaderboard = bcc.socialLeaderboard; + bcc.brainCloudManager.statusCodes = bcc.statusCodes; + bcc.brainCloudManager.time = bcc.time; + bcc.brainCloudManager.tournament = bcc.tournament; + bcc.brainCloudManager.itemCatalog = bcc.itemCatalog; + bcc.brainCloudManager.userItems = bcc.userItems; + bcc.brainCloudManager.customEntity = bcc.customEntity; + + bcc.brainCloudRttComms.rtt = bcc.rtt; + bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference + + } else { + bcc.brainCloudManager = window.brainCloudManager = window.brainCloudManager || {}; + bcc.brainCloudRttComms = window.brainCloudRttComms = window.brainCloudRttComms || {}; + + bcc.brainCloudClient = window.brainCloudClient = window.brainCloudClient || {}; + + bcc.brainCloudManager.abtests = bcc.brainCloudClient.abtests = bcc.brainCloudClient.abtests || {}; + bcc.brainCloudManager.asyncMatch = bcc.brainCloudClient.asyncMatch = bcc.brainCloudClient.asyncMatch || {}; + bcc.brainCloudManager.authentication = bcc.brainCloudClient.authentication = bcc.brainCloudClient.authentication || {}; + bcc.brainCloudManager.chat = bcc.brainCloudClient.chat = bcc.brainCloudClient.chat || {}; + bcc.brainCloudManager.dataStream = bcc.brainCloudClient.dataStream = bcc.brainCloudClient.dataStream || {}; + bcc.brainCloudManager.entity = bcc.brainCloudClient.entity = bcc.brainCloudClient.entity || {}; + bcc.brainCloudManager.event = bcc.brainCloudClient.event = bcc.brainCloudClient.event || {}; + bcc.brainCloudManager.file = bcc.brainCloudClient.file = bcc.brainCloudClient.file || {}; + bcc.brainCloudManager.friend = bcc.brainCloudClient.friend = bcc.brainCloudClient.friend || {}; + bcc.brainCloudManager.gamification = bcc.brainCloudClient.gamification = bcc.brainCloudClient.gamification || {}; + bcc.brainCloudManager.globalApp = bcc.brainCloudClient.globalApp = bcc.brainCloudClient.globalApp || {}; + bcc.brainCloudManager.globalStatistics = bcc.brainCloudClient.globalStatistics = bcc.brainCloudClient.globalStatistics || {}; + bcc.brainCloudManager.globalEntity = bcc.brainCloudClient.globalEntity = bcc.brainCloudClient.globalEntity || {}; + bcc.brainCloudManager.group = bcc.brainCloudClient.group = bcc.brainCloudClient.group || {}; + bcc.brainCloudManager.identity = bcc.brainCloudClient.identity = bcc.brainCloudClient.identity || {}; + bcc.brainCloudManager.lobby = bcc.brainCloudClient.lobby = bcc.brainCloudClient.lobby || {}; + bcc.brainCloudManager.mail = bcc.brainCloudClient.mail = bcc.brainCloudClient.mail || {}; + bcc.brainCloudManager.matchMaking = bcc.brainCloudClient.matchMaking = bcc.brainCloudClient.matchMaking || {}; + bcc.brainCloudManager.messaging = bcc.brainCloudClient.messaging = bcc.brainCloudClient.messaging || {}; + bcc.brainCloudManager.oneWayMatch = bcc.brainCloudClient.oneWayMatch = bcc.brainCloudClient.oneWayMatch || {}; + bcc.brainCloudManager.playbackStream = bcc.brainCloudClient.playbackStream = bcc.brainCloudClient.playbackStream || {}; + bcc.brainCloudManager.playerState = bcc.brainCloudClient.playerState = bcc.brainCloudClient.playerState || {}; + bcc.brainCloudManager.playerStatistics = bcc.brainCloudClient.playerStatistics = bcc.brainCloudClient.playerStatistics || {}; + bcc.brainCloudManager.playerStatisticsEvent = bcc.brainCloudClient.playerStatisticsEvent = bcc.brainCloudClient.playerStatisticsEvent || {}; + bcc.brainCloudManager.presence = bcc.brainCloudClient.presence = bcc.brainCloudClient.presence || {}; + bcc.brainCloudManager.product = bcc.brainCloudClient.product = bcc.brainCloudClient.product || {}; + bcc.brainCloudManager.virtualCurrency = bcc.brainCloudClient.virtualCurrency = bcc.brainCloudClient.virtualCurrency || {}; + bcc.brainCloudManager.appStore = bcc.brainCloudClient.appStore = bcc.brainCloudClient.appStore || {}; + bcc.brainCloudManager.profanity = bcc.brainCloudClient.profanity = bcc.brainCloudClient.profanity || {}; + bcc.brainCloudManager.pushNotification = bcc.brainCloudClient.pushNotification = bcc.brainCloudClient.pushNotification || {}; + bcc.brainCloudManager.reasonCodes = bcc.brainCloudClient.reasonCodes = bcc.brainCloudClient.reasonCodes || {}; + bcc.brainCloudManager.redemptionCode = bcc.brainCloudClient.redemptionCode = bcc.brainCloudClient.redemptionCode || {}; + bcc.brainCloudManager.rttService = bcc.brainCloudClient.rttService = bcc.brainCloudClient.rttService || {}; + bcc.brainCloudManager.s3Handling = bcc.brainCloudClient.s3Handling = bcc.brainCloudClient.s3Handling || {}; + bcc.brainCloudManager.script = bcc.brainCloudClient.script = bcc.brainCloudClient.script || {}; + bcc.brainCloudManager.socialLeaderboard = bcc.brainCloudClient.socialLeaderboard = bcc.brainCloudClient.socialLeaderboard || {}; + bcc.brainCloudManager.statusCodes = bcc.brainCloudClient.statusCodes = bcc.brainCloudClient.statusCodes || {}; + bcc.brainCloudManager.time = bcc.brainCloudClient.time = bcc.brainCloudClient.time || {}; + bcc.brainCloudManager.tournament = bcc.brainCloudClient.tournament = bcc.brainCloudClient.tournament || {}; + bcc.brainCloudManager.itemCatalog = bcc.brainCloudClient.itemCatalog = bcc.brainCloudClient.itemCatalog || {}; + bcc.brainCloudManager.userItems = bcc.brainCloudClient.userItems = bcc.brainCloudClient.userItems || {}; + bcc.brainCloudManager.customEntity = bcc.brainCloudClient.customEntity = bcc.brainCloudClient.customEntity || {}; + + bcc.brainCloudRttComms.rtt = bcc.brainCloudClient.rtt = bcc.brainCloudClient.rtt || {}; + bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference + } + + + bcc.version = "4.3.0"; + bcc.countryCode; + bcc.languageCode; + + /** + * Initializes the brainCloud client with your app information. This method + * must be called before any API method is invoked. + * + * @param {string} + * appId - The app id + * @param {string} + * secret - The app secret + * @param {string} + * version - The app version (e.g. "1.0.0"). + */ + bcc.initialize = function(appId, secret, appVersion) { + function isBlank(str) { + return (!str || /^\s*$/.test(str)); + }; + + var error = null; + if (isBlank(secret)) + error = "secret was null or empty"; + else if (isBlank(appId)) + error = "appId was null or empty"; + else if (isBlank(appVersion)) + error = "appVersion was null or empty"; + if (error != null) { + console.log("ERROR | Failed to initialize brainCloud - " + error); + return; + } + + bcc.brainCloudManager.initialize(appId, secret, appVersion); + }; + + bcc.initializeWithApps = function(defaultAppId, secretMap, appVersion) { + function isBlank(str) { + return (!str || /^\s*$/.test(str)); + }; + + var appId = defaultAppId; + var secret = secretMap[appId]; + + var error = null; + if (isBlank(secret)) + error = "secret was null or empty"; + else if (isBlank(appId)) + error = "appId was null or empty"; + else if (isBlank(appVersion)) + error = "appVersion was null or empty"; + if (error != null) { + console.log("ERROR | Failed to initialize brainCloud - " + error); + return; + } + + bcc.brainCloudManager.initializeWithApps(defaultAppId, secretMap, appVersion); + }; + + /** + * Initializes the identity service with the most recently + * used profile id and saved anonymous installation id + * + * @param profileId The id of the profile id that was most recently used by the app (on this device) + * @param anonymousId The anonymous installation id that was generated for this device + */ + bcc.initializeIdentity = function(profileId, anonymousId) { + bcc.authentication.initialize(profileId, anonymousId); + }; + + /** + * Sets the brainCloud server URL. Developers should not need to change this + * value. + * + * @param serverUrl + * {string} - The server URL e.g. "https://sharedprod.braincloudservers.com" + */ + bcc.setServerUrl = function(serverUrl) { + bcc.brainCloudManager.setServerUrl(serverUrl); + }; + + /** + * Returns the app id + * + * @return {string} - The brainCloud app id. + */ + bcc.getAppId = function() { + return bcc.brainCloudManager.getAppId(); + }; + + /** + * Returns the profile Id + * + * @return {string} - The brainCloud session's profile id. + */ + bcc.getProfileId = function() { + return bcc.authentication.profileId; + }; + + /** + * Returns the session id if a connection with brainCloud has been established. + * + * @return {string} - The brainCloud session id. + */ + bcc.getSessionId = function() { + return bcc.brainCloudManager.getSessionId(); + }; + + /** + * Returns the RTT connection id. Share this with your friends to be able to join games together. + * + * @return {string} - The brainCloud RTT connection id for this user. + */ + bcc.getRTTConnectionId = function() { + return bcc.brainCloudRttComms.getRTTConnectionId(); + }; + + /** + * Sets a callback handler for any out of band messages that come from + * brainCloud (essentially any message sent from brainCloud that wasn't in + * direct response to a client request). + * + * @param eventCallback + * {function} eventCallback is a function which takes a json object as it's only parameter + * + * where jsonEvents looks like the following: + * { + * "events": [{ + * "fromPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", + * "eventId": 3967, + * "createdAt": 1441742105908, + * "gameId": "10170", + * "toPlayerId": "178ed06a-d575-4591-8970-e23a5d35f9df", + * "eventType": "test", + * "eventData": {"testData": 117} + * }], + * ] + * } + * + * @see brainCloudClient.events + */ + bcc.registerEventCallback = function(eventCallback) { + bcc.brainCloudManager.registerEventCallback(eventCallback); + }; + + /** + * Deregisters the event callback. + */ + bcc.deregisterEventCallback = function() { + bcc.brainCloudManager.deregisterEventCallback(); + }; + + /** + * Sets a reward handler for any api call results that return rewards. + * + * @param in_rewardCallback The reward callback handler. + * @see The brainCloud apidocs site for more information on the return JSON + */ + bcc.registerRewardCallback = function(rewardCallback) { + bcc.brainCloudManager.registerRewardCallback(rewardCallback); + }; + + /** + * Deregisters the reward callback + */ + bcc.deregisterRewardCallback = function() { + bcc.brainCloudManager.deregisterRewardCallback(); + }; + + /** + * Sets a callback handler for any error messages that come from brainCloud. + * This will include any networking errors as well as requests from the client + * which do not register a callback handler. + * + * @param errorCallback + * {function} - The error callback + */ + bcc.setErrorCallback = function(errorCallback) { + bcc.brainCloudManager.setErrorCallback(errorCallback); + }; + + /** + * Turns on/off debugging. This will write all requests/responses + * to the javascript console log. + * + * @param debugEnabled + * {boolean} - True to enable debugging, false otherwise. + */ + bcc.enableLogging = function(enableLogging) { + bcc.brainCloudManager.setDebugEnabled(enableLogging); + bcc.brainCloudRttComms.setDebugEnabled(enableLogging); + }; + +// deprecated + bcc.setDebugEnabled = function(debugEnabled) { + bcc.brainCloudManager.setDebugEnabled(debugEnabled); + bcc.brainCloudRttComms.setDebugEnabled(debugEnabled); + }; + + /** + * Returns whether the client is initialized. + * @return True if initialized, false otherwise. + */ + bcc.isInitialized = function() { + return bcc.brainCloudManager.isInitialized(); + }; + + /** + * Returns whether the client is authenticated with the brainCloud server. + * @return True if authenticated, false otherwise. + */ + bcc.isAuthenticated = function() { + return bcc.brainCloudManager.isAuthenticated(); + }; + + bcc.resetCommunication = function() { + bcc.authentication.profileId = ""; + + bcc.brainCloudManager.resetCommunication(); + bcc.brainCloudRttComms.disableRTT(); + }; + + /** + * Inserts a marker which will tell the brainCloud comms layer + * to close the message bundle off at this point. Any messages queued + * before this method was called will likely be bundled together in + * the next send to the server. + * + * To ensure that only a single message is sent to the server you would + * do something like this: + * + * InsertEndOfMessageBundleMarker() + * SomeApiCall() + * InsertEndOfMessageBundleMarker() + * + */ + bcc.insertEndOfMessageBundleMarker = function() { + var message = { + "operation": "END_BUNDLE_MARKER" + }; + bcc.brainCloudManager.sendRequest(message); + }; + + /** + * Sets the country code sent to brainCloud when a user authenticates. + * Will override any auto detected country. + * @param countryCode ISO 3166-1 two-letter country code + */ + bcc.overrideCountryCode = function(countryCode) { + bcc.countryCode = countryCode; + } + + /** + * Sets the language code sent to brainCloud when a user authenticates. + * If the language is set to a non-ISO 639-1 standard value the app default will be used instead. + * Will override any auto detected language. + * @param languageCode ISO 639-1 two-letter language code + */ + bcc.overrideLanguageCode = function(languageCode) { + brainCloudClient.languageCode = languageCode; + } + + bcc.heartbeat = function(callback) { + bcc.brainCloudManager.sendRequest({ + service : "heartbeat", + operation : "READ", + callback : callback + }); + }; + + /** + * If the library is used through a command line nodejs app, the app need to be able to stop the heartbeat interval + * otherwise the app can never exit once it's done processing. + */ + bcc.stopHeartBeat = function() { + bcc.brainCloudManager.stopHeartBeat(); + } + + bcc.startHeartBeat = function() { + bcc.brainCloudManager.startHeartBeat(); + } +} + +/** + * @deprecated Use of the *singleton* (window.brainCloudClient) has been deprecated. We recommend that you create your own *variable* to hold an instance of the brainCloudWrapper. Explanation here: http://getbraincloud.com/apidocs/release-3-6-5/ + */ +BrainCloudClient.apply(window.brainCloudClient = window.brainCloudClient || {}); diff --git a/src/brainCloudWrapper.js b/src/brainCloudWrapper.js index 09896bc..0e22cf4 100644 --- a/src/brainCloudWrapper.js +++ b/src/brainCloudWrapper.js @@ -108,6 +108,7 @@ function BrainCloudWrapper(wrapperName) { }; bcw._authResponseHandler = function(result) { + if (result.status == 200) { var profileId = result.data.profileId; bcw.setStoredProfileId(profileId); @@ -115,6 +116,9 @@ function BrainCloudWrapper(wrapperName) { var sessionId = result.data.sessionId; bcw.setStoredSessionId(sessionId); } + + console.log("PROFILE IDDDDDDDDD"); + console.log(profileId); }; /////////////////////////////////////////////////////////////////////////// @@ -198,7 +202,8 @@ function BrainCloudWrapper(wrapperName) { function(result) { bcw._authResponseHandler(result); responseHandler(result); - }); + } + ); }; /** @@ -416,6 +421,46 @@ function BrainCloudWrapper(wrapperName) { }); }; + /** + * Authenticate the user using a Pase userid and authentication token + * + * Service Name - Authenticate + * Service Operation - Authenticate + * + * @param handoffId braincloud handoff Id generated from cloud script + * @param securityToken The security token entered by the user + * @param callback The method to be invoked when the server response is received + */ + bcw.authenticateHandoff = function(handoffId, securityToken, callback) { + bcw.brainCloudClient.authentication.authenticateHandoff( + handoffId, + securityToken, + bc.authentication.AUTHENTICATION_TYPE_HANDOFF, + null, + false, + callback); + }; + + /** + * Authenticate a user with handoffCode + * + * Service Name - authenticationV2 + * Service Operation - AUTHENTICATE + * + * @param handoffCode generated via cloudcode + * @param callback The method to be invoked when the server response is received + * + */ + bcw.authenticateSettopHandoff= function(handoffCode, callback) { + bcw.brainCloudClient.authentication.authenticateSettopHandoff( + handoffCode, + "", + bc.authentication.AUTHENTICATION_TYPE_SETTOP_HANDOFF, + null, + false, + callback); + }; + /** * Smart Switch Authenticate will logout of the current profile, and switch to the new authentication type. * In event the current session was previously an anonymous account, the smart switch will delete that profile. diff --git a/test/test.js b/test/test.js index 3f35ddb..cf142b8 100644 --- a/test/test.js +++ b/test/test.js @@ -656,13 +656,49 @@ async function testAuthentication() { }); }); - await asyncTest("authenticateHandoff()", 2, function() { - bc.brainCloudClient.authentication.initialize("", bc.brainCloudClient.authentication.generateAnonymousId()); + await asyncTest("authenticateHandoff()", 3, function() { + bc.brainCloudClient.authentication.initialize("", bc.brainCloudClient.authentication.generateAnonymousId()); - bc.brainCloudClient.authentication.authenticateHandoff("_invalid_profileId_", "_invalid_handoff_token_", function(result) { - equal(result.status, bc.statusCodes.FORBIDDEN); - equal(result.reason_code, bc.reasonCodes.TOKEN_DOES_NOT_MATCH_USER); - resolve_test(); + var handoffId; + var handoffToken; + + bc.brainCloudClient.authentication.authenticateAnonymous( + true, function(result) { + equal(result.status, 200, JSON.stringify(result)); + + bc.brainCloudClient.script.runScript("createHandoffId", {}, function(result) { + equal(result.status, 200, JSON.stringify(result)); + var d = result.data; + handoffId = d.response.handoffId; + handoffToken = d.response.securityToken; + + bc.brainCloudClient.authentication.authenticateHandoff(handoffId, handoffToken, function(result) { + equal(result.status, 200, JSON.stringify(result)); + resolve_test(); + }); + }); + }); + }); + + await asyncTest("authenticateSettopHandoff()", 3, function() { + bc.brainCloudClient.authentication.initialize("", bc.brainCloudClient.authentication.generateAnonymousId()); + + var handoffCode + + bc.brainCloudClient.authentication.authenticateAnonymous( + true, function(result) { + equal(result.status, 200, JSON.stringify(result)); + + bc.brainCloudClient.script.runScript("CreateSettopHandoffCode", {}, function(result) { + equal(result.status, 200, JSON.stringify(result)); + var d = result.data; + handoffCode = d.response.handoffCode + + bc.brainCloudClient.authentication.authenticateSettopHandoff(handoffCode, function(result) { + equal(result.status, 200, JSON.stringify(result)); + resolve_test(); + }); + }); }); }); } @@ -938,7 +974,7 @@ async function testCustomEntity() { position : "forward", goals : 2, assists : 4 - }, { "other" : 2 }, null, false, function(result) { + }, { "other" : 2 }, null, true, function(result) { equal(result.status, 200, JSON.stringify(result)); entityId = result.data.entityId; resolve_test(); @@ -2228,6 +2264,19 @@ async function testGroup() { resolve_test(); }); }); + + var groupTypes = ["test"]; + + await asyncTest("autoJoinGroupMulti()", 2, function() { + bc.group.autoJoinGroupMulti(groupTypes, + bc.group.autoJoinStrategy.joinFirstGroup, + null, + function(result) { + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); await asyncTest("GetRandomGroupsMatching()", 2, function() { bc.group.getRandomGroupsMatching({ groupType : "BLUE"}, @@ -3943,6 +3992,23 @@ async function testSocialLeaderboard() { }); }); + await asyncTest("postScoreToDynamicGroupLeaderboard())", 2, function() { + bc.socialLeaderboard.postScoreToDynamicGroupLeaderboard( + groupLeaderboard, + groupId, + 0, + { test : "asdf"}, + "HIGH_VALUE", + "WEEKLY", + 1570818219096, + 2, + function(result) { + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); + await asyncTest("removeGroupScore())", 2, function() { bc.socialLeaderboard.removeGroupScore( groupLeaderboard, @@ -4632,6 +4698,8 @@ async function testWrapper() await asyncTest("authenticateAnonymous()", 2, function() { + bc.resetStoredProfileId(); + bc.authenticateAnonymous(function(result) { ok(true, JSON.stringify(result)); equal(result.status, 200, "Expecting 200");