-
Notifications
You must be signed in to change notification settings - Fork 10.1k
/
Copy pathindex.html
34 lines (32 loc) · 1.05 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Passport example</title>
</head>
<body>
<p>Authenticated!</p>
<p>Socket ID: <span id="socketId"></span></p>
<p>Username: <span id="username"></span></p>
<form action="/logout" method="post">
<div>
<input type="submit" value="Log out" />
</div>
</form>
<script src="/socket.io/socket.io.js"></script>
<script>
const socket = io("ws://localhost:3000", {
// set this option to send cookies for session-management to work
withCredentials: true
});
const socketIdSpan = document.getElementById("socketId");
const usernameSpan = document.getElementById("username");
socket.on('connect', () => {
socketIdSpan.innerText = socket.id;
socket.emit('whoami', (username) => {
usernameSpan.innerText = username;
});
});
</script>
</body>
</html>