Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer disconnected in room pr #36

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"scripts": {
"build": "browserify src/index.js -s SimpleSignalClient | minify > ../dist/simple-signal-client.min.js",
"build-dev": "browserify src/index.js -s SimpleSignalClient -o ../dist/simple-signal-client.js",
"build-lobbys": "browserify src/index.js -s SimpleSignalClient -o ../examples/lobbys/js/simple-signal-client.js",
"test": "node support/server.js > /dev/null | npm run test-node",
"test-browser": "airtap -- test/*.js",
"test-browser-local": "airtap --local -- test/*.js",
Expand Down
4 changes: 4 additions & 0 deletions client/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ SimpleSignalClient.prototype._accept = function (request, metadata = {}, peerOpt
})
})

peer.on('error', (err) => {
console.log(err)
})

peer.once('close', () => {
this._closePeer(request.sessionId)
})
Expand Down
15 changes: 10 additions & 5 deletions examples/lobbys/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<div id="remoteVideos"></div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
<script src="https://github.com/t-mullen/simple-signal/releases/latest/download/simple-signal-client.min.js"></script>
<script src="js/simple-signal-client.js"></script>
<script>
const roomContainer = document.getElementById('list')
const localVideoContainer = document.getElementById('localVideo')
Expand Down Expand Up @@ -64,9 +64,14 @@
// connects to a peer and handles media streams
async function connectToPeer(peerID, localStream) {
console.log('connecting to peer', peerID)
const { peer } = await signalClient.connect(peerID, currentRoom) // connect to the peer
console.log('connected to peer', peerID)
onPeer(peer, localStream)
// connect to the peer
signalClient.connect(peerID, currentRoom).then(({ peer }) => {
console.log('connected to peer', peerID)
onPeer(peer, localStream)
}).catch(err => {
console.log("connecteing error");
console.log(err);
});
}

function joinRoom (roomID, localStream) {
Expand Down Expand Up @@ -120,4 +125,4 @@
})
}, () => alert('No webcam access!'))
</script>
</html>
</html>
1 change: 1 addition & 0 deletions examples/lobbys/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
simple-signal-client.js
39 changes: 39 additions & 0 deletions examples/lobbys/js/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

# Build simple-signal-client.js
$ cd $PROJECT/client
$ npm run build-lobbys


Edit examples/lobbys/js/simple-signal-client.js.
To change context from this code
<pre>
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
err.context = er;
throw err;
}
</pre>
to the following code.
<pre>
if (er instanceof Error) {
throw er; // Unhandled 'error' event
} else {
// At least give some kind of context to the user
var err = new Error('Uncaught, unspecified "error" event. (' + er + ')');
err.context = er;
console.log("Unknown Error and er = ")
console.log(er)
if (er.code === "ERR_DATA_CHANNEL") {
console.log("er.code = ")
console.log(er.code)
} else {
throw err;
}
}
</pre>

These code is currently ignore ERR_DATA_CHANNEL and it can make sure dynamically room and peer be stable.
We need this code until we know how to catch all ERR_DATA_CHANNEL error.
9 changes: 9 additions & 0 deletions examples/lobbys/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ signal.on('discover', (request) => {
}
})

signal.on('disconnect', (request) => {
const roomID = request.roomID
const peerID = request.conn.id
if (roomID) {
console.log(peerID, 'left room', roomID)
rooms[roomID].delete(peerID)
}
})

console.log('Running lobbys demo! Open http://localhost:8000')
io.listen(3000)