-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
73 lines (67 loc) · 1.86 KB
/
server.js
File metadata and controls
73 lines (67 loc) · 1.86 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const express = require("express");
const app = express();
const PORT = process.env.PORT || 3030;
const server = app.listen(PORT, () => console.log(`Listening on ${PORT}\n`));
const messages = [
{
channel: "1",
account: "0xcA8Fa8f0b631EcdB18Cda619C4Fc9d197c8aFfCa",
text: "Welcome to Dappcord!",
},
{
channel: "2",
account: "0xcA8Fa8f0b631EcdB18Cda619C4Fc9d197c8aFfCa",
text: "Welcome to Dappcord everyone! My name is John and I've been a blockchain developer for 2+ years.",
},
{
channel: "1",
account: "0x1b3cB81E51011b549d78bf720b0d924ac763A7C2",
text: "Hello everyone!",
},
{
channel: "2",
account: "0x1b3cB81E51011b549d78bf720b0d924ac763A7C2",
text: "Hey there! My name is Ann and I'm an aspiring blockchain developer!",
},
{
channel: "1",
account: "0x701C484bfb40ac628aFA487b6082f084B14AF0BD",
text: "Hey everyone!",
},
{
channel: "1",
account: "0x189B9cBd4AfF470aF2C0102f365FC1823d857965",
text: "Hey there, great to be here!",
},
{
channel: "1",
account: "0x176F3DAb24a159341c0509bB36B833E7fdd0a132",
text: "Hope everyone is having a good day ;)",
},
{
channel: "1",
account: "0x828103B231B39ffFCe028562412B3c04A4640e64",
text: "Hello!",
},
{
channel: "1",
account: "0x176F3DAb24a159341c0509bB36B833E7fdd0a132",
text: "Does anyone have any tips on becoming a blockchain developer?",
},
];
const { Server } = require("socket.io");
const io = new Server(server, {
cors: {
origin: "http://localhost:3000",
},
});
io.on("connection", (socket) => {
console.log("a user connected");
socket.on("get messages", () => {
io.emit("get messages", messages);
});
socket.on("new message", (msg) => {
messages.push(msg);
io.emit("new message", messages);
});
});