Skip to content

Commit

Permalink
Updated to stomp.py 8.1.0
Browse files Browse the repository at this point in the history
Resolves #17
  • Loading branch information
chrisn committed Mar 13, 2024
1 parent 216b45a commit dfcf82e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
39 changes: 20 additions & 19 deletions lib/radiovis_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ def stop(self):
self._connection.disconnect()
self._connection.transport.stop()

def on_connected(self, headers, body):
def on_connected(self, frame):
"""
Once connected, subscribe to the message queues for TEXT and SHOW
messages.
"""
self.notify("CONNECTED", headers, body)
self.notify("CONNECTED", frame)

if self._text_topic is not None:
self._connection.subscribe(destination = self._text_topic, ack = 'auto')
Expand All @@ -82,14 +82,14 @@ def on_connected(self, headers, body):
def on_disconnected(self):
self.notify("lost connection")

def on_message(self, headers, body):
def on_message(self, frame):
"""
Handler for received MESSAGE frames. Parse the message body
to extract TEXT and SHOW RadioVIS messages.
"""
self.notify("MESSAGE", headers, body)
self.notify("MESSAGE", frame)

lines = body.split('\n')
lines = frame.body.split('\n')

for line in lines:
# Remove leading and trailing whitespace.
Expand All @@ -109,46 +109,47 @@ def on_message(self, headers, body):
if match:
url = match.group(1)

if 'link' in headers:
link = headers['link']
if 'link' in frame.headers:
link = frame.headers['link']
else:
link = None

if 'trigger-time' in headers:
if 'trigger-time' in frame.headers:
# TODO: Parse date_time and construct a datetime object.
date_time = headers['trigger-time']
date_time = frame.headers['trigger-time']
else:
date_time = None

self.notify_show(url, link, date_time)
else:
pass

def on_receipt(self, headers, body):
self.notify("RECEIPT", headers, body)
def on_receipt(self, frame):
self.notify("RECEIPT", frame)

def on_error(self, headers, body):
def on_error(self, frame):
"""
Handler for received ERROR frames.
"""
self.notify("ERROR", headers, body)
self.notify("ERROR", frame)

def disconnect(self, args):
try:
self._connection.disconnect()
except stomp.NotConnectedException:
pass # ignore if no longer connected

def notify(self, message, headers = None, body = ''):
def notify(self, message, frame = None):
for listener in self._listeners:
listener.stomp_message(message)

if headers is not None:
for header in headers:
listener.stomp_message("%s: %s" % (header, headers[header]))
if frame is not None:
if frame.headers is not None:
for header in frame.headers:
listener.stomp_message("%s: %s" % (header, frame.headers[header]))

if len(body) > 0:
listener.stomp_message(body)
if len(frame.body) > 0:
listener.stomp_message(frame.body)

def notify_text(self, text):
"""
Expand Down
2 changes: 1 addition & 1 deletion requirements-ubuntu.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dnspython~=2.6.1
pynose~=1.5.0
stomp.py~=4.1.22
stomp.py~=8.1.0
PySocks~=1.7.1
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
wxPython~=4.2.1
dnspython~=2.6.1
nose~=1.5.0
stomp.py~=4.1.22
pynose~=1.5.0
stomp.py~=8.1.0
PySocks~=1.7.1

0 comments on commit dfcf82e

Please sign in to comment.