server update

beta.r3js.org
-=ybafelo 2018-08-20 17:31:48 +02:00
parent 534091283e
commit ae20cb579d
4 changed files with 93 additions and 22 deletions

View File

@ -135,6 +135,7 @@ R3.Event.COMPONENT_REPLACED = 0x75;
R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76; R3.Event.ENGINE_FIRED_PARTICLES_ZERO = 0x76;
R3.Event.GET_DEFAULT_SCENE = 0x77; R3.Event.GET_DEFAULT_SCENE = 0x77;
R3.Event.GET_DEFAULT_CAMERA = 0x78; R3.Event.GET_DEFAULT_CAMERA = 0x78;
R3.Event.GET_WEBSOCKET_CONFIG = 0x79;
/** /**
* Returns string name of event ID * Returns string name of event ID
@ -265,6 +266,7 @@ R3.Event.GetEventName = function(number) {
case 0x76 : return 'engine_fired_particles_zero'; case 0x76 : return 'engine_fired_particles_zero';
case 0x77 : return 'get_default_scene'; case 0x77 : return 'get_default_scene';
case 0x78 : return 'get_default_camera'; case 0x78 : return 'get_default_camera';
case 0x79 : return 'get_websocket_config';
break; break;
} }

View File

@ -1,9 +1,13 @@
/** /**
* Raw Server API object - should always correspond with the Server Schema * R3.API.Server
* @param id * @param id
* @param name * @param name
* @param protocol * @param protocol
* @param context
* @param application
* @param domain
* @param ip * @param ip
* @param preferIp - Set to true to use IP instead of resolving DNS at getUrl() runtime
* @param port * @param port
* @param protocols * @param protocols
* @param parentEntity * @param parentEntity
@ -13,7 +17,11 @@ R3.API.Server = function(
id, id,
name, name,
protocol, protocol,
context,
application,
domain,
ip, ip,
preferIp,
port, port,
protocols, protocols,
parentEntity parentEntity
@ -34,11 +42,31 @@ R3.API.Server = function(
} }
this.protocol = protocol; 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)) { if (R3.Utils.UndefinedOrNull(ip)) {
ip = '127.0.0.1'; ip = '127.0.0.1';
} }
this.ip = ip; this.ip = ip;
if (R3.Utils.UndefinedOrNull(preferIp)) {
preferIp = false;
}
this.preferIp = preferIp;
if (R3.Utils.UndefinedOrNull(port)) { if (R3.Utils.UndefinedOrNull(port)) {
port = R3.API.Server.PORT_SECURE; 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.PROTOCOL_WEBSOCKET_SSL = 'wss';
R3.API.Server.PORT_INSECURE = 80; R3.API.Server.PORT_INSECURE = 80;
R3.API.Server.PORT_SECURE = 443; R3.API.Server.PORT_SECURE = 443;
R3.API.Server.prototype.getURL = function() {
return this.protocol + '://' + this.ip + ':' + this.port;
};

View File

@ -58,11 +58,29 @@ R3.API.Socket = function(
this.peerId = peerId; this.peerId = peerId;
if (R3.Utils.UndefinedOrNull(server)) { if (R3.Utils.UndefinedOrNull(server)) {
server = new R3.API.Server( R3.Event.Emit(
null, R3.Event.GET_WEBSOCKET_CONFIG,
null, 'hello',
R3.API.Server.PROTOCOL_WEBSOCKET_SSL 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; this.server = server;

View File

@ -1,5 +1,5 @@
/** /**
* Creates a Server object * R3.Server
* @param apiServer R3.API.Server * @param apiServer R3.API.Server
* @constructor * @constructor
*/ */
@ -16,7 +16,11 @@ R3.Server = function(
apiServer.id, apiServer.id,
apiServer.name, apiServer.name,
apiServer.protocol, apiServer.protocol,
apiServer.context,
apiServer.application,
apiServer.domain,
apiServer.ip, apiServer.ip,
apiServer.preferIp,
apiServer.port, apiServer.port,
apiServer.protocols, apiServer.protocols,
apiServer.parentEntity apiServer.parentEntity
@ -41,20 +45,40 @@ R3.Server.prototype.createInstance = function() {
* Updates the instance with the current state * Updates the instance with the current state
*/ */
R3.Server.prototype.updateInstance = function(property) { R3.Server.prototype.updateInstance = function(property) {
if (property === 'protocol') { if (property === 'protocol') {
console.log('todo: server protocol update'); 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') { if (property === 'ip') {
console.log('todo: server ip update'); console.log('todo: server ip update');
} }
if (property === 'preferIp') {
console.log('todo: server preferIp update');
}
if (property === 'port') { if (property === 'port') {
console.log('todo: server port update'); console.log('todo: server port update');
} }
if (property === 'protocols') { if (property === 'protocols') {
console.log('todo: server protocols update'); 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.id,
this.name, this.name,
this.protocol, this.protocol,
this.context,
this.application,
this.domain,
this.ip, this.ip,
this.preferIp,
this.port, this.port,
this.protocols, this.protocols,
R3.Utils.IdOrNull(this.parentEntity) R3.Utils.IdOrNull(this.parentEntity)
@ -75,13 +103,12 @@ R3.Server.prototype.toApiObject = function() {
}; };
/** R3.Server.prototype.getURL = function() {
* Converts from an Object Server to a R3.Server
* @param objectServer Object if (this.preferIp) {
* @returns {R3.Server} return this.protocol + '://' + this.ip + ':' + this.port;
* @constructor } else {
*/ return this.protocol + '://' + this.context + '-' + this.application + '.' + this.domain + ':' + this.port
R3.Server.FromObject = function(objectServer) { }
var apiServer = R3.API.Server.FromObject(objectServer);
return new R3.Server(apiServer); };
};