-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect-liveservice.js
More file actions
42 lines (31 loc) · 936 Bytes
/
connect-liveservice.js
File metadata and controls
42 lines (31 loc) · 936 Bytes
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
/* globals io:true */
import $ from 'jquery';
var currentSocket;
$(window).on('beforeunload', function(){
if(currentSocket && currentSocket.close){
currentSocket.close();
}
});
var url = '/?embed_id={embedId}';
var publicUrl = '/?embed_id={embedId}&tenant_name={tenantName}';
export default function(hubId, tenantName){
if(currentSocket && currentSocket.close){
currentSocket.close();
}
if(typeof io !== 'undefined'){
currentSocket = io(can.sub((tenantName ? publicUrl : url), {
embedId : hubId,
tenantName : tenantName
}), { multiplex: false });
currentSocket.on('connect', function() {
console.log('CONNECTED!', currentSocket.id);
});
currentSocket.on('connect_error', function( err ) {
console.log('CONNECTION ERROR!', err.description, err.message, err.type);
});
currentSocket.on('disconnect', function( msg ) {
console.log('DISCONNECTION!', msg);
});
return currentSocket;
}
}