Socket components probably ok now

beta.r3js.org
-=ybafelo 2018-08-17 14:53:02 +02:00
parent f743e41af0
commit 534091283e
9 changed files with 102 additions and 162 deletions

View File

@ -242,7 +242,7 @@ R3.Component.MATERIAL_STANDARD = 0x2;
R3.Component.RENDERER = 0x3;
R3.Component.SERVER = 0x4;
R3.Component.CAMERA_PERSPECTIVE = 0x5;
R3.Component.SOCKET = 0x6;
//R3.Component.SOCKET = 0x6;
R3.Component.MESH = 0x7;
R3.Component.SPLINE = 0x8;
R3.Component.SHADOW_DIRECTIONAL = 0x9;
@ -465,12 +465,12 @@ R3.Component.GetComponentInfo = function(number) {
constructor : R3.D3.Camera.Perspective,
apiConstructor : R3.D3.API.Camera.Perspective
};
case 0x6 : return {
case 0x6 : return;/*{
name : 'R3.Socket',
runtime : R3.Component.SOCKET_RUNTIME,
constructor : R3.Socket,
apiConstructor : R3.API.Socket
};
};*/
case 0x7 : return {
name : 'R3.D3.Mesh',
runtime : R3.Component.GRAPHICS_RUNTIME,

View File

@ -1,5 +1,5 @@
/**
* Raw Socket API object - should always correspond with the Socket Schema
* R3.API.Socket
* @param id
* @param name
* @param socketType
@ -24,15 +24,28 @@ R3.API.Socket = function(
}
this.id = id;
if (R3.Utils.UndefinedOrNull(socketType)) {
socketType = R3.API.Socket.SOCKET_TYPE_CAST;
}
this.socketType = socketType;
if (R3.Utils.UndefinedOrNull(name)) {
name = 'Socket (' + this.id + ')';
switch (this.socketType) {
case R3.API.Socket.SOCKET_TYPE_CAST :
name = 'Socket Cast';
break;
case R3.API.Socket.SOCKET_TYPE_RECEIVE:
name = 'Socket Receive';
break;
default :
console.warn('no nice name for socket');
name = 'socket';
}
name += ' (' + this.id + ')';
}
this.name = name;
if (R3.Utils.UndefinedOrNull(socketType)) {
socketType = R3.API.Socket.TYPE_NONE;
}
this.socketType = socketType;
if (R3.Utils.UndefinedOrNull(roomId)) {
roomId = 'room_' + R3.Utils.RandomId();
@ -53,26 +66,33 @@ R3.API.Socket = function(
}
this.server = server;
var componentType = R3.Component.SOCKET;
if (this.socketType === R3.API.Socket.TYPE_CAST) {
componentType = R3.Component.SOCKET_CAST;
}
if (this.socketType === R3.API.Socket.TYPE_RECEIVE) {
componentType = R3.Component.SOCKET_RECEIVE;
}
R3.API.Component.call(
this,
componentType,
R3.API.Socket.GetComponentType(this.socketType),
parentEntity
);
};
R3.API.Socket.GetComponentType = function(socketType) {
var componentType = null;
switch (socketType) {
case R3.API.Socket.SOCKET_TYPE_CAST :
componentType = R3.Component.SOCKET_CAST;
break;
case R3.API.Socket.SOCKET_TYPE_RECEIVE :
componentType = R3.Component.SOCKET_RECEIVE;
break;
default :
console.error('could not determine socket component type')
}
return componentType;
};
R3.API.Socket.prototype = Object.create(R3.API.Component.prototype);
R3.API.Socket.prototype.constructor = R3.API.Socket;
R3.API.Socket.TYPE_NONE = 0x1;
R3.API.Socket.TYPE_CAST = 0x2;
R3.API.Socket.TYPE_RECEIVE = 0x3;
R3.API.Socket.SOCKET_TYPE_CAST = 0x1;
R3.API.Socket.SOCKET_TYPE_RECEIVE = 0x2;

View File

@ -1,5 +1,5 @@
/**
* Raw Cast API object - should always correspond with the Cast Schema
* R3.API.Socket.Cast
* @param apiSocket
* @param castType
* @param source
@ -15,20 +15,13 @@ R3.API.Socket.Cast = function(
if (R3.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {
socketType : R3.API.Socket.SOCKET_CAST
socketType : R3.API.Socket.SOCKET_TYPE_CAST
};
}
R3.API.Socket.call(
this,
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (R3.Utils.UndefinedOrNull(apiSocket.socketType)) {
apiSocket.socketType = R3.API.Socket.SOCKET_TYPE_CAST;
}
if (R3.Utils.UndefinedOrNull(castType)) {
castType = R3.API.Socket.Cast.CAST_TYPE_ROOM;
@ -45,34 +38,22 @@ R3.API.Socket.Cast = function(
}
this.sourceProperties = sourceProperties;
R3.API.Component.call(
R3.API.Socket.call(
this,
R3.Component.SOCKET_CAST
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
};
R3.API.Socket.Cast.prototype = Object.create(R3.API.Socket.prototype);
R3.API.Socket.Cast.prototype.constructor = R3.API.Socket.Cast.Receive;
R3.API.Socket.Cast.prototype.constructor = R3.API.Socket.Cast;
R3.API.Socket.Cast.CAST_TYPE_ROOM = 0x1;
R3.API.Socket.Cast.CAST_TYPE_PEER = 0x2;
R3.API.Socket.Cast.CAST_TYPE_ALL = 0x3;
R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;
/**
* Creates an API.Socket.Cast from an Object Cast
* @param objectSocketCast
* @constructor
*/
R3.API.Socket.Cast.FromObject = function(objectSocketCast) {
var apiSocket = R3.API.Socket.FromObject(objectSocketCast);
return new R3.API.Socket.Cast(
apiSocket,
objectSocketCast.castType,
objectSocketCast.source,
objectSocketCast.sourceProperties
);
};
R3.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;

View File

@ -1,5 +1,5 @@
/**
* Raw Socket.Receive API object - should always correspond with the Socket.Receive Schema
* R3.API.Socket.Receive
* @param apiSocket
* @param receiveType
* @param destination
@ -15,20 +15,13 @@ R3.API.Socket.Receive = function(
if (R3.Utils.UndefinedOrNull(apiSocket)) {
apiSocket = {
socketType : R3.API.Socket.SOCKET_RECEIVE
socketType : R3.API.Socket.SOCKET_TYPE_RECEIVE
};
}
R3.API.Socket.call(
this,
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
if (R3.Utils.UndefinedOrNull(apiSocket.socketType)) {
apiSocket.socketType = R3.API.Socket.SOCKET_TYPE_RECEIVE;
}
if (R3.Utils.UndefinedOrNull(receiveType)) {
receiveType = R3.API.Socket.Receive.RECEIVE_TYPE_ROOM;
@ -45,9 +38,15 @@ R3.API.Socket.Receive = function(
}
this.destinationProperties = destinationProperties;
R3.API.Component.call(
R3.API.Socket.call(
this,
R3.Component.SOCKET_RECEIVE
apiSocket.id,
apiSocket.name,
apiSocket.socketType,
apiSocket.roomId,
apiSocket.peerId,
apiSocket.server,
apiSocket.parentEntity
);
};
@ -56,22 +55,3 @@ R3.API.Socket.Receive.prototype.constructor = R3.API.Socket.Receive;
R3.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1;
R3.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2;
/**
* Creates an API Socket.Receive from an Object Socket.Receive
* @param socket R3.SocketsRuntime
* @param objectSocketReceive
* @constructor
*/
R3.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) {
var apiSocket = R3.API.Socket.FromObject(objectSocketReceive);
return new R3.API.Socket.Receive(
apiSocket,
objectSocketReceive.receiveType,
objectSocketReceive.destination,
objectSocketReceive.destinationProperties
);
};

View File

@ -1,5 +1,5 @@
/**
* Raw Light API object - should always correspond with the Light Schema
* R3.D3.API.Light.Ambient
* @constructor
* @param apiLight
*/
@ -30,4 +30,4 @@ R3.D3.API.Light.Ambient = function(
};
R3.D3.API.Light.Ambient.prototype = Object.create(R3.D3.API.Light.prototype);
R3.D3.API.Light.Ambient.prototype.constructor = R3.D3.API.Light.Ambient;
R3.D3.API.Light.Ambient.prototype.constructor = R3.D3.API.Light.Ambient;

View File

@ -34,7 +34,7 @@ R3.D3.Light = function(
);
var linkedObjects = {
'parentScene' : R3.D3.Scene
parentScene : R3.D3.Scene
};
switch (apiLight.lightType) {

View File

@ -38,12 +38,15 @@ R3.Socket = function(
server : R3.Server
};
if (this.socketType === R3.API.Socket.TYPE_CAST) {
linkedObjects.source = R3.Component;
}
if (this.socketType === R3.API.Socket.TYPE_RECEIVE) {
linkedObjects.destination = R3.Component;
switch (this.socketType) {
case R3.API.Socket.SOCKET_TYPE_CAST :
linkedObjects.source = R3.Component;
break;
case R3.API.Socket.SOCKET_TYPE_RECEIVE:
linkedObjects.destination = R3.Component;
break;
default:
break;
}
R3.Component.call(
@ -84,7 +87,7 @@ R3.Socket.prototype.updateInstance = function(property) {
console.log('todo: implement socket server update');
}
R3.D3.Texture.prototype.updateInstance.call(this, property);
R3.Component.prototype.updateInstance.call(this, property);
};
/**

View File

@ -1,5 +1,5 @@
/**
* Creates a Cast object
* R3.Socket.Cast
* @param socket R3.Socket
* @param apiSocketCast
* @constructor
@ -14,7 +14,7 @@ R3.Socket.Cast = function(
if (R3.Utils.UndefinedOrNull(apiSocketCast)) {
apiSocketCast = {
socketType : R3.API.Socket.TYPE_CAST
socketType : R3.API.Socket.SOCKET_TYPE_CAST
};
}
@ -37,9 +37,6 @@ R3.Socket.Cast.prototype = Object.create(R3.Socket.prototype);
R3.Socket.Cast.prototype.constructor = R3.Socket.Cast;
R3.Socket.Cast.prototype.createInstance = function() {
this.instance = true;
R3.Socket.prototype.createInstance.call(this);
};
@ -48,13 +45,8 @@ R3.Socket.Cast.prototype.createInstance = function() {
*/
R3.Socket.Cast.prototype.updateInstance = function(property) {
R3.Socket.prototype.updateInstance.call(
this,
property
);
if (property === 'castType') {
console.log('todo: implement socket.receive.castType update');
console.log('todo: implement castType update');
}
if (property === 'source') {
@ -73,9 +65,10 @@ R3.Socket.Cast.prototype.updateInstance = function(property) {
}
if (property === 'sourceProperties') {
console.log('todo: implement socket.receive.sourceProperties update');
console.log('todo: implement sourceProperties update');
}
R3.Socket.prototype.updateInstance.call(this, property);
};
/**
@ -84,21 +77,14 @@ R3.Socket.Cast.prototype.updateInstance = function(property) {
*/
R3.Socket.Cast.prototype.toApiObject = function() {
var apiSocket = new R3.API.Socket(
this.id,
this.name,
this.socketType,
this.roomId,
this.peerId,
R3.Utils.IdOrNull(this.server),
R3.Utils.IdOrNull(this.parentEntity)
);
var apiSocket = new R3.Socket.prototype.toApiObject.call(this);
return new R3.API.Socket.Cast(
var apiSocketCast = new R3.API.Socket.Cast(
apiSocket,
this.castType,
R3.Utils.IdOrNull(this.source),
this.sourceProperties
);
return apiSocketCast;
};

View File

@ -1,5 +1,5 @@
/**
* Creates a Receive object
* R3.Socket.Receive
* @param socket R3.Socket
* @param apiSocketReceive R3.API.Socket.Receive
* @constructor
@ -14,7 +14,7 @@ R3.Socket.Receive = function(
if (R3.Utils.UndefinedOrNull(apiSocketReceive)) {
apiSocketReceive = {
socketType : R3.API.Socket.TYPE_RECEIVE
socketType : R3.API.Socket.SOCKET_TYPE_RECEIVE
};
}
@ -38,9 +38,6 @@ R3.Socket.Receive.prototype = Object.create(R3.Socket.prototype);
R3.Socket.Receive.prototype.constructor = R3.Socket.Receive;
R3.Socket.Receive.prototype.createInstance = function() {
this.instance = true;
R3.Socket.prototype.createInstance.call(this);
};
@ -49,13 +46,8 @@ R3.Socket.Receive.prototype.createInstance = function() {
*/
R3.Socket.Receive.prototype.updateInstance = function(property) {
R3.Socket.prototype.updateInstance.call(
this,
property
);
if (property === 'receiveType') {
console.log('todo: implement socket.receive.receiveType update');
console.log('todo: implement receiveType update');
}
if (property === 'destination') {
@ -75,8 +67,10 @@ R3.Socket.Receive.prototype.updateInstance = function(property) {
}
if (property === 'destinationProperties') {
console.log('todo: implement socket.receive.destinationProperties update');
console.log('todo: implement destinationProperties update');
}
R3.Socket.prototype.updateInstance.call(this, property);
};
/**
@ -85,39 +79,15 @@ R3.Socket.Receive.prototype.updateInstance = function(property) {
*/
R3.Socket.Receive.prototype.toApiObject = function() {
var apiSocket = new R3.API.Socket(
this.id,
this.name,
this.socketType,
this.roomId,
this.peerId,
R3.Utils.IdOrNull(this.server),
R3.Utils.IdOrNull(this.parentEntity)
);
var apiSocket = new R3.Socket.prototype.toApiObject.call(this);
return new R3.API.Socket.Receive(
var apiSocketReceive = new R3.API.Socket.Receive(
apiSocket,
this.receiveType,
this.destination,
R3.Utils.IdOrNull(this.destination),
this.destinationProperties
);
};
/**
* Converts from an Object Receive to a R3.Socket.Receive
* @param sockets R3.SocketsRuntime
* @param objectReceive Object
* @returns {R3.Socket.Receive}
* @constructor
*/
R3.Socket.Receive.FromObject = function(sockets, objectReceive) {
var apiSocketReceive = R3.API.Socket.Receive.FromObject(objectReceive);
return new R3.Socket.Receive(
sockets,
apiSocketReceive
);
return apiSocketReceive;
};