/** * 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 ); };