From d9368602cad00ab5dc53959bce0e9ee49ee38a69 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Sun, 24 Aug 2014 00:44:35 +0200 Subject: actually sending json data --- src/daq/flumotion-plug/sfive.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/daq/flumotion-plug') diff --git a/src/daq/flumotion-plug/sfive.py b/src/daq/flumotion-plug/sfive.py index 4253f7c..59918ca 100644 --- a/src/daq/flumotion-plug/sfive.py +++ b/src/daq/flumotion-plug/sfive.py @@ -38,6 +38,8 @@ from flumotion.common.poller import Poller from twisted.internet import protocol, reactor from socket import error as socket_error +import simplejson as json +import datetime from flumotion.common.i18n import N_ T_ = i18n.gettexter() @@ -128,13 +130,10 @@ class ComponentSFivePlug(base.ComponentPlug): def _sendInit(self): self.debug('SFive: sending init message') - # TODO: create json and send it out - # { - # "hostname": "myhostname", - # "streamer-id": { "content-id": "av-orig", "format": "flash", "quality": "medium" }, - # "tags": [ "elevate", "2014", "discourse" ] - # } - self._proto.sendDatagram('hi! this is %s speaking\n' % (self._hostname)); + initdata = { "hostname": self._hostname, + "streamer-id": { "content-id": self._content_id, "format": self._format, "quality": self._quality }, + "tags": [] } + self._proto.sendDatagram(json.dumps(initdata)); def _updateSFive(self): client_count = self._component.getClients() @@ -160,6 +159,9 @@ class ComponentSFivePlug(base.ComponentPlug): # "bytes-sent": 921734098, # .... # } - data_str = 'client-count: %d, bytes_received: %d, bytes_sent: %d\n' % (client_count, bytes_received_diff, bytes_sent_diff) - self.debug(data_str) - self._proto.sendDatagram(data_str); + data = { "start-time": datetime.datetime.utcnow().isoformat('Z'), + "duration-ms": self._duration * 1000, + "client-count": client_count, + "bytes-received": bytes_received_diff, + "bytes-sent": bytes_sent_diff } + self._proto.sendDatagram(json.dumps(data)); -- cgit v1.2.3