1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | var debug = require('debug')('pub:sockets');
|
13 |
|
14 | if (window.io) {
|
15 |
|
16 | debug('socket:connect');
|
17 | var socket = io();
|
18 |
|
19 | socket.on('reload', function() {
|
20 |
|
21 | if (window.generator && window.generator.emit) {
|
22 | return window.generator.emit('notify', 'save');
|
23 | }
|
24 | debug('socket:reload');
|
25 | location.reload();
|
26 | });
|
27 |
|
28 | window.addEventListener('beforeunload', function() {
|
29 | debug('socket:disconnect');
|
30 | socket.disconnect();
|
31 | });
|
32 |
|
33 | } else console.log('no socket.io');
|