Spaces:
Running
Running
Create index.js
Browse files
index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { PeerServer } = require('peer');
|
| 2 |
+
|
| 3 |
+
const PORT = process.env.PORT || 7860;
|
| 4 |
+
|
| 5 |
+
const peerServer = PeerServer({
|
| 6 |
+
port: PORT,
|
| 7 |
+
path: '/myapp',
|
| 8 |
+
proxied: true,
|
| 9 |
+
allow_discovery: true,
|
| 10 |
+
});
|
| 11 |
+
|
| 12 |
+
console.log(`🚀 Peer Server running on port ${PORT}`);
|
| 13 |
+
|
| 14 |
+
peerServer.on('connection', (client) => {
|
| 15 |
+
console.log(`Client connected: ${client.getId()}`);
|
| 16 |
+
});
|
| 17 |
+
|
| 18 |
+
peerServer.on('disconnect', (client) => {
|
| 19 |
+
console.log(`Client disconnected: ${client.getId()}`);
|
| 20 |
+
});
|