|
@@ -9,68 +9,56 @@
|
|
</template>
|
|
</template>
|
|
<script>
|
|
<script>
|
|
'use strict';
|
|
'use strict';
|
|
- window.isActive = true;
|
|
|
|
-
|
|
|
|
- window.onfocus = function() {
|
|
|
|
- window.isActive = true;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- window.onblur = function() {
|
|
|
|
- window.isActive = false;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
Polymer({
|
|
Polymer({
|
|
is: 'web-socket',
|
|
is: 'web-socket',
|
|
attached: function() {
|
|
attached: function() {
|
|
this.init();
|
|
this.init();
|
|
},
|
|
},
|
|
init: function() {
|
|
init: function() {
|
|
- if (window.isActive) {
|
|
|
|
- clearInterval(this.reconnectTimer);
|
|
|
|
- this.reconnectTimer = undefined;
|
|
|
|
- var websocketUrl = (window.debug ? 'ws://' + window.location.hostname + ':3002' : 'wss://snapdrop.net') + '/binary';
|
|
|
|
- this.client = new BinaryClient(websocketUrl);
|
|
|
|
- this.client.on('stream', function(stream, meta) {
|
|
|
|
- // collect stream data
|
|
|
|
- var parts = [];
|
|
|
|
- stream.on('data', function(data) {
|
|
|
|
- //console.log('part received', meta, data);
|
|
|
|
- if (data.isSystemEvent) {
|
|
|
|
- if (meta) {
|
|
|
|
- data.from = meta.from;
|
|
|
|
- }
|
|
|
|
- this.fire('system-event', data);
|
|
|
|
- } else {
|
|
|
|
- parts.push(data);
|
|
|
|
|
|
+ clearInterval(this.reconnectTimer);
|
|
|
|
+ this.reconnectTimer = undefined;
|
|
|
|
+ var websocketUrl = (window.debug ? 'ws://' + window.location.hostname + ':3002' : 'wss://snapdrop.net') + '/binary';
|
|
|
|
+ this.client = new BinaryClient(websocketUrl);
|
|
|
|
+ this.client.on('stream', function(stream, meta) {
|
|
|
|
+ // collect stream data
|
|
|
|
+ var parts = [];
|
|
|
|
+ stream.on('data', function(data) {
|
|
|
|
+ //console.log('part received', meta, data);
|
|
|
|
+ if (data.isSystemEvent) {
|
|
|
|
+ if (meta) {
|
|
|
|
+ data.from = meta.from;
|
|
}
|
|
}
|
|
- }.bind(this));
|
|
|
|
- // when finished, set it as the background image
|
|
|
|
- stream.on('end', function() {
|
|
|
|
- var blob = new Blob(parts, {
|
|
|
|
- type: meta.type
|
|
|
|
- });
|
|
|
|
- console.log('file received', blob, meta);
|
|
|
|
- this.fire('file-received', {
|
|
|
|
- blob: blob,
|
|
|
|
- name: meta.name,
|
|
|
|
- from: meta.from
|
|
|
|
- });
|
|
|
|
- }.bind(this));
|
|
|
|
|
|
+ this.fire('system-event', data);
|
|
|
|
+ } else {
|
|
|
|
+ parts.push(data);
|
|
|
|
+ }
|
|
}.bind(this));
|
|
}.bind(this));
|
|
- this.client.on('open', function(e) {
|
|
|
|
- console.log(e);
|
|
|
|
- this.client.send({}, {
|
|
|
|
- serverMsg: 'rtc-support',
|
|
|
|
- rtc: window.webRTCSupported
|
|
|
|
|
|
+ // when finished, set it as the background image
|
|
|
|
+ stream.on('end', function() {
|
|
|
|
+ var blob = new Blob(parts, {
|
|
|
|
+ type: meta.type
|
|
|
|
+ });
|
|
|
|
+ console.log('file received', blob, meta);
|
|
|
|
+ this.fire('file-received', {
|
|
|
|
+ blob: blob,
|
|
|
|
+ name: meta.name,
|
|
|
|
+ from: meta.from
|
|
});
|
|
});
|
|
}.bind(this));
|
|
}.bind(this));
|
|
- this.client.on('error', function(e) {
|
|
|
|
- this._reconnect(e);
|
|
|
|
- }.bind(this));
|
|
|
|
- this.client.on('close', function(e) {
|
|
|
|
- this._reconnect(e);
|
|
|
|
- }.bind(this));
|
|
|
|
- }
|
|
|
|
|
|
+ }.bind(this));
|
|
|
|
+ this.client.on('open', function(e) {
|
|
|
|
+ console.log(e);
|
|
|
|
+ this.client.send({}, {
|
|
|
|
+ serverMsg: 'rtc-support',
|
|
|
|
+ rtc: window.webRTCSupported
|
|
|
|
+ });
|
|
|
|
+ }.bind(this));
|
|
|
|
+ this.client.on('error', function(e) {
|
|
|
|
+ this._reconnect(e);
|
|
|
|
+ }.bind(this));
|
|
|
|
+ this.client.on('close', function(e) {
|
|
|
|
+ this._reconnect(e);
|
|
|
|
+ }.bind(this));
|
|
},
|
|
},
|
|
_sendFile: function(toPeer, file) {
|
|
_sendFile: function(toPeer, file) {
|
|
console.log('send file via WebSocket', file);
|
|
console.log('send file via WebSocket', file);
|