94 lines
2.0 KiB
JavaScript
94 lines
2.0 KiB
JavaScript
|
/**
|
||
|
* Raw Socket API object - should always correspond with the Socket Schema
|
||
|
* @param id
|
||
|
* @param name
|
||
|
* @param socketType
|
||
|
* @param roomId
|
||
|
* @param peerId
|
||
|
* @param server R3.Server
|
||
|
* @param parentEntity
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.API.Socket = function(
|
||
|
id,
|
||
|
name,
|
||
|
socketType,
|
||
|
roomId,
|
||
|
peerId,
|
||
|
server,
|
||
|
parentEntity
|
||
|
) {
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(id)) {
|
||
|
id = R3.Utils.RandomId();
|
||
|
}
|
||
|
this.id = id;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(name)) {
|
||
|
name = 'Socket (' + this.id + ')';
|
||
|
}
|
||
|
this.name = name;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(socketType)) {
|
||
|
socketType = R3.API.Socket.TYPE_NONE;
|
||
|
}
|
||
|
this.socketType = socketType;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(roomId)) {
|
||
|
roomId = 'room_' + R3.Utils.RandomId();
|
||
|
}
|
||
|
this.roomId = roomId;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(peerId)) {
|
||
|
peerId = null;
|
||
|
}
|
||
|
this.peerId = peerId;
|
||
|
|
||
|
if (R3.Utils.UndefinedOrNull(server)) {
|
||
|
server = null;
|
||
|
}
|
||
|
this.server = server;
|
||
|
|
||
|
var componentType = R3.Component.SOCKET;
|
||
|
|
||
|
if (this.socketType === R3.API.Socket.TYPE_CAST) {
|
||
|
componentType = R3.Component.SOCKET_CAST;
|
||
|
}
|
||
|
|
||
|
if (this.socketType === R3.API.Socket.TYPE_RECEIVE) {
|
||
|
componentType = R3.Component.SOCKET_RECEIVE;
|
||
|
}
|
||
|
|
||
|
R3.API.Component.call(
|
||
|
this,
|
||
|
componentType,
|
||
|
parentEntity
|
||
|
);
|
||
|
};
|
||
|
|
||
|
R3.API.Socket.prototype = Object.create(R3.API.Component.prototype);
|
||
|
R3.API.Socket.prototype.constructor = R3.API.Socket;
|
||
|
|
||
|
R3.API.Socket.TYPE_NONE = 0x1;
|
||
|
R3.API.Socket.TYPE_CAST = 0x2;
|
||
|
R3.API.Socket.TYPE_RECEIVE = 0x3;
|
||
|
|
||
|
/**
|
||
|
* Creates an API Socket from an Object Socket
|
||
|
* @param objectSocket
|
||
|
* @constructor
|
||
|
*/
|
||
|
R3.API.Socket.FromObject = function(objectSocket) {
|
||
|
|
||
|
return new R3.API.Socket(
|
||
|
objectSocket.id,
|
||
|
objectSocket.name,
|
||
|
objectSocket.socketType,
|
||
|
objectSocket.roomId,
|
||
|
objectSocket.peerId,
|
||
|
objectSocket.server,
|
||
|
objectSocket.parentEntity
|
||
|
);
|
||
|
|
||
|
};
|