-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.html
89 lines (78 loc) · 2.73 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
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
<script src="/bin/client.js"></script>
<script>
var opts = {
path: '/',
transports: ['websocket', 'polling']
}
// var socket = new eio.Socket('ws://localhost:8081/?access_token=test', { path: '/' });
var socket = new SocketClient({
host: 'localhost:8081',
// host: 'wss://ws.dubtrack.fm',
// secret: 'super-secure-secret'
// host: 'dubtrack-websockets-staging.us-east-1.elasticbeanstalk.com',
secret: 'c91c92f84d2e2786595deb907f4e010efcd0',
// token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjbGllbnRJZCI6IjU2OWRiYTI5ZTQxMmVkMmQwMGVjNzJmMiIsInNvY2tldElkIjoicW5DaFlpM3RCTXhRXy1xMUFIYkoiLCJzZXJ2ZXJJZCI6IjU5YWU3MDE1YTNiZGIyYTkxYmExYTU1ZmMxODM4MDdjIiwiaXNHdWVzdCI6dHJ1ZSwicHJvamVjdCI6eyJpZCI6MiwidXNlcl9pZCI6MiwibmFtZSI6ImR1YnRyYWNrLXByb2QiLCJzZWNyZXQiOiIzNmFlN2E3ZDY5MzBkMTQ2ZjVhNWRiZTJjN2VmYzE1MzgzNTA5Y2QxYzljZmM5YjgifSwiaWF0IjoxNDg1MzQxODQ4fQ.4ChU8NtnCx9lwC9UKx3hGjNkM6XLiTfLr5QU_2qM4',
clientId: 'test'
});
var interval
function newClient () {
var socket2 = new SocketClient({
// host: 'dubtrack-websockets-staging.us-east-1.elasticbeanstalk.com',
host: 'localhost:8081',
authCallback: function (data, cb) {
socket.auth.createTokenRequest({ clientId: 'test' }, (err, msg) => {
cb(err, msg)
})
}
});
socket2.connection.on('connected', () => {
console.log('client 2 connected')
const testChannel = socket2.channels.get('test')
testChannel.subscribe(console.log.bind(console, 'client2'))
testChannel.publish('asdfasdfasdfas')
})
}
function reattach(channel) {
channel.attach();
/* Example when using presence on the channel */
channel.presence.enter();
}
socket.connection.on('connected', () => {
newClient()
console.log('channels', socket.channels.all)
for (let channelName in socket.channels.all) {
let channel = socket.channels.get(channelName);
console.log(channel)
reattach(channel);
}
if (interval) {
clearInterval(interval)
interval = null
}
window.channel = socket.channels.get('room:5845fb26b0b5bf0c00fb03cb')
window.channel2 = socket.channels.get('test2')
// channel.attach(function () {
// console.log('I\'m alive !!!!')
// })
channel.subscribe(console.log)
channel.presence.get({ clientId: socket.connection.clientId }, (err, list) => {
console.log('list', list)
})
channel2.subscribe((msg) => {
console.log('test2', msg)
})
channel.presence.enter((err) => {
console.log('error:', err)
})
channel.presence.on('enter', console.log)
channel.presence.on('leave', (msg) => {
console.log('leave', msg)
})
})
socket.connection.on('disconnected', () => {
// interval = setInterval(() => {
// socket.connection.connect()
// }, 1000)
})
socket.connection.on('failed', () => console.log('Failed'))
</script>