-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket.js
37 lines (31 loc) · 1.12 KB
/
socket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// const websocket = require('ws');
// const http = require('http');
// const { client } = require('./database/handleDatabase');
// //const { client } = require('@/database/handleDatabase');
// const server = http.createServer();
// const wss = new websocket.Server({server});
// wss.on('connection',(ws)=>{
// console.log("Connected",);
// });
// try{
// const db = client.db('User_Details');
// const collection = db.collection('Registration');
// const changestream = collection.watch();
// changestream.on('change',(newData)=>{
// console.log("type",newData.operationType);
// if(newData.operationType === 'insert' || newData.operationType === 'update'){
// //console.log("newData",newData);
// wss.clients.forEach((client)=>{
// if(client.readyState === websocket.OPEN){
// client.send(JSON.stringify(newData));
// }
// });
// };
// });
// }catch(error){
// console.log(error);
// };
// const PORT = 8080;
// server.listen(PORT,()=>{
// console.log(`websocket is running on port:${PORT}`);
// })