mirror of
https://gitlab.com/comunic/nodejs-webrtcsignalexchangerserver
synced 2025-06-19 17:35:19 +00:00
Can exchange ready messages
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user