websocket

beta.r3js.org
-=ybafelo 2018-07-24 14:54:45 +02:00
parent 64557daad3
commit 16f21ebcc8
4 changed files with 23 additions and 52 deletions

View File

@ -30,7 +30,7 @@ R3.API.Server = function(
this.name = name;
if (R3.Utils.UndefinedOrNull(protocol)) {
protocol = 'http';
protocol = R3.API.Server.PROTOCOL_HTTP_SSL;
}
this.protocol = protocol;
@ -40,7 +40,7 @@ R3.API.Server = function(
this.ip = ip;
if (R3.Utils.UndefinedOrNull(port)) {
port = 80;
port = R3.API.Server.PORT_SECURE;
}
this.port = port;
@ -59,21 +59,14 @@ R3.API.Server = function(
R3.API.Server.prototype = Object.create(R3.API.Component.prototype);
R3.API.Server.prototype.constructor = R3.API.Server;
/**
* Creates an API Server from an Object Server
* @param objectServer
* @constructor
*/
R3.API.Server.FromObject = function(objectServer) {
R3.API.Server.PROTOCOL_HTTP = 'http';
R3.API.Server.PROTOCOL_HTTP_SSL = 'https';
R3.API.Server.PROTOCOL_WEBSOCKET = 'ws';
R3.API.Server.PROTOCOL_WEBSOCKET_SSL = 'wss';
return new R3.API.Server(
objectServer.id,
objectServer.name,
objectServer.protocol,
objectServer.ip,
objectServer.port,
objectServer.protocols,
objectServer.parentEntity
);
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;
};

View File

@ -45,7 +45,11 @@ R3.API.Socket = function(
this.peerId = peerId;
if (R3.Utils.UndefinedOrNull(server)) {
server = null;
server = new R3.API.Server(
null,
null,
R3.API.Server.PROTOCOL_WEBSOCKET_SSL
);
}
this.server = server;

View File

@ -2,6 +2,7 @@
* Creates a Socket object
* @param socket R3.Socket
* @param apiSocket R3.API.Socket
* @property socketType
* @constructor
*/
R3.Socket = function(
@ -57,7 +58,7 @@ R3.Socket.prototype.constructor = R3.Socket;
R3.Socket.prototype.createInstance = function() {
this.instance = true;
this.instance = new WebSocket(this.server.getURL());
R3.Component.prototype.createInstance.call(this);
};
@ -66,18 +67,23 @@ R3.Socket.prototype.createInstance = function() {
* Updates the instance with the current state
*/
R3.Socket.prototype.updateInstance = function(property) {
if (property === 'socketType') {
console.log('todo: implement socket socketType update');
}
if (property === 'roomId') {
console.log('todo: implement socket roomId update');
}
if (property === 'peerId') {
console.log('todo: implement socket peerId update');
}
if (property === 'server') {
console.log('todo: implement socket server update');
}
R3.D3.Texture.prototype.updateInstance.call(this, property);
};
@ -86,7 +92,6 @@ R3.Socket.prototype.updateInstance = function(property) {
* @returns {R3.API.Socket}
*/
R3.Socket.prototype.toApiObject = function() {
return new R3.API.Socket(
this.id,
this.name,
@ -96,20 +101,4 @@ R3.Socket.prototype.toApiObject = function() {
R3.Utils.IdOrNull(this.server),
R3.Utils.IdOrNull(this.parentEntity)
);
};
/**
* Converts from an Object Socket to a R3.Socket
* @param sockets R3.SocketsRuntime
* @param objectSocket Object
* @returns {R3.Socket}
* @constructor
*/
R3.Socket.FromObject = function(sockets, objectSocket) {
var apiSocket = R3.API.Socket.FromObject(objectSocket);
return new R3.Socket(
sockets,
apiSocket
);
};

View File

@ -102,18 +102,3 @@ R3.Socket.Cast.prototype.toApiObject = function() {
);
};
/**
* Converts from an Object Cast to a R3.Socket.Cast
* @param sockets R3.SocketsRuntime
* @param objectCast Object
* @returns {R3.Socket.Cast}
* @constructor
*/
R3.Socket.Cast.FromObject = function(sockets, objectCast) {
var apiCast = R3.API.Socket.Cast.FromObject(objectCast);
return new R3.Socket.Cast(
sockets,
apiCast
);
};