-
Notifications
You must be signed in to change notification settings - Fork 285
/
websocket.html
47 lines (39 loc) · 1.02 KB
/
websocket.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
<!doctype html>
<html>
<head>
<title>PubNub JavaScript CommonJS</title>
<link
rel=stylesheet
href=http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css
>
</head>
<body><div class=container>
</div>
<script src=../javascript/pubnub-3.1.js></script>
<script src=websocket.js></script>
<script>(function() {
"use strict"
/* 'wss://ORIGIN/PUBLISH_KEY/SUBSCRIBE_KEY/CHANNEL' */
var socket = new WebSocket('wss://pubsub.pubnub.com/demo/demo/my_channel')
socket.onmessage = function(evt) {
console.log('socket receive');
console.log(evt.data);
}
socket.onclose = function() {
console.log('socket closed');
}
socket.onerror = function() {
console.log('socket error');
}
socket.onopen = function(evt) {
console.log('socket open');
socket.send('hello world!');
}
socket.onsend = function(evt) {
console.log('socket send');
console.log(evt);
}
console.log(socket)
})();</script>
</body>
</html>