r3-legacy/src/r3-socket-cast.js

91 lines
2.0 KiB
JavaScript

/**
* R3.Socket.Cast
* @param socket R3.Socket
* @param apiSocketCast
* @constructor
*/
R3.Socket.Cast = function(
socket,
apiSocketCast
) {
this.socket = socket;
this.socket.isNotWebSocketThrow();
if (R3.Utils.UndefinedOrNull(apiSocketCast)) {
apiSocketCast = {
socketType : R3.API.Socket.SOCKET_TYPE_CAST
};
}
R3.API.Socket.Cast.call(
this,
apiSocketCast,
apiSocketCast.castType,
apiSocketCast.source,
apiSocketCast.sourceProperties
);
R3.Socket.call(
this,
socket,
apiSocketCast
);
};
R3.Socket.Cast.prototype = Object.create(R3.Socket.prototype);
R3.Socket.Cast.prototype.constructor = R3.Socket.Cast;
R3.Socket.Cast.prototype.createInstance = function() {
R3.Socket.prototype.createInstance.call(this);
};
/**
* Updates the instance with the current state
*/
R3.Socket.Cast.prototype.updateInstance = function(property) {
if (property === 'castType') {
console.log('todo: implement castType update');
}
if (property === 'source') {
if (this.source !== null) {
this.sourceProperties = R3.Utils.ObjectPropertiesAsBoolean(this.source);
} else {
this.sourceProperties = {};
}
R3.Event.Emit(
R3.Event.CAST_SOURCE_CHANGED,
{
component:this
}
)
}
if (property === 'sourceProperties') {
console.log('todo: implement sourceProperties update');
}
R3.Socket.prototype.updateInstance.call(this, property);
};
/**
* Converts a R3.Socket.Cast to a new R3.API.Socket.Cast
* @returns {R3.API.Socket.Cast}
*/
R3.Socket.Cast.prototype.toApiObject = function() {
var apiSocket = new R3.Socket.prototype.toApiObject.call(this);
var apiSocketCast = new R3.API.Socket.Cast(
apiSocket,
this.castType,
R3.Utils.IdOrNull(this.source),
this.sourceProperties
);
return apiSocketCast;
};