This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf-test.html
108 lines (93 loc) · 4.67 KB
/
sf-test.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
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<html>
<head>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/bootswatch/4.4.1/lux/bootstrap.min.css" rel="stylesheet"
integrity="sha384-oOs/gFavzADqv3i5nCM+9CzXe3e5vXLXZ5LZ7PplpsWpTCufB7kqkTlC9FtZ5nJo" crossorigin="anonymous">
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"
integrity="sha256-4iQZ6BVL4qNKlQ27TExEhBN1HFPvAvAMbFavKKosSWQ=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js"
integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>
<script type="text/javascript" src="http://localhost:63342/websocket-client/build/socket.js"></script>
<script type="text/javascript" src="./build/socket.js"></script>
</head>
<body>
<header>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="#">Spiral Websocket Test</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarColor02"
aria-controls="navbarColor02" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarColor02">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="https://git.spiralscout.com/wolfy-j/we-demo">Demo Repository</a>
</li>
</ul>
</div>
</nav>
</header>
<div class="container">
<div>
<table class="table table-hover table-sm">
<thead>
<tr>
<th scope="col">Time</th>
<th scope="col">Event</th>
</tr>
</thead>
<tbody id="messages">
</tbody>
</table>
</div>
</div>
<script type="text/javascript">
window.addEventListener("load", function (evt) {
const messages = document.getElementById("messages");
const Socket = SFSocket.SFSocket;
const eventNames = SFSocket.eventNames;
const addMessage = (color, message) => {
const div = document.createElement('tr');
div.classList.add('table-' + color);
console.log(color, message);
div.innerHTML = `<td scope="row">${moment().format('HH:mm:ss SSS')}</td><td><pre class="m-0">${message+''}</pre></td>`;
messages.appendChild(div);
};
addMessage('', 'Intialization');
const ws = new Socket({
host: 'localhost',
port: 8080,
path: 'ws',
});
ws.subscribe(eventNames.ERROR, (e) => {
addMessage('danger', JSON.stringify(e));
});
ws.subscribe(eventNames.CHANNEL_JOINED, (channels) => {
addMessage('success', `Joined channels [${channels.join(',')}]`);
});
ws.subscribe(eventNames.CHANNEL_JOIN_FAILED, (channels) => {
addMessage('danger', `Failed to join channels [${channels.join(',')}]`);
});
ws.subscribe(eventNames.CHANNEL_LEFT, (channels) => {
addMessage('success', `Left channels [${channels.join(',')}]`);
});
Socket.ready();
addMessage('', 'Joining channels [channel1 and topic]');
// create a channel and it is automatically connected to server
const channel1 = ws.joinChannel('channel_1');
const channel2 = ws.joinChannel('topic');
// subscribe the channel to server
channel1.subscribe(eventNames.MESSAGE, (event) => addMessage('info', `<span class="badge badge-dark">${event.context.channel + ''}</span> ${event.data+''}`));
channel2.subscribe(eventNames.MESSAGE, (event) => addMessage('info', `<span class="badge badge-dark">${event.context.channel + ''}</span> ${event.data+''}`));
});
</script>
</body>
</html>