2015-12-23 13:57:13 +01:00
|
|
|
<link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html">
|
|
|
|
<link rel="import" href="../../bower_components/paper-styles/paper-styles.html">
|
2015-12-19 01:18:02 +01:00
|
|
|
<link rel="import" href="../file-sharing/file-input.html">
|
2015-12-18 17:43:46 +01:00
|
|
|
<link rel="import" href="user-avatar.html">
|
2015-12-23 13:57:13 +01:00
|
|
|
<link rel="import" href="personal-avatar.html">
|
2015-12-18 17:43:46 +01:00
|
|
|
<dom-module id="buddy-finder">
|
|
|
|
<template>
|
|
|
|
<style>
|
|
|
|
:host {
|
2015-12-23 13:57:13 +01:00
|
|
|
background-color: transparent;
|
2015-12-18 17:43:46 +01:00
|
|
|
@apply(--layout-fit);
|
2015-12-19 01:18:02 +01:00
|
|
|
@apply(--layout-horizontal);
|
2015-12-18 17:43:46 +01:00
|
|
|
@apply(--layout-center-center);
|
2015-12-19 01:18:02 +01:00
|
|
|
overflow: hidden;
|
2015-12-23 13:57:13 +01:00
|
|
|
position: relative;
|
|
|
|
height: 100%;
|
|
|
|
-webkit-user-select: none;
|
|
|
|
-moz-user-select: none;
|
|
|
|
-ms-user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
margin: 0;
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.buddies {
|
|
|
|
z-index: 1;
|
2015-12-19 01:18:02 +01:00
|
|
|
@apply(--layout-horizontal);
|
2015-12-23 13:57:13 +01:00
|
|
|
@apply(--layout-center-center);
|
|
|
|
@apply(--layout-wrap);
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.buddy {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
|
2015-12-23 13:57:13 +01:00
|
|
|
.me {
|
2015-12-18 17:43:46 +01:00
|
|
|
position: absolute;
|
2015-12-23 13:57:13 +01:00
|
|
|
bottom: 24px;
|
2015-12-18 17:43:46 +01:00
|
|
|
left: 50%;
|
2015-12-23 13:57:13 +01:00
|
|
|
margin-left: -180px;
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
|
2015-12-23 13:57:13 +01:00
|
|
|
.explanation {
|
|
|
|
@apply(--paper-font-headline);
|
|
|
|
color: #4285f4;
|
|
|
|
text-align: center;
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
<div class="buddies">
|
|
|
|
<template is="dom-repeat" items="{{buddies}}">
|
2015-12-23 13:57:13 +01:00
|
|
|
<file-input on-file-selected="_fileSelected">
|
|
|
|
<user-avatar contact="{{item}}" class="buddy"></user-avatar>
|
2015-12-19 01:18:02 +01:00
|
|
|
</file-input>
|
2015-12-18 17:43:46 +01:00
|
|
|
</template>
|
|
|
|
</div>
|
2015-12-23 13:57:13 +01:00
|
|
|
<div hidden$="{{buddies.length}}" class="explanation">
|
|
|
|
Open this page on another device
|
|
|
|
<wbr>to share files.
|
|
|
|
</div>
|
|
|
|
<personal-avatar class="me"></personal-avatar>
|
|
|
|
<!-- <iron-ajax id="ajax" auto url="https://yawim.com/findbuddies/{{me}}" handle-as="json" last-response="{{buddies}}"></iron-ajax> -->
|
2015-12-18 17:43:46 +01:00
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
'use strict';
|
|
|
|
Polymer({
|
|
|
|
is: 'buddy-finder',
|
|
|
|
properties: {
|
2015-12-23 13:57:13 +01:00
|
|
|
buddies: {
|
|
|
|
type: Array,
|
|
|
|
value: []
|
|
|
|
},
|
2015-12-18 17:43:46 +01:00
|
|
|
me: {
|
|
|
|
type: String,
|
|
|
|
}
|
|
|
|
},
|
2015-12-19 01:18:02 +01:00
|
|
|
attached: function() {
|
|
|
|
//Ask server every second for changes
|
2015-12-23 13:57:13 +01:00
|
|
|
var ajax = this.$.ajax;
|
|
|
|
|
|
|
|
function request() {
|
|
|
|
//ajax.generateRequest();
|
|
|
|
}
|
|
|
|
var intervalId = setInterval(request, 1000);
|
|
|
|
document.addEventListener('visibilitychange', function() {
|
|
|
|
if (document.hidden) {
|
|
|
|
clearInterval(intervalId);
|
|
|
|
intervalId = 0;
|
|
|
|
} else {
|
|
|
|
if (!intervalId) {
|
|
|
|
intervalId = setInterval(request, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2015-12-19 01:18:02 +01:00
|
|
|
},
|
2015-12-23 13:57:13 +01:00
|
|
|
_fileSelected: function(e) {
|
2015-12-19 01:18:02 +01:00
|
|
|
var peerId = e.model.item.peerId;
|
|
|
|
var file = e.detail;
|
2015-12-23 13:57:13 +01:00
|
|
|
app.p2p.sendFile(peerId, file);
|
2015-12-18 17:43:46 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
</dom-module>
|