r3-legacy/src/game-lib-socket-receive.js

124 lines
2.9 KiB
JavaScript

/**
* 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
};
}
GameLib.API.Socket.Receive.call(
this,
apiSocketReceive,
apiSocketReceive.receiveType,
apiSocketReceive.destination,
apiSocketReceive.destinationProperties
);
GameLib.Socket.call(
this,
socket,
apiSocketReceive
);
};
GameLib.Socket.Receive.prototype = Object.create(GameLib.Socket.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
);
};