/** * Sockets * @param id * @param name * @param socketsType * @constructor */ GameLib.SocketsRuntime = function( id, name, socketsType ) { if (GameLib.Utils.UndefinedOrNull(id)) { id = GameLib.Utils.RandomId(); } this.id = id; if (GameLib.Utils.UndefinedOrNull(name)) { name = 'Sockets (' + id + ')'; } this.name = name; if (GameLib.Utils.UndefinedOrNull(socketsType)) { socketsType = GameLib.SocketsRuntime.TYPE_WEB_SOCKET; } this.socketsType = socketsType; this.createInstance(); }; /** * GameLib.SocketsRuntime Types * @type {number} */ GameLib.SocketsRuntime.TYPE_WEB_SOCKET = 0x1; GameLib.SocketsRuntime.prototype.createInstance = function() { if (this.socketsType === GameLib.SocketsRuntime.TYPE_WEB_SOCKET) { this.instance = WebSocket; } else { this.instance = null; } }; GameLib.SocketsRuntime.prototype.updateInstance = function(property) { if (property === 'socketsType') { this.createInstance(); } }; /** * Logs a warning and throws an error if not cannon */ GameLib.SocketsRuntime.prototype.isNotWebSocketThrow = function() { if (this.instance !== WebSocket) { console.error('Only WebSocket supported'); throw new Error('Only WebSocket supported'); } };