Can exchange ready messages

This commit is contained in:
2019-01-25 10:47:42 +01:00
parent 89041d7009
commit 7318468d49
4 changed files with 136 additions and 1 deletions

View File

@ -62,6 +62,13 @@ class SignalExchangerClient {
*/
//onSignal = null;
/**
* Function called when we get a ready message notice
*
* @type {Function}
*/
//onReadyMessage = null;
/**
* Construct a client instance
*
@ -125,6 +132,20 @@ class SignalExchangerClient {
}
/**
* Send ready message to a peer
*
* @param {String} peerID The ID of the target peer for the message
*/
sendReadyMessage(peerID){
this.sendData({
ready_msg: true,
target_id: peerID
});
}
/**
* Send a signal to the server
*
@ -192,6 +213,26 @@ class SignalExchangerClient {
}
}
//Check if message is a callback for a ready notice
else if(message.ready_message_sent){
if(message.number_of_targets < 1){
//Try to send message again
setTimeout(() => {
this.sendReadyMessage(message.target_id);
}, 1000);
}
}
// Check if message is a ready notice
else if(message.ready_msg){
if(this.onReadyMessage != null)
this.onReadyMessage(message.source_id);
}
// Check if the message is a signal
else if(message.signal){
if(this.onSignal != null)