clone3 commited on
Commit
388cfc7
·
verified ·
1 Parent(s): b516fa4

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +6 -1
server.js CHANGED
@@ -1,12 +1,16 @@
1
  const WebSocket = require('ws');
 
 
2
  const PORT = 7860;
3
 
 
 
4
  const wss = new WebSocket.Server({ port: PORT });
5
 
6
  // This counter represents number of connected clients
7
  function broadcastClientCount() {
8
  const count = wss.clients.size;
9
- const message = JSON.stringify({ clients: count });
10
 
11
  wss.clients.forEach((client) => {
12
  if (client.readyState === WebSocket.OPEN) {
@@ -16,6 +20,7 @@ function broadcastClientCount() {
16
  }
17
 
18
  wss.on('connection', (ws) => {
 
19
  console.log('Client connected');
20
  broadcastClientCount(); // On connect
21
 
 
1
  const WebSocket = require('ws');
2
+ const express = require('express');
3
+ const app = express();
4
  const PORT = 7860;
5
 
6
+ let visits = 0;
7
+
8
  const wss = new WebSocket.Server({ port: PORT });
9
 
10
  // This counter represents number of connected clients
11
  function broadcastClientCount() {
12
  const count = wss.clients.size;
13
+ const message = JSON.stringify({ online: count, visitor: visits});
14
 
15
  wss.clients.forEach((client) => {
16
  if (client.readyState === WebSocket.OPEN) {
 
20
  }
21
 
22
  wss.on('connection', (ws) => {
23
+ visits++;
24
  console.log('Client connected');
25
  broadcastClientCount(); // On connect
26