diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..8ba3f86 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,55 @@ +All rights reserved +bitHeads, inc. 2015 + +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1 Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2 Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3 Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4 Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: + + You must give any other recipients of the Work or Derivative Works a copy of this License; and + You must cause any modified files to carry prominent notices stating that You changed the files; and + You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and + If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5 Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6 Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7 Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8 Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9 Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS diff --git a/deploy/node/package.json b/deploy/node/package.json index 505c2fb..0828663 100644 --- a/deploy/node/package.json +++ b/deploy/node/package.json @@ -1,6 +1,6 @@ { "name": "braincloud", - "version": "4.13.0", + "version": "4.14.0", "description": " brainCloud client for NodeJS", "main": "index.js", "react-native": "react-native.js", diff --git a/src/brainCloudClient-group-file.js b/src/brainCloudClient-group-file.js new file mode 100644 index 0000000..fa06fea --- /dev/null +++ b/src/brainCloudClient-group-file.js @@ -0,0 +1,274 @@ +function BCGroupFile() { + var bc = this; + + bc.groupFile = {}; + + bc.SERVICE_GROUP_FILE = "groupFile"; + + bc.groupFile.OPERATION_GET_FILE_INFO = "GET_FILE_INFO"; + bc.groupFile.OPERATION_GET_FILE_INFO_SIMPLE = "GET_FILE_INFO_SIMPLE"; + bc.groupFile.OPERATION_GET_CDN_URL = "GET_CDN_URL"; + bc.groupFile.OPERATION_GET_FILE_LIST = "GET_FILE_LIST"; + bc.groupFile.OPERATION_CHECK_FILENAME_EXISTS = "CHECK_FILENAME_EXISTS"; + bc.groupFile.OPERATION_CHECK_FULLPATH_FILENAME_EXISTS = "CHECK_FULLPATH_FILENAME_EXISTS"; + bc.groupFile.OPERATION_MOVE_FILE = "MOVE_FILE"; + bc.groupFile.OPERATION_UPDATE_FILE_INFO = "UPDATE_FILE_INFO"; + bc.groupFile.OPERATION_COPY_FILE = "COPY_FILE"; + bc.groupFile.OPERATION_DELETE_FILE = "DELETE_FILE"; + bc.groupFile.OPERATION_MOVE_USER_TO_GROUP_FILE = "MOVE_USER_TO_GROUP_FILE"; + + /** + * Returns information on a file using fileId. + * @param groupId ID of the group + * @param fileId ID of the file + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.getFileInfo = function (groupId, fileId, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_GET_FILE_INFO, + data: { + groupId: groupId, + fileId: fileId + }, + callback: callback + }); + }; + + /** + * Returns information on a file using path and name. + * @param groupId ID of the group + * @param folderPath Folder path + * @param filename File name + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.getFileInfoSimple = function (groupId, folderPath, filename, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_GET_FILE_INFO_SIMPLE, + data: { + groupId: groupId, + folderPath: folderPath, + filename: filename + }, + callback: callback + }); + }; + + /** + * Return the CDN url for file for clients that cannot handle redirect + * @param groupId ID of the group + * @param fileId ID of the file + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.getCDNUrl = function (groupId, fileId, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_GET_CDN_URL, + data: { + groupId: groupId, + fileId: fileId + }, + callback: callback + }); + }; + + /** + * Returns a list of files. + * @param groupId ID of group + * @param folderPath Folder path + * @param recurse Whether to recurse beyond the starting folder + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.getFileList = function (groupId, folderPath, recurse, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_GET_FILE_LIST, + data: { + groupId: groupId, + folderPath: folderPath, + recurse: recurse + }, + callback: callback + }); + }; + + /** + * Check if filename exists for provided path and name. + * @param groupId ID of the group + * @param folderPath File located cloud path/folder + * @param filename File cloud name + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.checkFilenameExists = function (groupId, folderPath, filename, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_CHECK_FILENAME_EXISTS, + data: { + groupId: groupId, + folderPath: folderPath, + filename: filename + }, + callback: callback + }); + }; + + /** + * Check if filename exists for provided path and name. + * @param groupId ID of the group + * @param fullPathFilename File cloud name in full path + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.checkFullpathFilenameExists = function (groupId, fullPathFilename, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_CHECK_FULLPATH_FILENAME_EXISTS, + data: { + groupId: groupId, + fullPathFilename: fullPathFilename + }, + callback: callback + }); + }; + + /** + * Move a file. + * @param groupId ID of the group + * @param fileId ID of the file + * @param version Target version of the file. As an option, you can use -1 for the latest version of the file + * @param newTreeId ID of the destination folder + * @param treeVersion Target version of the folder tree + * @param newFilename Optional new file name + * @param overwriteIfPresent Whether to allow overwrite of an existing file if present + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.moveFile = function (groupId, fileId, version, newTreeId, treeVersion, newFilename, overwriteIfPresent, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_MOVE_FILE, + data: { + groupId: groupId, + fileId: fileId, + version: version, + newTreeId: newTreeId, + treeVersion: treeVersion, + newFilename: newFilename, + overwriteIfPresent: overwriteIfPresent + }, + callback: callback + }); + }; + + /** + * Rename or edit permissions of an uploaded file. Does not change the contents of the file. + * @param groupId ID of the group + * @param fileId ID of the file + * @param version Target version of the file + * @param newFilename Optional new file name + * @param newAcl Optional new acl + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.updateFileInfo = function (groupId, fileId, version, newFilename, newAcl, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_UPDATE_FILE_INFO, + data: { + groupId: groupId, + fileId: fileId, + version: version, + newFilename: newFilename, + newAcl: newAcl + }, + callback: callback + }); + }; + + /** + * Copy a file. + * @param groupId ID of the group + * @param fileId ID of the file + * @param version Target version of the file + * @param newTreeId ID of the destination folder + * @param treeVersion Target version of the folder tree + * @param newFilename Optional new file name + * @param overwriteIfPresent Whether to allow overwrite of an existing file if present + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.copyFile = function (groupId, fileId, version, newTreeId, treeVersion, newFilename, overwriteIfPresent, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_COPY_FILE, + data: { + groupId: groupId, + fileId: fileId, + version: version, + newTreeId: newTreeId, + treeVersion: treeVersion, + newFilename: newFilename, + overwriteIfPresent: overwriteIfPresent + }, + callback: callback + }); + }; + + /** + * Delete a file. + * @param groupId ID of the group + * @param fileId ID of the file + * @param version Target version of the file + * @param filename File name for verification purposes + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.deleteFile = function (groupId, fileId, version, filename, callback) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_DELETE_FILE, + data: { + groupId: groupId, + fileId: fileId, + version: version, + filename: filename + }, + callback: callback + }); + }; + + /** + * Move a file from user space to group space. + * @param userCloudPath User file folder + * @param userCloudFilename User file name + * @param groupId ID of the group + * @param groupTreeId ID of the destination folder + * @param groupFileName Group file name + * @param groupFileAcl Acl of the new group file + * @param overwriteIfPresent Whether to allow overwrite of an existing file if present + * @param callback The method to be invoked when the server response is received + */ + bc.groupFile.moveUserToGroupFile = function ( + userCloudPath, + userCloudFilename, + groupId, + groupTreeId, + groupFilename, + groupFileAcl, + overwriteIfPresent, + callback + ) { + bc.brainCloudManager.sendRequest({ + service: bc.SERVICE_GROUP_FILE, + operation: bc.groupFile.OPERATION_MOVE_USER_TO_GROUP_FILE, + data: { + userCloudPath: userCloudPath, + userCloudFilename: userCloudFilename, + groupId: groupId, + groupTreeId: groupTreeId, + groupFilename: groupFilename, + groupFileAcl: groupFileAcl, + overwriteIfPresent: overwriteIfPresent + }, + callback: callback + }); + }; +} + +BCGroupFile.apply(window.brainCloudClient = window.brainCloudClient || {}); diff --git a/src/brainCloudClient-relay.js b/src/brainCloudClient-relay.js index 0a48d70..ca414e5 100644 --- a/src/brainCloudClient-relay.js +++ b/src/brainCloudClient-relay.js @@ -6,10 +6,10 @@ function BCRelay() { bc.SERVICE_RELAY = "relay"; bc.relay.TO_ALL_PLAYERS = 0x000000FFFFFFFFFF; - bc.relay.CHANNEL_HIGH_PRIORITY_1 = 0; - bc.relay.CHANNEL_HIGH_PRIORITY_2 = 1; - bc.relay.CHANNEL_NORMAL_PRIORITY = 2; - bc.relay.CHANNEL_LOW_PRIORITY = 3; + bc.relay.CHANNEL_HIGH_PRIORITY_1 = 0; + bc.relay.CHANNEL_HIGH_PRIORITY_2 = 1; + bc.relay.CHANNEL_NORMAL_PRIORITY = 2; + bc.relay.CHANNEL_LOW_PRIORITY = 3; /** * Start a connection, based on connection type to @@ -26,22 +26,30 @@ function BCRelay() { * @param success Called on success to establish a connection. * @param failure Called on failure to establish a connection or got disconnected. */ - bc.relay.connect = function(options, success, failure) { + bc.relay.connect = function (options, success, failure) { bc.brainCloudRelayComms.connect(options, success, failure); }; /** * Disconnects from the relay server */ - bc.relay.disconnect = function() { + bc.relay.disconnect = function () { bc.brainCloudRelayComms.disconnect(); } + /** + * Terminate the match instance by the owner. + * @param json Payload data sent in JSON format. It will be relayed to other connnected players. + */ + bc.relay.endMatch = function (json) { + bc.brainCloudRelayComms.endMatch(json); + } + /** * Returns whether or not we have a successful connection with * the relay server */ - bc.relay.isConnected = function() { + bc.relay.isConnected = function () { return bc.brainCloudRelayComms.isConnected; } @@ -50,7 +58,7 @@ function BCRelay() { * Note: Pings are not distributed amount other members. Your game will * have to bundle it inside a packet and distribute to other peers. */ - bc.relay.getPing = function() { + bc.relay.getPing = function () { return bc.brainCloudRelayComms.ping; } @@ -61,49 +69,49 @@ function BCRelay() { * * @param interval in Seconds */ - bc.relay.setPingInterval = function(interval) { + bc.relay.setPingInterval = function (interval) { bc.brainCloudRelayComms.setPingInterval(interval); } /** * Get the lobby's owner profile Id */ - bc.relay.getOwnerProfileId = function() { + bc.relay.getOwnerProfileId = function () { return bc.brainCloudRelayComms.getOwnerProfileId(); } /** * Get the lobby's owner Connection Id */ - bc.relay.getOwnerCxId = function() { + bc.relay.getOwnerCxId = function () { return bc.brainCloudRelayComms.getOwnerCxId(); } /** * Returns the profileId associated with a netId. */ - bc.relay.getProfileIdForNetId = function(netId) { + bc.relay.getProfileIdForNetId = function (netId) { return bc.brainCloudRelayComms.getProfileIdForNetId(netId); } /** * Returns the Connection Id associated with a netId. */ - bc.relay.getCxIdForNetId = function(netId) { + bc.relay.getCxIdForNetId = function (netId) { return bc.brainCloudRelayComms.getCxIdForNetId(netId); } /** * Returns the netId associated with a profileId. */ - bc.relay.getNetIdForProfileId = function(profileId) { + bc.relay.getNetIdForProfileId = function (profileId) { return bc.brainCloudRelayComms.getNetIdForProfileId(profileId); } /** * Returns the netId associated with a connection Id. */ - bc.relay.getNetIdForCxId = function(cxId) { + bc.relay.getNetIdForCxId = function (cxId) { return bc.brainCloudRelayComms.getNetIdForCxId(cxId); } @@ -112,10 +120,10 @@ function BCRelay() { * * @param callback Calle whenever a relay message was received. function(netId, data[]) */ - bc.relay.registerRelayCallback = function(callback) { + bc.relay.registerRelayCallback = function (callback) { bc.brainCloudRelayComms.registerRelayCallback(callback); } - bc.relay.deregisterRelayCallback = function() { + bc.relay.deregisterRelayCallback = function () { bc.brainCloudRelayComms.deregisterRelayCallback(); } @@ -163,10 +171,10 @@ function BCRelay() { * profileId: "..." * } */ - bc.relay.registerSystemCallback = function(callback) { + bc.relay.registerSystemCallback = function (callback) { bc.brainCloudRelayComms.registerSystemCallback(callback); } - bc.relay.deregisterSystemCallback = function() { + bc.relay.deregisterSystemCallback = function () { bc.brainCloudRelayComms.deregisterSystemCallback(); } @@ -179,13 +187,11 @@ function BCRelay() { * @param ordered Receive this ordered or not. * @param channel One of: (bc.relay.CHANNEL_HIGH_PRIORITY_1, bc.relay.CHANNEL_HIGH_PRIORITY_2, bc.relay.CHANNEL_NORMAL_PRIORITY, bc.relay.CHANNEL_LOW_PRIORITY) */ - bc.relay.send = function(data, toNetId, reliable, ordered, channel) { - if (toNetId == bc.relay.TO_ALL_PLAYERS) - { + bc.relay.send = function (data, toNetId, reliable, ordered, channel) { + if (toNetId == bc.relay.TO_ALL_PLAYERS) { bc.relay.sendToAll(data, reliable, ordered, channel); } - else - { + else { // Fancy math here because using bitwise operation will transform the number into 32 bits var playerMask = Math.pow(2, toNetId); bc.brainCloudRelayComms.sendRelay(data, playerMask, reliable, ordered, channel); @@ -201,7 +207,7 @@ function BCRelay() { * @param ordered Receive this ordered or not. * @param channel One of: (bc.relay.CHANNEL_HIGH_PRIORITY_1, bc.relay.CHANNEL_HIGH_PRIORITY_2, bc.relay.CHANNEL_NORMAL_PRIORITY, bc.relay.CHANNEL_LOW_PRIORITY) */ - bc.relay.sendToPlayers = function(data, playerMask, reliable, ordered, channel) { + bc.relay.sendToPlayers = function (data, playerMask, reliable, ordered, channel) { bc.brainCloudRelayComms.sendRelay(data, playerMask, reliable, ordered, channel); } @@ -213,7 +219,7 @@ function BCRelay() { * @param ordered Receive this ordered or not. * @param channel One of: (bc.relay.CHANNEL_HIGH_PRIORITY_1, bc.relay.CHANNEL_HIGH_PRIORITY_2, bc.relay.CHANNEL_NORMAL_PRIORITY, bc.relay.CHANNEL_LOW_PRIORITY) */ - bc.relay.sendToAll = function(data, reliable, ordered, channel) { + bc.relay.sendToAll = function (data, reliable, ordered, channel) { var myProfileId = bc.authentication.profileId; var myNetId = bc.relay.getNetIdForProfileId(myProfileId); diff --git a/src/brainCloudClient.js b/src/brainCloudClient.js index bfc8dcd..8d094e1 100644 --- a/src/brainCloudClient.js +++ b/src/brainCloudClient.js @@ -24,6 +24,7 @@ function BrainCloudClient() { BCGlobalApp.apply(bcc); BCGlobalStatistics.apply(bcc); BCGlobalEntity.apply(bcc); + BCGroupFile.apply(bcc); BCGroup.apply(bcc); BCIdentity.apply(bcc); BCItemCatalog.apply(bcc); @@ -75,6 +76,7 @@ function BrainCloudClient() { bcc.brainCloudManager.globalApp = bcc.globalApp; bcc.brainCloudManager.globalStatistics = bcc.globalStatistics; bcc.brainCloudManager.globalEntity = bcc.globalEntity; + bcc.brainCloudManager.groupFile = bcc.groupFile; bcc.brainCloudManager.group = bcc.group; bcc.brainCloudManager.identity = bcc.identity; bcc.brainCloudManager.lobby = bcc.lobby; @@ -132,6 +134,7 @@ function BrainCloudClient() { 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.groupFile = bcc.brainCloudClient.groupFile = bcc.brainCloudClient.groupFile || {}; 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 || {}; @@ -172,7 +175,7 @@ function BrainCloudClient() { } - bcc.version = "4.13.0"; + bcc.version = "4.14.0"; bcc.countryCode; bcc.languageCode; diff --git a/src/brainCloudRelayComms.js b/src/brainCloudRelayComms.js index dd85ec5..3078e2f 100644 --- a/src/brainCloudRelayComms.js +++ b/src/brainCloudRelayComms.js @@ -13,6 +13,7 @@ function BrainCloudRelayComms(_client) { bcr.CL2RS_ACK = 3; bcr.CL2RS_PING = 4; bcr.CL2RS_RSMG_ACK = 5; + bcr.CL2RS_ENDMATCH = 6; // Messages sent from Relay-Server to Client bcr.RS2CL_RSMG = 0; @@ -45,6 +46,8 @@ function BrainCloudRelayComms(_client) { bcr._sendPacketId = {}; bcr.ping = 999; + bcr.endMatchRequested = false; + bcr.setDebugEnabled = function(debugEnabled) { bcr._debugEnabled = debugEnabled; }; @@ -94,6 +97,7 @@ function BrainCloudRelayComms(_client) { var passcode = options.passcode; var lobbyId = options.lobbyId; + bcr.endMatchRequested = false; bcr.isConnected = false; bcr.connectCallback = { success: success, @@ -136,16 +140,20 @@ function BrainCloudRelayComms(_client) { bcr.disconnect = function() { bcr.stopPing(); - if (bcr.socket) { + + if(!bcr.endMatchRequested){ + if (bcr.socket) { //> REMOVE IF K6 - bcr.socket.removeEventListener('error', bcr.onSocketError); - bcr.socket.removeEventListener('close', bcr.onSocketClose); - bcr.socket.removeEventListener('open', bcr.onSocketOpen); - bcr.socket.removeEventListener('message', bcr.onSocketMessage); + bcr.socket.removeEventListener('error', bcr.onSocketError); + bcr.socket.removeEventListener('close', bcr.onSocketClose); + bcr.socket.removeEventListener('open', bcr.onSocketOpen); + bcr.socket.removeEventListener('message', bcr.onSocketMessage); //> END - bcr.socket.close(); - bcr.socket = null; + bcr.socket.close(); + bcr.socket = null; + } } + bcr.isConnected = false; bcr._sendPacketId = {}; bcr._netIdToProfileId = {}; @@ -153,6 +161,20 @@ function BrainCloudRelayComms(_client) { bcr.ping = 999; } + bcr.endMatch = function(json){ + if(bcr.isConnected){ + + // Send end match request + var payload = { + jsonPayload: json + }; + + bcr.sendJson(bcr.CL2RS_ENDMATCH, payload); + + bcr.endMatchRequested = true; + } + } + bcr.registerRelayCallback = function(callback) { bcr._relayCallback = callback; } @@ -509,6 +531,11 @@ function BrainCloudRelayComms(_client) { bcr._ownerId = json.cxId; break; } + case "END_MATCH": { + bcr.endMatchRequested = true; + bcr.disconnect(); + break; + } } if (bcr._systemCallback) { diff --git a/src/brainCloudWrapper.js b/src/brainCloudWrapper.js index 0cf4f8e..7070722 100644 --- a/src/brainCloudWrapper.js +++ b/src/brainCloudWrapper.js @@ -36,6 +36,7 @@ function BrainCloudWrapper(wrapperName) { bcw.globalApp = bcw.brainCloudClient.globalApp; bcw.globalStatistics = bcw.brainCloudClient.globalStatistics; bcw.globalEntity = bcw.brainCloudClient.globalEntity; + bcw.groupFile = bcw.brainCloudClient.groupFile; bcw.group = bcw.brainCloudClient.group; bcw.identity = bcw.brainCloudClient.identity; bcw.lobby = bcw.brainCloudClient.lobby; diff --git a/test/test.js b/test/test.js index d1ebd4f..5deaf36 100644 --- a/test/test.js +++ b/test/test.js @@ -2141,6 +2141,275 @@ async function testGlobalEntity() { }); } +//////////////////////////////////////// +// Group File tests +//////////////////////////////////////// +async function testGroupFile(){ + if (!module("GroupFile", () => + { + initializeClient(); + + return new Promise(resolve => { + bc.brainCloudClient.authentication.authenticateUniversal("js-tester", "js-tester", true, (result) => { + resolve(); + }); + }); + + }, () => + { + return tearDownLogout(); + })) return; + + var groupID = "a7ff751c-3251-407a-b2fd-2bd1e9bca64a"; + var groupFileID = "d2dd646a-f1af-4a96-90a7-a0310246f5a2"; + var filename = "testingGroupFile.dat"; + var tempFilename = "temporaryFile.dat" + var movedFilename = "movedGroupFile.dat"; + var copiedFilename = "copiedGroupFile.dat"; + var updatedFilename = "updatedGroupFile.dat"; + var acl = { + "other" : 0, + "member" : 2 + }; + + await asyncTest("getFileInfo()", 2, function() { + bc.groupFile.getFileInfo( + groupID, + groupFileID, + function(result) { + + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); + await asyncTest("getFileInfoSimple()", 2, function() { + bc.groupFile.getFileInfoSimple( + groupID, + "", + filename, + function(result) { + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); + + await asyncTest("getCDNUrl()", 2, function() { + bc.groupFile.getCDNUrl( + groupID, + groupFileID, + function(result) { + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); + + await asyncTest("getFileList()", 2, function() { + bc.groupFile.getFileList( + groupID, + "", + true, + function(result) { + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + }); + }); + + await asyncTest("checkFilenameExists()", 2, function() { + bc.groupFile.checkFilenameExists( + groupID, + "", + filename, + function(result) { + if(result.data.exists == true){ + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + else{ + resolve_test(); + } + }); + }); + + await asyncTest("checkFullpathFilenameExists()", 2, function() { + bc.groupFile.checkFullpathFilenameExists( + groupID, + filename, + function(result) { + if(result.data.exists == true){ + ok(true, JSON.stringify(result)); + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + else{ + resolve_test(); + } + }); + }); + + await asyncTest("moveUserToGroupFile()", 3, function() { + var fileSize = fs.statSync("README.md").size; + bc.file.prepareFileUpload("TestFolder", "README.md", true, true, fileSize, result => + { + equal(result.status, 200, "Expecting 200"); + if (result.status == 200) + { + let uploadId = result.data.fileDetails.uploadId; + let xhr = new BC.XMLHttpRequest4Upload(); + let file = fs.createReadStream("README.md"); + file.size = fileSize; + + xhr.addEventListener("load", result => + { + if (result.statusCode === 200) + { + ok(true, "done file upload"); + testMoveUserToGroupFile(); + } + else + { + ok(false, "Failed upload " + result.statusMessage); + resolve_test(); + } + + }); + + xhr.addEventListener("error", result => + { + ok(false, error); + resolve_test(); + }); + + bc.file.uploadFile(xhr, file, uploadId); + } + else + { + resolve_test(); + } + }); + + function testMoveUserToGroupFile(){ + bc.groupFile.moveUserToGroupFile( + "TestFolder/", + "README.md", + groupID, + "", + tempFilename, + acl, + true, + function(result){ + var tempFileId = result.data.fileDetails.fileId; + + deleteTempFile(tempFileId, tempFilename); + + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + ) + } + }); + + await asyncTest("moveFile()", function(){ + var moveBack = true; + + testMoveFile(movedFilename); + + function testMoveFile(moveName){ + bc.groupFile.moveFile( + groupID, + groupFileID, + -1, + "", + 0, + moveName, + true, + function(result) { + //Change the filename back to its original once it has been updated + if(moveBack){ + moveBack = false; + testMoveFile(filename); + } + else{ + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + } + ); + }; + }) + + await asyncTest("copyFile()", function() { + bc.groupFile.copyFile( + groupID, + groupFileID, + -1, + "", + 0, + copiedFilename, + true, + function(result) { + if(result.status == 200){ + console.log("File copied."); + + var tempFileId = result.data.fileDetails.fileId; + var tempFilename = result.data.fileDetails.fileName; + + console.log("Deleting newly copied file..."); + deleteTempFile(tempFileId, tempFilename); + + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + } + ); + }); + + await asyncTest("updateFileInfo()", function() { + var revertBack = true; + + testUpdateInfo(updatedFilename); + + function testUpdateInfo(updateName){ + bc.groupFile.updateFileInfo( + groupID, + groupFileID, + -1, + updateName, + acl, + function(result) { + //Change the filename back to its original once it has been updated + if(revertBack){ + revertBack = false; + testUpdateInfo(filename); + } + else{ + equal(result.status, 200, "Expecting 200"); + resolve_test(); + } + } + ); + }; + }); + + //Deletes a file that was created for a test (ex: Testing copy or upload functions) + //Also acts as groupFile.deleteFile test + function deleteTempFile(tempFileId, tempFilename){ + bc.groupFile.deleteFile( + groupID, + tempFileId, + -1, + tempFilename, + function(){ + console.log("Temp file deleted"); + } + ) + } +} + //////////////////////////////////////// // Group tests //////////////////////////////////////// @@ -6025,6 +6294,12 @@ async function testRelay() { // // Full flow. Create lobby -> ready up -> connect to server await asyncTest("connect()", 8, () => { + // Determines whether callback has already occured + let systemCallback = false; + let relayCallback = false; + + let endMatch = false; + // Force timeout after 5 mins let timeoutId = setTimeout(() => { @@ -6037,20 +6312,35 @@ async function testRelay() { bc.relay.registerRelayCallback((netId, data) => { - ok(netId == bc.relay.getNetIdForProfileId(UserA.profileId) && data.toString('ascii') == "Echo", "Relay callback") - resolve_test(); + if(relayCallback == false) + { + ok(netId == bc.relay.getNetIdForProfileId(UserA.profileId) && data.toString('ascii') == "Echo", "Relay callback") + + relayCallback = true; + + // Send end match request + var json = { + "op" : "END_MATCH" + } + bc.relay.endMatch(json); + + // + resolve_test(); + } }) bc.relay.registerSystemCallback(json => { - if (json.op == "CONNECT") + if (json.op == "CONNECT" && systemCallback == false) { ok(true, "System Callback") let relayOwnerCxId = bc.relay.getOwnerCxId() ok(ownerCxId == relayOwnerCxId, `getOwnerCxId: ${ownerCxId} == ${relayOwnerCxId}`) let netId = bc.relay.getNetIdForProfileId(UserA.profileId) ok(UserA.profileId == bc.relay.getProfileIdForNetId(netId), "getNetIdForProfileId and getProfileIdForNetId") - + + systemCallback = true; + // Wait 5sec then check the ping. // If we are pinging properly, we should get // less than 999. unless we have godawful @@ -6063,6 +6353,13 @@ async function testRelay() { bc.relay.send(Buffer.from("Echo"), netId, true, true, bc.relay.CHANNEL_HIGH_PRIORITY_1) }, 5000) } + else if(json.op == "END_MATCH" && endMatch == false){ + console.log("System callback END_MATCH"); + + ok(true, "End Match"); + + endMatch = true; + } }) bc.rttService.registerRTTLobbyCallback(result => @@ -6749,6 +7046,7 @@ async function run_tests() await testGlobalApp(); await testGlobalStatistics(); await testGlobalEntity(); + await testGroupFile(); await testGroup(); await testIdentity(); await testMail();