Squashed commit of the following:

commit 5b7ac6f0f56f3888c01049f08b6b47dbeb3bcfb0
Author: Robin Linus <robin_woll@capira.de>
Date:   Wed Dec 30 18:06:48 2015 +0100

    Clean up about and social links

commit 9c7da37d1e8f58f1c45626289fbab336fc982a0f
Author: Robin Linus <robin_woll@capira.de>
Date:   Wed Dec 30 18:06:35 2015 +0100

    Change Slogan

commit fcea5cfb5c6928acabce44caacc1d75fafdab447
Author: Robin Linus <robin_woll@capira.de>
Date:   Wed Dec 30 18:06:22 2015 +0100

    Add shorturl

commit f09e9e42c30aa7b26df2a5fb00bec653f3ad68e1
Author: Robin Linus <robin_woll@capira.de>
Date:   Wed Dec 30 16:56:55 2015 +0100

    initial
This commit is contained in:
Robin Linus 2015-12-30 18:07:37 +01:00
parent 1bce467a7c
commit e756a3fd0c
11 changed files with 278 additions and 128 deletions

View file

@ -9,55 +9,68 @@
</template>
<script>
'use strict';
window.isActive = true;
window.onfocus = function() {
window.isActive = true;
};
window.onblur = function() {
window.isActive = false;
};
Polymer({
is: 'web-socket',
attached: function() {
this.init();
},
init: function() {
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;
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);
}
this.fire('system-event', data);
} else {
parts.push(data);
}
}.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));
}.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
this.client.on('open', function(e) {
console.log(e);
this.client.send({}, {
serverMsg: 'rtc-support',
rtc: window.webRTCSupported
});
}.bind(this));
}.bind(this));
this.client.on('open', function(e) {
this.cancelAsync(this.reconnectTimer);
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));
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) {
console.log('send file via WebSocket', file);
@ -80,7 +93,9 @@
_reconnect: function(e) {
console.log('disconnected', e);
//try to reconnect after 3s
this.reconnectTimer = this.async(this.init, 3000);
if (!this.reconnectTimer) {
this.reconnectTimer = setInterval(this.init.bind(this), 3000);
}
}
});
</script>