cast and receive sockets
parent
23e6b4101b
commit
6e2dbf188d
File diff suppressed because one or more lines are too long
1123
build/game-lib.js
1123
build/game-lib.js
File diff suppressed because it is too large
Load Diff
|
@ -204,12 +204,12 @@ GameLib.Component.prototype.toString = function() {
|
||||||
return this.id;
|
return this.id;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameLib.Component.RECEIVE = 0x1;
|
GameLib.Component.SOCKET_RECEIVE = 0x1;
|
||||||
GameLib.Component.MATERIAL = 0x2;
|
GameLib.Component.MATERIAL = 0x2;
|
||||||
GameLib.Component.RENDERER = 0x3;
|
GameLib.Component.RENDERER = 0x3;
|
||||||
//GameLib.Component.LOOK_AT = 0x4;
|
GameLib.Component.SERVER = 0x4;
|
||||||
GameLib.Component.CAMERA = 0x5;
|
GameLib.Component.CAMERA = 0x5;
|
||||||
//GameLib.Component.FOLLOW = 0x6;
|
GameLib.Component.SOCKET = 0x6;
|
||||||
GameLib.Component.MESH = 0x7;
|
GameLib.Component.MESH = 0x7;
|
||||||
GameLib.Component.SPLINE = 0x8;
|
GameLib.Component.SPLINE = 0x8;
|
||||||
GameLib.Component.LIGHT = 0x9;
|
GameLib.Component.LIGHT = 0x9;
|
||||||
|
@ -284,7 +284,7 @@ GameLib.Component.SYSTEM_PARTICLE = 0x53;
|
||||||
GameLib.Component.PARTICLE = 0x54;
|
GameLib.Component.PARTICLE = 0x54;
|
||||||
GameLib.Component.AUDIO = 0x55;
|
GameLib.Component.AUDIO = 0x55;
|
||||||
GameLib.Component.SYSTEM_AUDIO = 0x56;
|
GameLib.Component.SYSTEM_AUDIO = 0x56;
|
||||||
GameLib.Component.CAST = 0x57;
|
GameLib.Component.SOCKET_CAST = 0x57;
|
||||||
GameLib.Component.MAX_COMPONENTS = 0x58;
|
GameLib.Component.MAX_COMPONENTS = 0x58;
|
||||||
|
|
||||||
GameLib.Component.GRAPHICS_RUNTIME = 0x1;
|
GameLib.Component.GRAPHICS_RUNTIME = 0x1;
|
||||||
|
@ -311,10 +311,10 @@ GameLib.Component.GetCompentTypes = function(constructor) {
|
||||||
GameLib.Component.GetComponentInfo = function(number) {
|
GameLib.Component.GetComponentInfo = function(number) {
|
||||||
switch(number) {
|
switch(number) {
|
||||||
case 0x1 : return {
|
case 0x1 : return {
|
||||||
name : 'GameLib.Receive',
|
name : 'GameLib.Socket.Receive',
|
||||||
runtime : GameLib.Component.SOCKET_RUNTIME,
|
runtime : GameLib.Component.SOCKET_RUNTIME,
|
||||||
constructor : GameLib.Receive,
|
constructor : GameLib.Socket.Receive,
|
||||||
apiConstructor : GameLib.API.Receive
|
apiConstructor : GameLib.API.Socket.Receive
|
||||||
};
|
};
|
||||||
case 0x2 : return {
|
case 0x2 : return {
|
||||||
name : 'GameLib.D3.Material',
|
name : 'GameLib.D3.Material',
|
||||||
|
@ -328,14 +328,24 @@ GameLib.Component.GetComponentInfo = function(number) {
|
||||||
constructor : GameLib.D3.Renderer,
|
constructor : GameLib.D3.Renderer,
|
||||||
apiConstructor : GameLib.D3.API.Renderer
|
apiConstructor : GameLib.D3.API.Renderer
|
||||||
};
|
};
|
||||||
case 0x4 : return null;
|
case 0x4 : return {
|
||||||
|
name : 'GameLib.Server',
|
||||||
|
runtime : GameLib.Component.DEFAULT_RUNTIME,
|
||||||
|
constructor : GameLib.Server,
|
||||||
|
apiConstructor : GameLib.API.Server
|
||||||
|
};
|
||||||
case 0x5 : return {
|
case 0x5 : return {
|
||||||
name : 'GameLib.D3.Camera',
|
name : 'GameLib.D3.Camera',
|
||||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
constructor : GameLib.D3.Camera,
|
constructor : GameLib.D3.Camera,
|
||||||
apiConstructor : GameLib.D3.API.Camera
|
apiConstructor : GameLib.D3.API.Camera
|
||||||
};
|
};
|
||||||
case 0x6 : return null;
|
case 0x6 : return {
|
||||||
|
name : 'GameLib.Socket',
|
||||||
|
runtime : GameLib.Component.SOCKET_RUNTIME,
|
||||||
|
constructor : GameLib.Socket,
|
||||||
|
apiConstructor : GameLib.API.Socket
|
||||||
|
};
|
||||||
case 0x7 : return {
|
case 0x7 : return {
|
||||||
name : 'GameLib.D3.Mesh',
|
name : 'GameLib.D3.Mesh',
|
||||||
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
runtime : GameLib.Component.GRAPHICS_RUNTIME,
|
||||||
|
@ -757,10 +767,10 @@ GameLib.Component.GetComponentInfo = function(number) {
|
||||||
apiConstructor : GameLib.API.System
|
apiConstructor : GameLib.API.System
|
||||||
};
|
};
|
||||||
case 0x57 : return {
|
case 0x57 : return {
|
||||||
name : 'GameLib.Cast',
|
name : 'GameLib.Socket.Cast',
|
||||||
runtime : GameLib.Component.SOCKET_RUNTIME,
|
runtime : GameLib.Component.SOCKET_RUNTIME,
|
||||||
constructor : GameLib.Cast,
|
constructor : GameLib.Socket.Cast,
|
||||||
apiConstructor : GameLib.API.Cast
|
apiConstructor : GameLib.API.Socket.Cast
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
/**
|
|
||||||
* Raw Cast API object - should always correspond with the Cast Schema
|
|
||||||
* @param id
|
|
||||||
* @param name
|
|
||||||
* @param castType
|
|
||||||
* @param source
|
|
||||||
* @param sourceProperties
|
|
||||||
* @param roomId
|
|
||||||
* @param peerId
|
|
||||||
* @param serverIp
|
|
||||||
* @param port
|
|
||||||
* @param parentEntity
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Cast = function(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
castType,
|
|
||||||
source,
|
|
||||||
sourceProperties,
|
|
||||||
roomId,
|
|
||||||
peerId,
|
|
||||||
serverIp,
|
|
||||||
port,
|
|
||||||
parentEntity
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Cast (' + this.id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(castType)) {
|
|
||||||
castType = GameLib.API.Cast.CAST_TYPE_ROOM;
|
|
||||||
}
|
|
||||||
this.castType = castType;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(source)) {
|
|
||||||
source = null;
|
|
||||||
}
|
|
||||||
this.source = source;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(sourceProperties)) {
|
|
||||||
sourceProperties = null;
|
|
||||||
}
|
|
||||||
this.sourceProperties = sourceProperties;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(roomId)) {
|
|
||||||
roomId = 'default';
|
|
||||||
}
|
|
||||||
this.roomId = roomId;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(peerId)) {
|
|
||||||
peerId = null;
|
|
||||||
}
|
|
||||||
this.peerId = peerId;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
|
|
||||||
serverIp = '127.0.0.1';
|
|
||||||
}
|
|
||||||
this.serverIp = serverIp;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(port)) {
|
|
||||||
port = 80;
|
|
||||||
}
|
|
||||||
this.port = port;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.CAST,
|
|
||||||
parentEntity
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.API.Cast.prototype = Object.create(GameLib.Component.prototype);
|
|
||||||
GameLib.API.Cast.prototype.constructor = GameLib.API.Cast;
|
|
||||||
|
|
||||||
GameLib.API.Cast.CAST_TYPE_ROOM = 0x1;
|
|
||||||
GameLib.API.Cast.CAST_TYPE_PEER = 0x2;
|
|
||||||
GameLib.API.Cast.CAST_TYPE_ALL = 0x3;
|
|
||||||
GameLib.API.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an API Cast from an Object Cast
|
|
||||||
* @param objectCast
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Cast.FromObject = function(objectCast) {
|
|
||||||
|
|
||||||
return new GameLib.API.Cast(
|
|
||||||
objectCast.id,
|
|
||||||
objectCast.name,
|
|
||||||
objectCast.castType,
|
|
||||||
objectCast.source,
|
|
||||||
objectCast.sourceProperties,
|
|
||||||
objectCast.roomId,
|
|
||||||
objectCast.peerId,
|
|
||||||
objectCast.serverIp,
|
|
||||||
objectCast.port,
|
|
||||||
objectCast.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
|
@ -1,107 +0,0 @@
|
||||||
/**
|
|
||||||
* Raw Receive API object - should always correspond with the Receive Schema
|
|
||||||
* @param id
|
|
||||||
* @param name
|
|
||||||
* @param receiveType
|
|
||||||
* @param destination
|
|
||||||
* @param destinationProperties
|
|
||||||
* @param roomId
|
|
||||||
* @param peerId
|
|
||||||
* @param serverIp
|
|
||||||
* @param port
|
|
||||||
* @param parentEntity
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Receive = function(
|
|
||||||
id,
|
|
||||||
name,
|
|
||||||
receiveType,
|
|
||||||
destination,
|
|
||||||
destinationProperties,
|
|
||||||
roomId,
|
|
||||||
peerId,
|
|
||||||
serverIp,
|
|
||||||
port,
|
|
||||||
parentEntity
|
|
||||||
) {
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(id)) {
|
|
||||||
id = GameLib.Utils.RandomId();
|
|
||||||
}
|
|
||||||
this.id = id;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(name)) {
|
|
||||||
name = 'Receive (' + this.id + ')';
|
|
||||||
}
|
|
||||||
this.name = name;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(receiveType)) {
|
|
||||||
receiveType = GameLib.API.Receive.RECEIVE_TYPE_ROOM;
|
|
||||||
}
|
|
||||||
this.receiveType = receiveType;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(destination)) {
|
|
||||||
destination = null;
|
|
||||||
}
|
|
||||||
this.destination = destination;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(destinationProperties)) {
|
|
||||||
destinationProperties = null;
|
|
||||||
}
|
|
||||||
this.destinationProperties = destinationProperties;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(roomId)) {
|
|
||||||
roomId = 'default';
|
|
||||||
}
|
|
||||||
this.roomId = roomId;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(peerId)) {
|
|
||||||
peerId = null;
|
|
||||||
}
|
|
||||||
this.peerId = peerId;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(serverIp)) {
|
|
||||||
serverIp = '127.0.0.1';
|
|
||||||
}
|
|
||||||
this.serverIp = serverIp;
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(port)) {
|
|
||||||
port = 80;
|
|
||||||
}
|
|
||||||
this.port = port;
|
|
||||||
|
|
||||||
GameLib.API.Component.call(
|
|
||||||
this,
|
|
||||||
GameLib.Component.RECEIVE,
|
|
||||||
parentEntity
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.API.Receive.prototype = Object.create(GameLib.Component.prototype);
|
|
||||||
GameLib.API.Receive.prototype.constructor = GameLib.API.Receive;
|
|
||||||
|
|
||||||
GameLib.API.Receive.RECEIVE_TYPE_ROOM = 0x1;
|
|
||||||
GameLib.API.Receive.RECEIVE_TYPE_PEER = 0x2;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an API Receive from an Object Receive
|
|
||||||
* @param objectReceive
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.API.Receive.FromObject = function(objectReceive) {
|
|
||||||
|
|
||||||
return new GameLib.API.Receive(
|
|
||||||
objectReceive.id,
|
|
||||||
objectReceive.name,
|
|
||||||
objectReceive.castType,
|
|
||||||
objectReceive.destination,
|
|
||||||
objectReceive.destinationProperties,
|
|
||||||
objectReceive.roomId,
|
|
||||||
objectReceive.peerId,
|
|
||||||
objectReceive.serverIp,
|
|
||||||
objectReceive.port,
|
|
||||||
objectReceive.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
|
@ -0,0 +1,79 @@
|
||||||
|
/**
|
||||||
|
* Raw Server API object - should always correspond with the Server Schema
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param protocol
|
||||||
|
* @param ip
|
||||||
|
* @param port
|
||||||
|
* @param protocols
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Server = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
protocol,
|
||||||
|
ip,
|
||||||
|
port,
|
||||||
|
protocols,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Server (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(protocol)) {
|
||||||
|
protocol = 'http';
|
||||||
|
}
|
||||||
|
this.protocol = protocol;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(ip)) {
|
||||||
|
ip = '127.0.0.1';
|
||||||
|
}
|
||||||
|
this.ip = ip;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(port)) {
|
||||||
|
port = 80;
|
||||||
|
}
|
||||||
|
this.port = port;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(protocols)) {
|
||||||
|
protocols = [];
|
||||||
|
}
|
||||||
|
this.protocols = protocols;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.SERVER,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.API.Server.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.API.Server.prototype.constructor = GameLib.API.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API Server from an Object Server
|
||||||
|
* @param objectServer
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Server.FromObject = function(objectServer) {
|
||||||
|
|
||||||
|
return new GameLib.API.Server(
|
||||||
|
objectServer.id,
|
||||||
|
objectServer.name,
|
||||||
|
objectServer.protocol,
|
||||||
|
objectServer.ip,
|
||||||
|
objectServer.port,
|
||||||
|
objectServer.protocols,
|
||||||
|
objectServer.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,93 @@
|
||||||
|
/**
|
||||||
|
* Raw Socket API object - should always correspond with the Socket Schema
|
||||||
|
* @param id
|
||||||
|
* @param name
|
||||||
|
* @param socketType
|
||||||
|
* @param roomId
|
||||||
|
* @param peerId
|
||||||
|
* @param server GameLib.Server
|
||||||
|
* @param parentEntity
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket = function(
|
||||||
|
id,
|
||||||
|
name,
|
||||||
|
socketType,
|
||||||
|
roomId,
|
||||||
|
peerId,
|
||||||
|
server,
|
||||||
|
parentEntity
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(id)) {
|
||||||
|
id = GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.id = id;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(name)) {
|
||||||
|
name = 'Socket (' + this.id + ')';
|
||||||
|
}
|
||||||
|
this.name = name;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(socketType)) {
|
||||||
|
socketType = GameLib.API.Socket.TYPE_NONE;
|
||||||
|
}
|
||||||
|
this.socketType = socketType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(roomId)) {
|
||||||
|
roomId = 'room_' + GameLib.Utils.RandomId();
|
||||||
|
}
|
||||||
|
this.roomId = roomId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(peerId)) {
|
||||||
|
peerId = null;
|
||||||
|
}
|
||||||
|
this.peerId = peerId;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(server)) {
|
||||||
|
server = null;
|
||||||
|
}
|
||||||
|
this.server = server;
|
||||||
|
|
||||||
|
var componentType = GameLib.Component.SOCKET;
|
||||||
|
|
||||||
|
if (this.socketType === GameLib.API.Socket.TYPE_CAST) {
|
||||||
|
componentType = GameLib.Component.SOCKET_CAST;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.socketType === GameLib.API.Socket.TYPE_RECEIVE) {
|
||||||
|
componentType = GameLib.Component.SOCKET_RECEIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
componentType,
|
||||||
|
parentEntity
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.API.Socket.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.API.Socket.prototype.constructor = GameLib.API.Socket;
|
||||||
|
|
||||||
|
GameLib.API.Socket.TYPE_NONE = 0x1;
|
||||||
|
GameLib.API.Socket.TYPE_CAST = 0x2;
|
||||||
|
GameLib.API.Socket.TYPE_RECEIVE = 0x3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API Socket from an Object Socket
|
||||||
|
* @param objectSocket
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket.FromObject = function(objectSocket) {
|
||||||
|
|
||||||
|
return new GameLib.API.Socket(
|
||||||
|
objectSocket.id,
|
||||||
|
objectSocket.name,
|
||||||
|
objectSocket.socketType,
|
||||||
|
objectSocket.roomId,
|
||||||
|
objectSocket.peerId,
|
||||||
|
objectSocket.server,
|
||||||
|
objectSocket.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,70 @@
|
||||||
|
/**
|
||||||
|
* Raw Cast API object - should always correspond with the Cast Schema
|
||||||
|
* @param apiSocket
|
||||||
|
* @param castType
|
||||||
|
* @param source
|
||||||
|
* @param sourceProperties
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket.Cast = function(
|
||||||
|
apiSocket,
|
||||||
|
castType,
|
||||||
|
source,
|
||||||
|
sourceProperties
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||||
|
apiSocket = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Socket.call(
|
||||||
|
this,
|
||||||
|
apiSocket
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(castType)) {
|
||||||
|
castType = GameLib.API.Socket.Cast.CAST_TYPE_ROOM;
|
||||||
|
}
|
||||||
|
this.castType = castType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(source)) {
|
||||||
|
source = null;
|
||||||
|
}
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(sourceProperties)) {
|
||||||
|
sourceProperties = null;
|
||||||
|
}
|
||||||
|
this.sourceProperties = sourceProperties;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.SOCKET_CAST
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.API.Socket.Cast.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.API.Socket.Cast.prototype.constructor = GameLib.API.Socket.Cast.Receive;
|
||||||
|
|
||||||
|
GameLib.API.Socket.Cast.CAST_TYPE_ROOM = 0x1;
|
||||||
|
GameLib.API.Socket.Cast.CAST_TYPE_PEER = 0x2;
|
||||||
|
GameLib.API.Socket.Cast.CAST_TYPE_ALL = 0x3;
|
||||||
|
GameLib.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER = 0x4;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API.Socket.Cast from an Object Cast
|
||||||
|
* @param objectSocketCast
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket.Cast.FromObject = function(objectSocketCast) {
|
||||||
|
|
||||||
|
var apiSocket = GameLib.API.Socket.FromObject(objectSocketCast);
|
||||||
|
|
||||||
|
return new GameLib.API.Socket.Cast(
|
||||||
|
apiSocket,
|
||||||
|
objectSocketCast.castType,
|
||||||
|
objectSocketCast.source,
|
||||||
|
objectSocketCast.sourceProperties
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,70 @@
|
||||||
|
/**
|
||||||
|
* Raw Socket.Receive API object - should always correspond with the Socket.Receive Schema
|
||||||
|
* @param apiSocket
|
||||||
|
* @param receiveType
|
||||||
|
* @param destination
|
||||||
|
* @param destinationProperties
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket.Receive = function(
|
||||||
|
apiSocket,
|
||||||
|
receiveType,
|
||||||
|
destination,
|
||||||
|
destinationProperties
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||||
|
apiSocket = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Socket.call(
|
||||||
|
this,
|
||||||
|
apiSocket
|
||||||
|
);
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(receiveType)) {
|
||||||
|
receiveType = GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM;
|
||||||
|
}
|
||||||
|
this.receiveType = receiveType;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(destination)) {
|
||||||
|
destination = null;
|
||||||
|
}
|
||||||
|
this.destination = destination;
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(destinationProperties)) {
|
||||||
|
destinationProperties = null;
|
||||||
|
}
|
||||||
|
this.destinationProperties = destinationProperties;
|
||||||
|
|
||||||
|
GameLib.API.Component.call(
|
||||||
|
this,
|
||||||
|
GameLib.Component.SOCKET_RECEIVE
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.API.Socket.Receive.prototype = Object.create(GameLib.Component.prototype);
|
||||||
|
GameLib.API.Socket.Receive.prototype.constructor = GameLib.API.Socket.Receive;
|
||||||
|
|
||||||
|
GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM = 0x1;
|
||||||
|
GameLib.API.Socket.Receive.RECEIVE_TYPE_PEER = 0x2;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an API Socket.Receive from an Object Socket.Receive
|
||||||
|
* @param socket GameLib.SocketsRuntime
|
||||||
|
* @param objectSocketReceive
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.API.Socket.Receive.FromObject = function(socket, objectSocketReceive) {
|
||||||
|
|
||||||
|
var apiSocket = GameLib.API.Socket.FromObject(objectSocketReceive);
|
||||||
|
|
||||||
|
return new GameLib.API.Socket.Receive(
|
||||||
|
apiSocket,
|
||||||
|
objectSocketReceive.receiveType,
|
||||||
|
objectSocketReceive.destination,
|
||||||
|
objectSocketReceive.destinationProperties
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -1,116 +0,0 @@
|
||||||
/**
|
|
||||||
* Creates a Cast object
|
|
||||||
* @param socket GameLib.Socket
|
|
||||||
* @param apiCast GameLib.API.Cast
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.Cast = function(
|
|
||||||
socket,
|
|
||||||
apiCast
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.socket = socket;
|
|
||||||
this.socket.isNotWebSocketThrow();
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiCast)) {
|
|
||||||
apiCast = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiCast instanceof GameLib.Cast) {
|
|
||||||
return apiCast;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.API.Cast.call(
|
|
||||||
this,
|
|
||||||
apiCast.id,
|
|
||||||
apiCast.name,
|
|
||||||
apiCast.castType,
|
|
||||||
apiCast.source,
|
|
||||||
apiCast.sourceProperties,
|
|
||||||
apiCast.roomId,
|
|
||||||
apiCast.peerId,
|
|
||||||
apiCast.serverIp,
|
|
||||||
apiCast.port,
|
|
||||||
apiCast.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
this.connected = false;
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
|
||||||
this,
|
|
||||||
{
|
|
||||||
source : GameLib.Component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.Cast.prototype = Object.create(GameLib.API.Cast.prototype);
|
|
||||||
GameLib.Cast.prototype.constructor = GameLib.Cast;
|
|
||||||
|
|
||||||
GameLib.Cast.prototype.createInstance = function() {
|
|
||||||
|
|
||||||
this.instance = true;
|
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance with the current state
|
|
||||||
*/
|
|
||||||
GameLib.Cast.prototype.updateInstance = function(property) {
|
|
||||||
if (property === 'source') {
|
|
||||||
if (this.source !== null) {
|
|
||||||
this.sourceProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.source);
|
|
||||||
} else {
|
|
||||||
this.sourceProperties = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.CAST_SOURCE_CHANGED,
|
|
||||||
{
|
|
||||||
component:this
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'sourceProperties') {
|
|
||||||
console.log(this.sourceProperties);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a GameLib.Cast to a new GameLib.API.Cast
|
|
||||||
* @returns {GameLib.API.Cast}
|
|
||||||
*/
|
|
||||||
GameLib.Cast.prototype.toApiObject = function() {
|
|
||||||
|
|
||||||
return new GameLib.API.Cast(
|
|
||||||
this.id,
|
|
||||||
this.name,
|
|
||||||
this.castType,
|
|
||||||
GameLib.Utils.IdOrNull(this.source),
|
|
||||||
this.sourceProperties,
|
|
||||||
this.roomId,
|
|
||||||
this.peerId,
|
|
||||||
this.serverIp,
|
|
||||||
this.port,
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts from an Object Cast to a GameLib.Cast
|
|
||||||
* @param sockets GameLib.SocketsRuntime
|
|
||||||
* @param objectCast Object
|
|
||||||
* @returns {GameLib.Cast}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.Cast.FromObject = function(sockets, objectCast) {
|
|
||||||
var apiCast = GameLib.API.Cast.FromObject(objectCast);
|
|
||||||
return new GameLib.Cast(
|
|
||||||
sockets,
|
|
||||||
apiCast
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -1,118 +0,0 @@
|
||||||
/**
|
|
||||||
* Creates a Receive object
|
|
||||||
* @param socket GameLib.Socket
|
|
||||||
* @param apiReceive GameLib.API.Receive
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.Receive = function(
|
|
||||||
socket,
|
|
||||||
apiReceive
|
|
||||||
) {
|
|
||||||
|
|
||||||
this.socket = socket;
|
|
||||||
this.socket.isNotWebSocketThrow();
|
|
||||||
|
|
||||||
if (GameLib.Utils.UndefinedOrNull(apiReceive)) {
|
|
||||||
apiReceive = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apiReceive instanceof GameLib.Receive) {
|
|
||||||
return apiReceive;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.API.Receive.call(
|
|
||||||
this,
|
|
||||||
apiReceive.id,
|
|
||||||
apiReceive.name,
|
|
||||||
apiReceive.receiveType,
|
|
||||||
apiReceive.destination,
|
|
||||||
apiReceive.destinationProperties,
|
|
||||||
apiReceive.roomId,
|
|
||||||
apiReceive.peerId,
|
|
||||||
apiReceive.serverIp,
|
|
||||||
apiReceive.port,
|
|
||||||
apiReceive.parentEntity
|
|
||||||
);
|
|
||||||
|
|
||||||
this.connected = false;
|
|
||||||
|
|
||||||
GameLib.Component.call(
|
|
||||||
this,
|
|
||||||
{
|
|
||||||
destination : GameLib.Component
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
GameLib.Receive.prototype = Object.create(GameLib.API.Receive.prototype);
|
|
||||||
GameLib.Receive.prototype.constructor = GameLib.Receive;
|
|
||||||
|
|
||||||
GameLib.Receive.prototype.createInstance = function() {
|
|
||||||
|
|
||||||
this.instance = true;
|
|
||||||
|
|
||||||
GameLib.Component.prototype.createInstance.call(this);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Updates the instance with the current state
|
|
||||||
*/
|
|
||||||
GameLib.Receive.prototype.updateInstance = function(property) {
|
|
||||||
|
|
||||||
if (property === 'destination') {
|
|
||||||
|
|
||||||
if (this.destination !== null) {
|
|
||||||
this.destinationProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.destination);
|
|
||||||
} else {
|
|
||||||
this.destinationProperties = {};
|
|
||||||
}
|
|
||||||
|
|
||||||
GameLib.Event.Emit(
|
|
||||||
GameLib.Event.RECEIVE_DESTINATION_CHANGED,
|
|
||||||
{
|
|
||||||
component:this
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (property === 'destinationProperties') {
|
|
||||||
console.log(this.destinationProperties);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts a GameLib.Receive to a new GameLib.API.Receive
|
|
||||||
* @returns {GameLib.API.Receive}
|
|
||||||
*/
|
|
||||||
GameLib.Receive.prototype.toApiObject = function() {
|
|
||||||
|
|
||||||
return new GameLib.API.Receive(
|
|
||||||
this.id,
|
|
||||||
this.name,
|
|
||||||
this.receiveType,
|
|
||||||
GameLib.Utils.IdOrNull(this.destination),
|
|
||||||
this.destinationProperties,
|
|
||||||
this.roomId,
|
|
||||||
this.peerId,
|
|
||||||
this.serverIp,
|
|
||||||
this.port,
|
|
||||||
GameLib.Utils.IdOrNull(this.parentEntity)
|
|
||||||
);
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts from an Object Receive to a GameLib.Receive
|
|
||||||
* @param sockets GameLib.SocketsRuntime
|
|
||||||
* @param objectReceive Object
|
|
||||||
* @returns {GameLib.Receive}
|
|
||||||
* @constructor
|
|
||||||
*/
|
|
||||||
GameLib.Receive.FromObject = function(sockets, objectReceive) {
|
|
||||||
var apiReceive = GameLib.API.Receive.FromObject(objectReceive);
|
|
||||||
return new GameLib.Receive(
|
|
||||||
sockets,
|
|
||||||
apiReceive
|
|
||||||
);
|
|
||||||
};
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/**
|
||||||
|
* Creates a Server object
|
||||||
|
* @param apiServer GameLib.API.Server
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Server = function(
|
||||||
|
apiServer
|
||||||
|
) {
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiServer)) {
|
||||||
|
apiServer = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiServer instanceof GameLib.Server) {
|
||||||
|
return apiServer;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Server.call(
|
||||||
|
this,
|
||||||
|
apiServer.id,
|
||||||
|
apiServer.name,
|
||||||
|
apiServer.protocol,
|
||||||
|
apiServer.ip,
|
||||||
|
apiServer.port,
|
||||||
|
apiServer.protocols,
|
||||||
|
apiServer.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
this.connected = false;
|
||||||
|
|
||||||
|
GameLib.Component.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Server.prototype = Object.create(GameLib.API.Server.prototype);
|
||||||
|
GameLib.Server.prototype.constructor = GameLib.Server;
|
||||||
|
|
||||||
|
GameLib.Server.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = true;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.Server.prototype.updateInstance = function(property) {
|
||||||
|
if (property === 'protocol') {
|
||||||
|
console.log('todo: server protocol update');
|
||||||
|
}
|
||||||
|
if (property === 'ip') {
|
||||||
|
console.log('todo: server ip update');
|
||||||
|
}
|
||||||
|
if (property === 'port') {
|
||||||
|
console.log('todo: server port update');
|
||||||
|
}
|
||||||
|
if (property === 'protocols') {
|
||||||
|
console.log('todo: server protocols update');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.Server to a new GameLib.API.Server
|
||||||
|
* @returns {GameLib.API.Server}
|
||||||
|
*/
|
||||||
|
GameLib.Server.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
return new GameLib.API.Server(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.protocol,
|
||||||
|
this.ip,
|
||||||
|
this.port,
|
||||||
|
this.protocols,
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Server to a GameLib.Server
|
||||||
|
* @param objectServer Object
|
||||||
|
* @returns {GameLib.Server}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Server.FromObject = function(objectServer) {
|
||||||
|
var apiServer = GameLib.API.Server.FromObject(objectServer);
|
||||||
|
return new GameLib.Server(apiServer);
|
||||||
|
};
|
|
@ -0,0 +1,108 @@
|
||||||
|
/**
|
||||||
|
* Creates a Socket object
|
||||||
|
* @param socket GameLib.Socket
|
||||||
|
* @param apiSocket GameLib.API.Socket
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket = function(
|
||||||
|
socket,
|
||||||
|
apiSocket
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.socket = socket;
|
||||||
|
this.socket.isNotWebSocketThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSocket)) {
|
||||||
|
apiSocket = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiSocket instanceof GameLib.Socket) {
|
||||||
|
return apiSocket;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Socket.call(
|
||||||
|
this,
|
||||||
|
apiSocket.id,
|
||||||
|
apiSocket.name,
|
||||||
|
apiSocket.socketType,
|
||||||
|
apiSocket.roomId,
|
||||||
|
apiSocket.peerId,
|
||||||
|
apiSocket.server,
|
||||||
|
apiSocket.parentEntity
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.server instanceof GameLib.API.Server) {
|
||||||
|
this.server = new GameLib.Server(this.server);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.connected = false;
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
{
|
||||||
|
server : GameLib.Server
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Socket.prototype = Object.create(GameLib.API.Socket.prototype);
|
||||||
|
GameLib.Socket.prototype.constructor = GameLib.Socket;
|
||||||
|
|
||||||
|
GameLib.Socket.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = true;
|
||||||
|
|
||||||
|
GameLib.Component.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.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');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.Socket to a new GameLib.API.Socket
|
||||||
|
* @returns {GameLib.API.Socket}
|
||||||
|
*/
|
||||||
|
GameLib.Socket.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
return new GameLib.API.Socket(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.socketType,
|
||||||
|
this.roomId,
|
||||||
|
this.peerId,
|
||||||
|
GameLib.Utils.IdOrNull(this.server),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Socket to a GameLib.Socket
|
||||||
|
* @param sockets GameLib.SocketsRuntime
|
||||||
|
* @param objectSocket Object
|
||||||
|
* @returns {GameLib.Socket}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket.FromObject = function(sockets, objectSocket) {
|
||||||
|
var apiSocket = GameLib.API.Socket.FromObject(objectSocket);
|
||||||
|
return new GameLib.Socket(
|
||||||
|
sockets,
|
||||||
|
apiSocket
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,130 @@
|
||||||
|
/**
|
||||||
|
* Creates a Cast object
|
||||||
|
* @param socket GameLib.Socket
|
||||||
|
* @param apiSocketCast
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Cast = function(
|
||||||
|
socket,
|
||||||
|
apiSocketCast
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.socket = socket;
|
||||||
|
this.socket.isNotWebSocketThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSocketCast)) {
|
||||||
|
apiSocketCast = {
|
||||||
|
socketType : GameLib.API.Socket.TYPE_CAST
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiSocketCast instanceof GameLib.Socket.Cast) {
|
||||||
|
return apiSocketCast;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Socket.Cast.call(
|
||||||
|
this,
|
||||||
|
apiSocketCast,
|
||||||
|
apiSocketCast.castType,
|
||||||
|
apiSocketCast.source,
|
||||||
|
apiSocketCast.sourceProperties
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Socket.call(
|
||||||
|
this,
|
||||||
|
socket,
|
||||||
|
apiSocketCast
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
{
|
||||||
|
source : GameLib.Component
|
||||||
|
}
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Socket.Cast.prototype = Object.create(GameLib.API.Socket.Cast.prototype);
|
||||||
|
GameLib.Socket.Cast.prototype.constructor = GameLib.Socket.Cast;
|
||||||
|
|
||||||
|
GameLib.Socket.Cast.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = true;
|
||||||
|
|
||||||
|
GameLib.Socket.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Cast.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
|
GameLib.Socket.prototype.updateInstance.call(
|
||||||
|
this,
|
||||||
|
property
|
||||||
|
);
|
||||||
|
|
||||||
|
if (property === 'castType') {
|
||||||
|
console.log('todo: implement socket.receive.castType update');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'source') {
|
||||||
|
if (this.source !== null) {
|
||||||
|
this.sourceProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.source);
|
||||||
|
} else {
|
||||||
|
this.sourceProperties = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.CAST_SOURCE_CHANGED,
|
||||||
|
{
|
||||||
|
component:this
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'sourceProperties') {
|
||||||
|
console.log('todo: implement socket.receive.sourceProperties update');
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.Socket.Cast to a new GameLib.API.Socket.Cast
|
||||||
|
* @returns {GameLib.API.Socket.Cast}
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Cast.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiSocket = new GameLib.API.Socket(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.socketType,
|
||||||
|
this.roomId,
|
||||||
|
this.peerId,
|
||||||
|
GameLib.Utils.IdOrNull(this.server),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.API.Socket.Cast(
|
||||||
|
apiSocket,
|
||||||
|
this.castType,
|
||||||
|
GameLib.Utils.IdOrNull(this.source),
|
||||||
|
this.sourceProperties
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Cast to a GameLib.Socket.Cast
|
||||||
|
* @param sockets GameLib.SocketsRuntime
|
||||||
|
* @param objectCast Object
|
||||||
|
* @returns {GameLib.Socket.Cast}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Cast.FromObject = function(sockets, objectCast) {
|
||||||
|
var apiCast = GameLib.API.Socket.Cast.FromObject(objectCast);
|
||||||
|
return new GameLib.Socket.Cast(
|
||||||
|
sockets,
|
||||||
|
apiCast
|
||||||
|
);
|
||||||
|
};
|
|
@ -0,0 +1,134 @@
|
||||||
|
/**
|
||||||
|
* Creates a Receive object
|
||||||
|
* @param socket GameLib.Socket
|
||||||
|
* @param apiSocketReceive GameLib.API.Socket.Receive
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Receive = function(
|
||||||
|
socket,
|
||||||
|
apiSocketReceive
|
||||||
|
) {
|
||||||
|
|
||||||
|
this.socket = socket;
|
||||||
|
this.socket.isNotWebSocketThrow();
|
||||||
|
|
||||||
|
if (GameLib.Utils.UndefinedOrNull(apiSocketReceive)) {
|
||||||
|
apiSocketReceive = {
|
||||||
|
socketType : GameLib.API.Socket.TYPE_RECEIVE
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (apiSocketReceive instanceof GameLib.Socket.Receive) {
|
||||||
|
return apiSocketReceive;
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.API.Socket.Receive.call(
|
||||||
|
this,
|
||||||
|
apiSocketReceive,
|
||||||
|
apiSocketReceive.receiveType,
|
||||||
|
apiSocketReceive.destination,
|
||||||
|
apiSocketReceive.destinationProperties
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Socket.call(
|
||||||
|
this,
|
||||||
|
socket,
|
||||||
|
apiSocketReceive
|
||||||
|
);
|
||||||
|
|
||||||
|
GameLib.Component.call(
|
||||||
|
this,
|
||||||
|
{
|
||||||
|
destination : GameLib.Component
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
GameLib.Socket.Receive.prototype = Object.create(GameLib.API.Socket.Receive.prototype);
|
||||||
|
GameLib.Socket.Receive.prototype.constructor = GameLib.Socket.Receive;
|
||||||
|
|
||||||
|
GameLib.Socket.Receive.prototype.createInstance = function() {
|
||||||
|
|
||||||
|
this.instance = true;
|
||||||
|
|
||||||
|
GameLib.Socket.prototype.createInstance.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Updates the instance with the current state
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Receive.prototype.updateInstance = function(property) {
|
||||||
|
|
||||||
|
GameLib.Socket.prototype.updateInstance.call(
|
||||||
|
this,
|
||||||
|
property
|
||||||
|
);
|
||||||
|
|
||||||
|
if (property === 'receiveType') {
|
||||||
|
console.log('todo: implement socket.receive.receiveType update');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'destination') {
|
||||||
|
|
||||||
|
if (this.destination !== null) {
|
||||||
|
this.destinationProperties = GameLib.Utils.ObjectPropertiesAsBoolean(this.destination);
|
||||||
|
} else {
|
||||||
|
this.destinationProperties = {};
|
||||||
|
}
|
||||||
|
|
||||||
|
GameLib.Event.Emit(
|
||||||
|
GameLib.Event.RECEIVE_DESTINATION_CHANGED,
|
||||||
|
{
|
||||||
|
component:this
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (property === 'destinationProperties') {
|
||||||
|
console.log('todo: implement socket.receive.destinationProperties update');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a GameLib.Socket.Receive to a new GameLib.API.Socket.Receive
|
||||||
|
* @returns {GameLib.API.Socket.Receive}
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Receive.prototype.toApiObject = function() {
|
||||||
|
|
||||||
|
var apiSocket = new GameLib.API.Socket(
|
||||||
|
this.id,
|
||||||
|
this.name,
|
||||||
|
this.socketType,
|
||||||
|
this.roomId,
|
||||||
|
this.peerId,
|
||||||
|
GameLib.Utils.IdOrNull(this.server),
|
||||||
|
GameLib.Utils.IdOrNull(this.parentEntity)
|
||||||
|
);
|
||||||
|
|
||||||
|
return new GameLib.API.Socket.Receive(
|
||||||
|
apiSocket,
|
||||||
|
this.receiveType,
|
||||||
|
this.destination,
|
||||||
|
this.destinationProperties
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts from an Object Receive to a GameLib.Socket.Receive
|
||||||
|
* @param sockets GameLib.SocketsRuntime
|
||||||
|
* @param objectReceive Object
|
||||||
|
* @returns {GameLib.Socket.Receive}
|
||||||
|
* @constructor
|
||||||
|
*/
|
||||||
|
GameLib.Socket.Receive.FromObject = function(sockets, objectReceive) {
|
||||||
|
|
||||||
|
var apiSocketReceive = GameLib.API.Socket.Receive.FromObject(objectReceive);
|
||||||
|
|
||||||
|
return new GameLib.Socket.Receive(
|
||||||
|
sockets,
|
||||||
|
apiSocketReceive
|
||||||
|
);
|
||||||
|
|
||||||
|
};
|
|
@ -25,6 +25,8 @@ GameLib.SocketsRuntime = function(
|
||||||
}
|
}
|
||||||
this.socketsType = socketsType;
|
this.socketsType = socketsType;
|
||||||
|
|
||||||
|
this.connections = [];
|
||||||
|
|
||||||
this.createInstance();
|
this.createInstance();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -42,6 +44,11 @@ GameLib.SocketsRuntime.prototype.createInstance = function() {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GameLib.SocketsRuntime.prototype.connect = function(serverIp, port, protocol) {
|
||||||
|
var connection = new WebSocket('ws://' + serverIp + ':' + port , protocol);
|
||||||
|
this.connections.push(connection);
|
||||||
|
};
|
||||||
|
|
||||||
GameLib.SocketsRuntime.prototype.updateInstance = function(property) {
|
GameLib.SocketsRuntime.prototype.updateInstance = function(property) {
|
||||||
if (property === 'socketsType') {
|
if (property === 'socketsType') {
|
||||||
this.createInstance();
|
this.createInstance();
|
||||||
|
|
|
@ -775,16 +775,28 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
} else if (property === 'castType') {
|
} else if (property === 'socketType') {
|
||||||
controllers.push(
|
controllers.push(
|
||||||
folder.add(
|
folder.add(
|
||||||
object,
|
object,
|
||||||
property,
|
property,
|
||||||
{
|
{
|
||||||
'room': GameLib.API.Cast.CAST_TYPE_ROOM,
|
'none' : GameLib.API.Socket.TYPE_NONE,
|
||||||
'peer': GameLib.API.Cast.CAST_TYPE_PEER ,
|
'cast' : GameLib.API.Socket.TYPE_CAST,
|
||||||
'all': GameLib.API.Cast.CAST_TYPE_ALL,
|
'receive' : GameLib.API.Socket.TYPE_RECEIVE
|
||||||
'all but peer': GameLib.API.Cast.CAST_TYPE_ALL_BUT_PEER
|
}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else if (property === 'castType') {
|
||||||
|
controllers.push(
|
||||||
|
folder.add(
|
||||||
|
object,
|
||||||
|
property,
|
||||||
|
{
|
||||||
|
'room': GameLib.API.Socket.Cast.CAST_TYPE_ROOM,
|
||||||
|
'peer': GameLib.API.Socket.Cast.CAST_TYPE_PEER ,
|
||||||
|
'all': GameLib.API.Socket.Cast.CAST_TYPE_ALL,
|
||||||
|
'all but peer': GameLib.API.Socket.Cast.CAST_TYPE_ALL_BUT_PEER
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -794,8 +806,8 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
object,
|
object,
|
||||||
property,
|
property,
|
||||||
{
|
{
|
||||||
'room': GameLib.API.Receive.RECEIVE_TYPE_ROOM,
|
'room': GameLib.API.Socket.Receive.RECEIVE_TYPE_ROOM,
|
||||||
'peer': GameLib.API.Cast.RECEIVE_TYPE_PEER
|
'peer': GameLib.API.Socket.Cast.RECEIVE_TYPE_PEER
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -1340,6 +1352,10 @@ GameLib.System.GUI.prototype.buildControl = function(folder, componentTemplate,
|
||||||
property === 'angle'
|
property === 'angle'
|
||||||
) {
|
) {
|
||||||
controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01));
|
controllers.push(folder.add(object, property, -Math.PI * 2, Math.PI * 2, 0.01));
|
||||||
|
} else if (
|
||||||
|
property === 'port'
|
||||||
|
) {
|
||||||
|
controllers.push(folder.add(object, property, 1, 65536, 1));
|
||||||
} else {
|
} else {
|
||||||
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
|
controllers.push(folder.add(object, property, -1000, 1000, 0.1));
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ GameLib.System.Socket = function(
|
||||||
|
|
||||||
this.castComponents = [];
|
this.castComponents = [];
|
||||||
|
|
||||||
|
this.receiveComponents = [];
|
||||||
|
|
||||||
this.instanceCreatedSubscription = null;
|
this.instanceCreatedSubscription = null;
|
||||||
|
|
||||||
this.removeComponentSubscription = null;
|
this.removeComponentSubscription = null;
|
||||||
|
@ -32,7 +34,8 @@ GameLib.System.Socket.prototype.start = function() {
|
||||||
|
|
||||||
GameLib.System.prototype.start.call(this);
|
GameLib.System.prototype.start.call(this);
|
||||||
|
|
||||||
this.castComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.CAST);
|
this.castComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_CAST);
|
||||||
|
this.receiveComponents = GameLib.EntityManager.Instance.queryComponents(GameLib.Component.SOCKET_RECEIVE);
|
||||||
|
|
||||||
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
this.instanceCreatedSubscription = GameLib.Event.Subscribe(
|
||||||
GameLib.Event.INSTANCE_CREATED,
|
GameLib.Event.INSTANCE_CREATED,
|
||||||
|
@ -53,24 +56,30 @@ GameLib.System.Socket.prototype.start = function() {
|
||||||
function(castComponent) {
|
function(castComponent) {
|
||||||
this.connect(castComponent);
|
this.connect(castComponent);
|
||||||
}.bind(this)
|
}.bind(this)
|
||||||
)
|
);
|
||||||
|
|
||||||
|
this.receiveComponents.map(
|
||||||
|
function(receiveComponent) {
|
||||||
|
this.connect(receiveComponent);
|
||||||
|
}.bind(this)
|
||||||
|
);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to the socket server
|
* Connect to the socket server
|
||||||
* @param castComponent
|
* @param socketComponent
|
||||||
*/
|
*/
|
||||||
GameLib.System.Socket.prototype.connect = function(castComponent) {
|
GameLib.System.Socket.prototype.connect = function(socketComponent) {
|
||||||
console.log(castComponent.name + ' is connecting to the server ' + castComponent.serverIp);
|
console.log(socketComponent.name + ' is connecting to the server ' + socketComponent.serverIp);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Disconnect from the socket server
|
* Disconnect from the socket server
|
||||||
* @param castComponent
|
* @param socketComponent
|
||||||
*/
|
*/
|
||||||
GameLib.System.Socket.prototype.disconnect = function(castComponent) {
|
GameLib.System.Socket.prototype.disconnect = function(socketComponent) {
|
||||||
console.log(castComponent.name + ' is disconnecting from server ' + castComponent.serverIp);
|
console.log(socketComponent.name + ' is disconnecting from server ' + socketComponent.serverIp);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,28 +88,49 @@ GameLib.System.Socket.prototype.disconnect = function(castComponent) {
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
GameLib.System.Socket.prototype.instanceCreated = function(data) {
|
GameLib.System.Socket.prototype.instanceCreated = function(data) {
|
||||||
if (data.component instanceof GameLib.Cast) {
|
|
||||||
|
if (data.component instanceof GameLib.Socket.Cast) {
|
||||||
|
|
||||||
this.connect(data.component);
|
this.connect(data.component);
|
||||||
|
|
||||||
GameLib.Utils.PushUnique(this.castComponents, data.component);
|
GameLib.Utils.PushUnique(this.castComponents, data.component);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Socket.Receive) {
|
||||||
|
|
||||||
|
this.connect(data.component);
|
||||||
|
|
||||||
|
GameLib.Utils.PushUnique(this.receiveComponents, data.component);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a cast component from this system
|
* Removes a cast or receive component from this system
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
GameLib.System.Socket.prototype.removeComponent = function(data) {
|
GameLib.System.Socket.prototype.removeComponent = function(data) {
|
||||||
|
|
||||||
if (data.component instanceof GameLib.Cast) {
|
var index;
|
||||||
|
|
||||||
var index = this.castComponents.indexOf(data.component);
|
if (data.component instanceof GameLib.Socket.Cast) {
|
||||||
|
|
||||||
|
index = this.castComponents.indexOf(data.component);
|
||||||
|
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.castComponents.splice(index, 1);
|
this.castComponents.splice(index, 1);
|
||||||
} else {
|
} else {
|
||||||
console.log('Socket System out of Component sync')
|
console.log('Socket System out of Cast Component sync')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.component instanceof GameLib.Socket.Receive) {
|
||||||
|
|
||||||
|
index = this.receiveComponents.indexOf(data.component);
|
||||||
|
|
||||||
|
if (index !== -1) {
|
||||||
|
this.receiveComponents.splice(index, 1);
|
||||||
|
} else {
|
||||||
|
console.log('Socket System out of Receive Component sync')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +168,23 @@ GameLib.System.Socket.prototype.stop = function() {
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
if (this.castComponents.length !== '0') {
|
if (this.castComponents.length !== 0) {
|
||||||
console.warn(this.castComponents.length + ' connections still open after socket system stopped');
|
console.warn(this.castComponents.length + ' cast connections still open after socket system stopped');
|
||||||
|
}
|
||||||
|
|
||||||
|
this.receiveComponents = this.receiveComponents.reduce(
|
||||||
|
function(result, receiveComponent) {
|
||||||
|
|
||||||
|
if (!this.disconnect(receiveComponent)) {
|
||||||
|
result.push(receiveComponent);
|
||||||
|
}
|
||||||
|
|
||||||
|
}.bind(this),
|
||||||
|
[]
|
||||||
|
);
|
||||||
|
|
||||||
|
if (this.receiveComponents.length !== 0) {
|
||||||
|
console.warn(this.receiveComponents.length + ' receive connections still open after socket system stopped');
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue