buddy-finder.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. <dom-module id="buddy-finder">
  6. <template>
  7. <style>
  8. :host {
  9. display: block;
  10. background-color: white;
  11. @apply(--layout-fit);
  12. @apply(--layout-horizontal);
  13. @apply(--layout-center-center);
  14. overflow: hidden;
  15. }
  16. .paper-font-display1 {
  17. color: black;
  18. text-align: center;
  19. margin-bottom: 16px;
  20. display: none;
  21. }
  22. .buddies {
  23. z-index: 1;
  24. @apply(--layout-horizontal);
  25. }
  26. .buddy {
  27. cursor: pointer;
  28. }
  29. .circles {
  30. position: absolute;
  31. bottom: -50px;
  32. left: 50%;
  33. width: 1140px;
  34. margin-left: -570px;
  35. height: 700px;
  36. transform-origin: 570px 570px;
  37. animation: grow 1.5s ease-out;
  38. fill: transparent;
  39. }
  40. .me {
  41. position: absolute;
  42. bottom: 30px;
  43. left: 50%;
  44. margin-left: -60px;
  45. }
  46. </style>
  47. <div class="paper-font-display1">People near by</div>
  48. <div class="buddies">
  49. <template is="dom-repeat" items="{{buddies}}">
  50. <file-input on-file-selected="_fileDropped">
  51. <user-avatar contact="{{item.peerId}}" class="buddy"></user-avatar>
  52. </file-input>
  53. </template>
  54. </div>
  55. <user-avatar contact="{{me}}" class="me"></user-avatar>
  56. <svg class="circles" viewBox="-0.5 -0.5 1140 700">
  57. <circle class="circle" cx="570" cy="570" r="120" stroke="rgba(160,160,160,.15)"></circle>
  58. <circle class="circle" cx="570" cy="570" r="210" stroke="rgba(160,160,160,.2)"></circle>
  59. <circle class="circle" cx="570" cy="570" r="300" stroke="rgba(160,160,160,.3)"></circle>
  60. <circle class="circle" cx="570" cy="570" r="390" stroke="rgba(160,160,160,.35)"></circle>
  61. <circle class="circle" cx="570" cy="570" r="480" stroke="rgba(160,160,160,.4)"></circle>
  62. <circle class="circle" cx="570" cy="570" r="570" stroke="rgba(160,160,160,.43)"></circle>
  63. </svg>
  64. <iron-ajax id="ajax" auto url="https://yawim.com/findbuddies/{{me}}" handle-as="json" last-response="{{buddies}}"></iron-ajax>
  65. </template>
  66. <script>
  67. 'use strict';
  68. Polymer({
  69. is: 'buddy-finder',
  70. properties: {
  71. buddies: Array,
  72. me: {
  73. type: String,
  74. }
  75. },
  76. attached: function() {
  77. //Ask server every second for changes
  78. setInterval(function() {
  79. this.$.ajax.generateRequest();
  80. }.bind(this), 1000);
  81. },
  82. _fileDropped: function(e) {
  83. var peerId = e.model.item.peerId;
  84. var file = e.detail;
  85. app.p2p.connectToPeer(peerId, function() {
  86. app.p2p.sendFile(peerId, file);
  87. });
  88. console.log('Send:', file);
  89. console.log('To:', peerId);
  90. }
  91. });
  92. </script>
  93. </dom-module>