PairDrop/app/elements/p2p-network/connection-wrapper.html

58 lines
2 KiB
HTML
Raw Normal View History

<link rel="import" href="p2p-network.html">
<link rel="import" href="web-socket.html">
<dom-module id="connection-wrapper">
<template>
<p2p-network id="p2p" me="{{me}}"></p2p-network>
<web-socket id="ws" me="{{me}}"></web-socket>
</template>
<script>
'use strict';
(function() {
2015-12-26 13:33:16 +01:00
window.webRTCSupported = !!(window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection || window.webkitRTCPeerConnection);
function rtcConnectionSupported(peerId) {
2015-12-26 13:33:16 +01:00
return window.webRTCSupported && (peerId.indexOf('rtc_') === 0);
}
Polymer({
is: 'connection-wrapper',
properties: {
me: {
2015-12-26 13:33:16 +01:00
notify: true
},
},
behaviors: [Chat.FileTransferProtocol],
_sendFile: function(toPeer, file) {
if (!rtcConnectionSupported(toPeer)) {
this.$.ws._sendFile(toPeer, file);
} else {
this.$.p2p._sendFile(toPeer, file);
}
},
_sendSystemEvent: function(toPeer, event) {
console.log('system event', toPeer, event);
if (!rtcConnectionSupported(toPeer)) {
this.$.ws._sendSystemEvent(toPeer, event);
} else {
this.$.p2p._sendSystemEvent(toPeer, event);
}
},
connectToPeer: function(toPeer, callback) {
if (!rtcConnectionSupported(toPeer)) {
callback();
} else {
2015-12-26 13:33:16 +01:00
this.$.p2p.connectToPeer(toPeer, callback);
}
},
2015-12-26 13:33:16 +01:00
_onHandshake: function(event) {
var me = event.uuid;
console.log('i am');
this.set('me', me);
if (window.webRTCSupported) {
this.$.p2p.initialize();
}
}
});
})();
</script>
</dom-module>