forked from peers/peerjs-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |