aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-15 00:41:45 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-15 00:41:45 -0400
commita306d46a1ee07504b56f8f1115b8693fdf7b92b5 (patch)
treeb11287478ec2c3b4ec70516594dde01abe19c7e0
parent33d96c5143da76252532da5f02fe96ab2a82732e (diff)
downloadpython-termcast-server-a306d46a1ee07504b56f8f1115b8693fdf7b92b5.tar.gz
python-termcast-server-a306d46a1ee07504b56f8f1115b8693fdf7b92b5.zip
allow different kinds of message publishing
-rw-r--r--pubsub.py16
-rw-r--r--ssh.py3
-rw-r--r--termcast.py4
3 files changed, 19 insertions, 4 deletions
diff --git a/pubsub.py b/pubsub.py
index 6b860e0..b5faf22 100644
--- a/pubsub.py
+++ b/pubsub.py
@@ -10,7 +10,21 @@ class Publisher(object):
if who in self.subscribers:
self.subscribers.remove(who)
- def publish(self, message, *args):
+ def request_all(self, message, *args):
+ ret = []
+ for subscriber in self.subscribers:
+ method = "request_" + message
+ if hasattr(subscriber, method):
+ ret.append(getattr(subscriber, method)(*args))
+ return ret
+
+ def request_one(self, message, *args):
+ for subscriber in self.subscribers:
+ method = "request_" + message
+ if hasattr(subscriber, method):
+ return getattr(subscriber, method)(*args)
+
+ def notify(self, message, *args):
for subscriber in self.subscribers:
method = "msg_" + message
if hasattr(subscriber, method):
diff --git a/ssh.py b/ssh.py
index 52c9056..127f1d7 100644
--- a/ssh.py
+++ b/ssh.py
@@ -23,7 +23,8 @@ class Connection(object):
# XXX need to have the user select a stream, and then pass the stream's
# id in here
- self.publisher.publish("new_viewer", chan, "some-random-id")
+ contents = self.publisher.request_one("new_viewer", "some-random-id")
+ chan.send(contents)
time.sleep(5)
chan.close()
diff --git a/termcast.py b/termcast.py
index 1514fd9..fcc43c6 100644
--- a/termcast.py
+++ b/termcast.py
@@ -75,9 +75,9 @@ class Connection(object):
else:
return
- def msg_new_viewer(self, sock, connection_id):
+ def request_new_viewer(self, connection_id):
# XXX restore this once we start passing in meaningful connection ids
# if connection_id != self.connection_id:
# return
term_contents = self.handler.get_term()
- sock.send(term_contents.replace("\n", "\r\n"))
+ return term_contents.replace("\n", "\r\n")