diff --git a/src/r3-a-1-event.js b/src/r3-a-1-event.js index 9a1156f..8e65b64 100644 --- a/src/r3-a-1-event.js +++ b/src/r3-a-1-event.js @@ -135,6 +135,7 @@ R3.Event.COMPONENT_REPLACED = 0x75; R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76; R3.Event.GET_DEFAULT_SCENE = 0x77; R3.Event.GET_DEFAULT_CAMERA = 0x78; +R3.Event.GET_WEBSOCKET_CONFIG = 0x79; /** * Returns string name of event ID @@ -265,6 +266,7 @@ R3.Event.GetEventName = function(number) { case 0x76 : return 'engine_fired_particles_zero'; case 0x77 : return 'get_default_scene'; case 0x78 : return 'get_default_camera'; + case 0x79 : return 'get_websocket_config'; break; } diff --git a/src/r3-api-server.js b/src/r3-api-server.js index e2e10a1..b255071 100644 --- a/src/r3-api-server.js +++ b/src/r3-api-server.js @@ -1,9 +1,13 @@ /** - * Raw Server API object - should always correspond with the Server Schema + * R3.API.Server * @param id * @param name * @param protocol + * @param context + * @param application + * @param domain * @param ip + * @param preferIp - Set to true to use IP instead of resolving DNS at getUrl() runtime * @param port * @param protocols * @param parentEntity @@ -13,7 +17,11 @@ R3.API.Server = function( id, name, protocol, + context, + application, + domain, ip, + preferIp, port, protocols, parentEntity @@ -34,11 +42,31 @@ R3.API.Server = function( } this.protocol = protocol; + if (R3.Utils.UndefinedOrNull(context)) { + context = null; + } + this.context = context; + + if (R3.Utils.UndefinedOrNull(application)) { + application = null; + } + this.application = application; + + if (R3.Utils.UndefinedOrNull(domain)) { + domain = null; + } + this.domain = domain; + if (R3.Utils.UndefinedOrNull(ip)) { ip = '127.0.0.1'; } this.ip = ip; + if (R3.Utils.UndefinedOrNull(preferIp)) { + preferIp = false; + } + this.preferIp = preferIp; + if (R3.Utils.UndefinedOrNull(port)) { port = R3.API.Server.PORT_SECURE; } @@ -65,8 +93,4 @@ R3.API.Server.PROTOCOL_WEBSOCKET = 'ws'; R3.API.Server.PROTOCOL_WEBSOCKET_SSL = 'wss'; R3.API.Server.PORT_INSECURE = 80; -R3.API.Server.PORT_SECURE = 443; - -R3.API.Server.prototype.getURL = function() { - return this.protocol + '://' + this.ip + ':' + this.port; -}; \ No newline at end of file +R3.API.Server.PORT_SECURE = 443; \ No newline at end of file diff --git a/src/r3-api-socket-0.js b/src/r3-api-socket-0.js index b172441..2542bcb 100644 --- a/src/r3-api-socket-0.js +++ b/src/r3-api-socket-0.js @@ -58,11 +58,29 @@ R3.API.Socket = function( this.peerId = peerId; if (R3.Utils.UndefinedOrNull(server)) { - server = new R3.API.Server( - null, - null, - R3.API.Server.PROTOCOL_WEBSOCKET_SSL + R3.Event.Emit( + R3.Event.GET_WEBSOCKET_CONFIG, + 'hello', + function(websocketConfig) { + if (websocketConfig) { + server = new R3.API.Server( + null, + null, + websocketConfig.protocol, + websocketConfig.context, + websocketConfig.application, + websocketConfig.domain + ); + } else { + server = new R3.API.Server( + null, + null, + R3.API.Server.PROTOCOL_WEBSOCKET_SSL + ); + } + } ); + } this.server = server; diff --git a/src/r3-server.js b/src/r3-server.js index d5b5c10..3dfefa2 100644 --- a/src/r3-server.js +++ b/src/r3-server.js @@ -1,5 +1,5 @@ /** - * Creates a Server object + * R3.Server * @param apiServer R3.API.Server * @constructor */ @@ -16,7 +16,11 @@ R3.Server = function( apiServer.id, apiServer.name, apiServer.protocol, + apiServer.context, + apiServer.application, + apiServer.domain, apiServer.ip, + apiServer.preferIp, apiServer.port, apiServer.protocols, apiServer.parentEntity @@ -41,20 +45,40 @@ R3.Server.prototype.createInstance = function() { * Updates the instance with the current state */ R3.Server.prototype.updateInstance = function(property) { + if (property === 'protocol') { console.log('todo: server protocol update'); } + + if (property === 'context') { + console.log('todo: server context update'); + } + + if (property === 'application') { + console.log('todo: server application update'); + } + + if (property === 'domain') { + console.log('todo: server domain update'); + } + if (property === 'ip') { console.log('todo: server ip update'); } + + if (property === 'preferIp') { + console.log('todo: server preferIp update'); + } + if (property === 'port') { console.log('todo: server port update'); } + if (property === 'protocols') { console.log('todo: server protocols update'); } - R3.D3.Texture.prototype.updateInstance.call(this, property); + R3.Component.prototype.updateInstance.call(this, property); }; /** @@ -67,7 +91,11 @@ R3.Server.prototype.toApiObject = function() { this.id, this.name, this.protocol, + this.context, + this.application, + this.domain, this.ip, + this.preferIp, this.port, this.protocols, R3.Utils.IdOrNull(this.parentEntity) @@ -75,13 +103,12 @@ R3.Server.prototype.toApiObject = function() { }; -/** - * Converts from an Object Server to a R3.Server - * @param objectServer Object - * @returns {R3.Server} - * @constructor - */ -R3.Server.FromObject = function(objectServer) { - var apiServer = R3.API.Server.FromObject(objectServer); - return new R3.Server(apiServer); -}; +R3.Server.prototype.getURL = function() { + + if (this.preferIp) { + return this.protocol + '://' + this.ip + ':' + this.port; + } else { + return this.protocol + '://' + this.context + '-' + this.application + '.' + this.domain + ':' + this.port + } + +}; \ No newline at end of file