Skip to content

Commit

Permalink
Create client1.html
Browse files Browse the repository at this point in the history
  • Loading branch information
ppacory authored Aug 1, 2019
1 parent 929c862 commit 1382da1
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions nginx/client1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!DOCTYPE html> <html>
<head>
<meta charset="utf-8" />
</head>
<body>
<script src="https://unpkg.com/[email protected]/dist/peerjs.min.js"></script>
<script type="text/javascript">

peer = new Peer('client1', { host: '172.20.25.150', port: 9000, path:'/myapp', debug:false});

peer.on('open', function (id) {
// Workaround for peer.reconnect deleting previous id
if (peer.id === null) {
console.log('Received null id from peer open');
peer.id = lastPeerId;
} else {
lastPeerId = peer.id;
}
console.log('ID: ' + peer.id);
console.log('wait connection ...');
});



peer.on('connection', function (c) {
// Allow only a single connection
//if (conn) {
// c.on('open', function() {
// c.send("Already connected to another client");
// setTimeout(function() { c.close(); }, 500);
// });
// return;
//}
conn = c;
console.log("Connected to: " + conn.peer);
conn.on('data', function (data) {
console.log(data);
});

conn.on('close', function () {
console.log("Connection reset Awaiting connection...");
conn = null;
});
});


peer.on('disconnected', function () {
console.log('Connection lost. Please reconnect');
// Workaround for peer.reconnect deleting previous id
peer.id = lastPeerId;
peer._lastServerId = lastPeerId;
peer.reconnect();
});

peer.on('close', function() {
conn = null;
console.log('Connection destroyed');
});

peer.on('error', function (err) {
console.log(err);
});

</script>
</body>
</html>

0 comments on commit 1382da1

Please sign in to comment.