Skip to content

Commit

Permalink
Merge pull request #107 from getbraincloud/develop
Browse files Browse the repository at this point in the history
Release Relay service
  • Loading branch information
davidstl authored Jan 17, 2020
2 parents f3891d9 + 8de59ac commit c72822f
Show file tree
Hide file tree
Showing 7 changed files with 684 additions and 3 deletions.
2 changes: 1 addition & 1 deletion deploy/node/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion deploy/node/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "braincloud",
"version": "4.3.5",
"version": "4.3.6",
"description": " brainCloud client for NodeJS",
"main": "index.js",
"react-native": "react-native.js",
Expand Down
167 changes: 167 additions & 0 deletions src/brainCloudClient-relay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
function BCRelay() {
var bc = this;

bc.relay = {};

bc.SERVICE_RELAY = "relay";

bc.relay.TO_ALL_PLAYERS = 131;
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
* brainClouds Relay Servers. Connect options come in
* from ROOM_ASSIGNED lobby callback.
*
* @param options {
* ssl: false,
* host: "168.0.1.192"
* port: 9000,
* passcode: "somePasscode",
* lobbyId: "55555:v5v:001"
* }
* @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.brainCloudRelayComms.connect(options, success, failure);
};

/**
* Disconnects from the relay server
*/
bc.relay.disconnect = function() {
bc.brainCloudRelayComms.disconnect();
}

/**
* Returns whether or not we have a successful connection with
* the relay server
*/
bc.relay.isConnected = function() {
return bc.brainCloudRelayComms.isConnected;
}

/**
* Get the current ping for our user.
* 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() {
return bc.brainCloudRelayComms.ping;
}

/**
* Set the ping interval. Ping allows to keep the connection
* alive, but also inform the player of his current ping.
* The default is 1 seconds interval.
*
* @param interval in Seconds
*/
bc.relay.setPingInterval = function(interval) {
bc.brainCloudRelayComms.setPingInterval(interval);
}

/**
* Get the lobby's owner profile Id
*/
bc.relay.getOwnerProfileId = function() {
return bc.brainCloudRelayComms.getOwnerProfileId();
}

/**
* Returns the profileId associated with a netId.
*/
bc.relay.getProfileIdForNetId = function(netId) {
return bc.brainCloudRelayComms.getProfileIdForNetId(netId);
}

/**
* Returns the netId associated with a profileId.
*/
bc.relay.getNetIdForProfileId = function(profileId) {
return bc.brainCloudRelayComms.getNetIdForProfileId(profileId);
}

/**
* Register callback for relay messages coming from peers.
*
* @param callback Calle whenever a relay message was received. function(netId, data[])
*/
bc.relay.registerRelayCallback = function(callback) {
bc.brainCloudRelayComms.registerRelayCallback(callback);
}
bc.relay.deregisterRelayCallback = function() {
bc.brainCloudRelayComms.deregisterRelayCallback();
}

/**
* Register callback for RelayServer system messages.
*
* @param callback Called whenever a system message was received. function(json)
*
* # CONNECT
* Received when a new member connects to the server.
* {
* op: "CONNECT",
* profileId: "...",
* ownerId: "...",
* netId: #
* }
*
* # NET_ID
* Receive the Net Id assossiated with a profile Id. This is
* sent for each already connected members once you
* successfully connected.
* {
* op: "NET_ID",
* profileId: "...",
* netId: #
* }
*
* # DISCONNECT
* Received when a member disconnects from the server.
* {
* op: "DISCONNECT",
* profileId: "..."
* }
*
* # MIGRATE_OWNER
* If the owner left or never connected in a timely manner,
* the relay-server will migrate the role to the next member
* with the best ping. If no one else is currently connected
* yet, it will be transferred to the next member in the
* lobby members' list. This last scenario can only occur if
* the owner connected first, then quickly disconnected.
* Leaving only unconnected lobby members.
* {
* op: "MIGRATE_OWNER",
* profileId: "..."
* }
*/
bc.relay.registerSystemCallback = function(callback) {
bc.brainCloudRelayComms.registerSystemCallback(callback);
}
bc.relay.deregisterSystemCallback = function() {
bc.brainCloudRelayComms.deregisterSystemCallback();
}

