Hi, for my specific use case I require communication between 2 peers solely for signaling, yes this could be achieved with a data channel but the effort it takes to create a data channel and maintaining it is unnecessary for a simple message for custom app-signaling, not to mention is unnecessarily stresses the user.
So what I decided to implement 'orders', the idea is that a peer order another peer, triggering an event without establishing a data channel, the server is only required to send a message from one to the other, through it's active websockets
Implementation.
server:
added 'ORDER' message type to the switch
*still trying to find out why sockets after 2 min of inactivity, might fiddle with a heartbeat
client
//added to message type switch
case 'ORDER': //order given by the server
this.emit('order', message.subType, message.data);//just condensing the custom events inside the order handler, for clarity
break;
//the hard part
Peer.prototype.order = function(dst,subType, data) {//dst is the peer id of the ordered peer, subType is order event to be triggered
if (this.disconnected) {
util.warn('You cannot order a Peer because you called ' +
'.disconnect() on this Peer and ended your connection with the ' +
'server. You can create a new Peer to reconnect.');
this.emitError('disconnected', 'Cannot connect to server after disconnecting from it.');
return;
}
if (!dst) {
util.error('To order, please provide an online recipients id');
return;
}
var order;
order.dst= dst;
order.data = data;
order.type: 'ORDER';
order.subType: subType;
this.socket.send(order){}, function(err) {
util.log('Failed to send order, ', err);
return;
};
};
Gonna start testing in a bit, just wanted to know if I'm making any glaring mistake and/or if there is interest in this feature.
Also any ideas why my websockets keeps closing every 2 min of inactivity?
lastly where could I place an error for dst not connected?
(disclaimer: university student in an internship working in a webrtc based webapp, learnt javascript a fortnight ago...)