-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from getbraincloud/develop
Release Relay service
- Loading branch information
Showing
7 changed files
with
684 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 || {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.