Mercurial > code > home > repos > light9
view web/light9-collector-client.html @ 2376:4556eebe5d73
topdir reorgs; let pdm have its src/ dir; separate vite area from light9/
author | drewp@bigasterisk.com |
---|---|
date | Sun, 12 May 2024 19:02:10 -0700 |
parents | light9/web/light9-collector-client.html@16e0af42613f |
children |
line wrap: on
line source
<link rel="import" href="/lib/polymer/polymer.html"> <link rel="import" href="/lib/iron-ajax/iron-ajax.html"> <dom-module id="light9-collector-client"> <template> <iron-ajax url="/collector/attrs" method="PUT" id="put"></iron-ajax> <span>{{status}} ([[sent]] sent)</span> </template> <script> Polymer({ is: "light9-collector-client", properties: { status: {type: String, value: 'init'}, clientSession: {value: ""+Date.now()}, self: {type: Object, notify: true}, sent: {type: Number, value: 0}, }, ready: function() { this.self = this; var self = this; this.lastSent = []; self.$.put.addEventListener( 'error', function() { self.status = 'err'; }); self.$.put.addEventListener( 'request', function() { self.status = 'send'; }); self.$.put.addEventListener( 'response', function() { self.status = 'ok'; }); // collector gives up on clients after 10sec setInterval(self.ping.bind(self), 9000); self.status = 'ready'; }, ping: function() { this.send(this.lastSent); }, send: function(settings) { this.$.put.body = JSON.stringify({ "settings": settings, "client": window.location.href, "clientSession": this.clientSession, "sendTime": Date.now() / 1000 }); this.$.put.generateRequest(); this.sent += 1; this.lastSent = settings.slice(); } }); </script> </dom-module>