mirror of
https://gitlab.com/comunic/nodejs-webrtcsignalexchangerserver
synced 2024-11-21 21:09:27 +00:00
Connection established between the two peers !
This commit is contained in:
parent
bc723c5f3c
commit
62e247488a
16
README.MD
16
README.MD
@ -3,10 +3,22 @@
|
||||
A lightweight node application that allows to exchange signals connection through websockets.
|
||||
|
||||
|
||||
## Requirements
|
||||
# Requirements
|
||||
```sh
|
||||
sudo apt install nodejs node-express node-wc
|
||||
```
|
||||
|
||||
## Author
|
||||
# Using for signaling
|
||||
## Installation
|
||||
* Install docker
|
||||
* Install coturn: `sudo apt install coturn`
|
||||
* Add a client to coturn: `sudo turnadmin -a -u anonymous -r anonymous.com -p anonymous`
|
||||
|
||||
|
||||
## Running TURN server
|
||||
```sh
|
||||
sudo turnserver -o -a -f -r anonymous.com # Use -L option to specify an IP address
|
||||
```
|
||||
|
||||
# Author
|
||||
Pierre HUBERT 2019
|
@ -55,6 +55,13 @@ class SignalExchangerClient {
|
||||
*/
|
||||
//onClosed = null;
|
||||
|
||||
/**
|
||||
* Function called when we get a new signal information
|
||||
*
|
||||
* @type {Function}
|
||||
*/
|
||||
//onSignal = null;
|
||||
|
||||
/**
|
||||
* Construct a client instance
|
||||
*
|
||||
@ -185,6 +192,12 @@ class SignalExchangerClient {
|
||||
}
|
||||
}
|
||||
|
||||
// Check if the message is a signal
|
||||
else if(message.signal){
|
||||
if(this.onSignal != null)
|
||||
this.onSignal(message.signal, message.source_id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
11
client/simplepeer.min.js
vendored
Normal file
11
client/simplepeer.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -10,6 +10,7 @@
|
||||
<h1>Signal Exchanger test client</h1>
|
||||
|
||||
|
||||
<script src="simplepeer.min.js"></script>
|
||||
<script src="SignalExchangerClient.js"></script>
|
||||
<script src="test-client.js"></script>
|
||||
</body>
|
||||
|
@ -17,13 +17,12 @@ let client = new SignalExchangerClient(
|
||||
Config.clientID
|
||||
);
|
||||
|
||||
var p;
|
||||
|
||||
client.onConnected = function(){
|
||||
console.log("Connected to signal exchanger server.");
|
||||
|
||||
client.sendSignal(
|
||||
Config.otherPeerID,
|
||||
"A signal content from " + Config.clientID + " to " + Config.otherPeerID,
|
||||
);
|
||||
InitializePeer();
|
||||
}
|
||||
|
||||
client.onError = function() {
|
||||
@ -33,3 +32,54 @@ client.onError = function() {
|
||||
client.onClosed = function() {
|
||||
console.log("Connection to server closed.");
|
||||
}
|
||||
|
||||
client.onSignal = function(signal, peerID){
|
||||
|
||||
if(peerID !== Config.otherPeerID)
|
||||
return alert("A signal from an unknow peer ID has just been received!");
|
||||
|
||||
p.signal(JSON.parse(signal));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize peer connection
|
||||
*
|
||||
* Warning : It is better to wait for the socket connection to be ready before
|
||||
* launching this function if this peer is the initiator of the connection
|
||||
*/
|
||||
function InitializePeer() {
|
||||
|
||||
p = new SimplePeer({
|
||||
initiator: location.hash === '#1',
|
||||
trickle: false,
|
||||
config: {
|
||||
'iceServers': [
|
||||
{ urls: 'stun:127.0.0.1:3478' },
|
||||
{"url":"turn:127.0.0.1:3478",
|
||||
"credential":"anonymous",
|
||||
"username": "anonymous"}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
p.on('error', function (err) { console.log('SimplePeer error', err) });
|
||||
|
||||
//Automatically send new signals to the other peer
|
||||
p.on('signal', function (data) {
|
||||
console.log('SIGNAL', JSON.stringify(data))
|
||||
client.sendSignal(Config.otherPeerID, JSON.stringify(data));
|
||||
});
|
||||
|
||||
p.on('connect', function () {
|
||||
console.log('CONNECT');
|
||||
msg = 'whatever' + Math.random();
|
||||
console.log("Sending: " + msg);
|
||||
p.send(msg);
|
||||
})
|
||||
|
||||
p.on('data', function (data) {
|
||||
console.log('data: ' + data)
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue
Block a user