buddy-finder.html 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <link rel="import" href="../../bower_components/iron-ajax/iron-ajax.html">
  2. <link rel="import" href="../../bower_components/paper-styles/paper-styles.html">
  3. <link rel="import" href="../file-sharing/file-input.html">
  4. <link rel="import" href="user-avatar.html">
  5. <link rel="import" href="personal-avatar.html">
  6. <dom-module id="buddy-finder">
  7. <template>
  8. <style>
  9. :host {
  10. background-color: transparent;
  11. @apply(--layout-fit);
  12. @apply(--layout-horizontal);
  13. @apply(--layout-center-center);
  14. overflow: hidden;
  15. position: relative;
  16. height: 100%;
  17. -webkit-user-select: none;
  18. -moz-user-select: none;
  19. -ms-user-select: none;
  20. user-select: none;
  21. margin: 0;
  22. }
  23. .buddies {
  24. z-index: 1;
  25. @apply(--layout-horizontal);
  26. @apply(--layout-center-center);
  27. @apply(--layout-wrap);
  28. }
  29. .buddy {
  30. cursor: pointer;
  31. }
  32. .me {
  33. position: absolute;
  34. bottom: 24px;
  35. left: 50%;
  36. margin-left: -180px;
  37. }
  38. .explanation {
  39. @apply(--paper-font-headline);
  40. color: #4285f4;
  41. text-align: center;
  42. }
  43. </style>
  44. <div class="buddies">
  45. <template is="dom-repeat" items="{{buddies}}">
  46. <file-input on-file-selected="_fileSelected">
  47. <user-avatar contact="{{item}}" class="buddy"></user-avatar>
  48. </file-input>
  49. </template>
  50. </div>
  51. <div hidden$="{{buddies.length}}" class="explanation">
  52. Open this page on another device
  53. <wbr>to share files.
  54. </div>
  55. <personal-avatar class="me"></personal-avatar>
  56. <!-- <iron-ajax id="ajax" auto url="https://yawim.com/findbuddies/{{me}}" handle-as="json" last-response="{{buddies}}"></iron-ajax> -->
  57. </template>
  58. <script>
  59. 'use strict';
  60. Polymer({
  61. is: 'buddy-finder',
  62. properties: {
  63. buddies: {
  64. type: Array,
  65. value: []
  66. },
  67. me: {
  68. type: String,
  69. }
  70. },
  71. attached: function() {
  72. //Ask server every second for changes
  73. var ajax = this.$.ajax;
  74. function request() {
  75. //ajax.generateRequest();
  76. }
  77. var intervalId = setInterval(request, 1000);
  78. document.addEventListener('visibilitychange', function() {
  79. if (document.hidden) {
  80. clearInterval(intervalId);
  81. intervalId = 0;
  82. } else {
  83. if (!intervalId) {
  84. intervalId = setInterval(request, 1000);
  85. }
  86. }
  87. });
  88. },
  89. _fileSelected: function(e) {
  90. var peerId = e.model.item.peerId;
  91. var file = e.detail;
  92. app.p2p.sendFile(peerId, file);
  93. }
  94. });
  95. </script>
  96. </dom-module>