/**
* Send a packet to peer(s)
*
* @param data Byte array for the data to send
* @param toNetId The net id to send to, bc.relay.TO_ALL_PLAYERS to relay to all.
* @param reliable Send this reliable or not.
* @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) {
bc.brainCloudRelayComms.sendRelay(data, toNetId, reliable, ordered, channel);
}
}

BCRelay.apply(window.brainCloudClient = window.brainCloudClient || {});
12 changes: 11 additions & 1 deletion src/brainCloudClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function BrainCloudClient() {
BCPushNotifications.apply(bcc);
BCReasonCodes.apply(bcc);
BCRedemptionCodes.apply(bcc);
BCRelay.apply(bcc);
BCRTT.apply(bcc);
BCS3Handler.apply(bcc);
BCScript.apply(bcc);
Expand All @@ -55,6 +56,7 @@ function BrainCloudClient() {

bcc.brainCloudManager = new BrainCloudManager();
bcc.brainCloudRttComms = new BrainCloudRttComms(this);
bcc.brainCloudRelayComms = new BrainCloudRelayComms(this);

bcc.brainCloudManager.abtests = bcc.abtests;
bcc.brainCloudManager.asyncMatch = bcc.asyncMatch;
Expand Down Expand Up @@ -88,6 +90,7 @@ function BrainCloudClient() {
bcc.brainCloudManager.pushNotification = bcc.pushNotification;
bcc.brainCloudManager.reasonCodes = bcc.reasonCodes;
bcc.brainCloudManager.redemptionCode = bcc.redemptionCode;
bcc.brainCloudManager.relay = bcc.relay;
bcc.brainCloudManager.rttService = bcc.rttService;
bcc.brainCloudManager.s3Handling = bcc.s3Handling;
bcc.brainCloudManager.script = bcc.script;
Expand All @@ -101,10 +104,12 @@ function BrainCloudClient() {

bcc.brainCloudRttComms.rtt = bcc.rtt;
bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference
bcc.brainCloudRelayComms.brainCloudClient = bcc;

} else {
bcc.brainCloudManager = window.brainCloudManager = window.brainCloudManager || {};
bcc.brainCloudRttComms = window.brainCloudRttComms = window.brainCloudRttComms || {};
bcc.brainCloudRelayComms = window.brainCloudRelayComms = window.brainCloudRelayComms || {};

bcc.brainCloudClient = window.brainCloudClient = window.brainCloudClient || {};

Expand Down Expand Up @@ -140,6 +145,7 @@ function BrainCloudClient() {
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.relay = bcc.brainCloudClient.relay = bcc.brainCloudClient.relay || {};
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 || {};
Expand All @@ -153,10 +159,11 @@ function BrainCloudClient() {

bcc.brainCloudRttComms.rtt = bcc.brainCloudClient.rtt = bcc.brainCloudClient.rtt || {};
bcc.brainCloudRttComms.brainCloudClient = bcc; // Circular reference
bcc.brainCloudRelayComms.brainCloudClient = bcc; // Circular reference
}


bcc.version = "4.3.5";
bcc.version = "4.3.6";
bcc.countryCode;
bcc.languageCode;

Expand Down Expand Up @@ -346,12 +353,14 @@ function BrainCloudClient() {
bcc.enableLogging = function(enableLogging) {
bcc.brainCloudManager.setDebugEnabled(enableLogging);
bcc.brainCloudRttComms.setDebugEnabled(enableLogging);
bcc.brainCloudRelayComms.setDebugEnabled(enableLogging);
};

// deprecated
bcc.setDebugEnabled = function(debugEnabled) {
bcc.brainCloudManager.setDebugEnabled(debugEnabled);
bcc.brainCloudRttComms.setDebugEnabled(debugEnabled);
bcc.brainCloudRelayComms.setDebugEnabled(debugEnabled);
};

/**
Expand All @@ -375,6 +384,7 @@ function BrainCloudClient() {

bcc.brainCloudManager.resetCommunication();
bcc.brainCloudRttComms.disableRTT();
bcc.brainCloudRelayComms.disconnect();
};

/**
Expand Down
Loading

0 comments on commit c72822f

Please sign in to comment.