Created
April 9, 2015 21:18
-
-
Save kashifpk/97a406257fa61e560fb8 to your computer and use it in GitHub Desktop.
autobahn access from outside of class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from autobahn.twisted.wamp import ApplicationSession, ApplicationRunner | |
from twisted.internet.defer import inlineCallbacks | |
from autobahn.twisted.util import sleep | |
class MyComponent(ApplicationSession): | |
@inlineCallbacks | |
def onJoin(self, details): | |
print("session joined") | |
if not self.factory._myAppSession: | |
self.factory._myAppSession = self | |
def display_image(data): | |
print("Display image event received, data: {}".format(data)) | |
#yield sleep(1) | |
# notify that image has been displayed | |
self.publish(u'image_displayed', [data]) | |
#session.publish('image_displayed', 'from_direct_session') | |
try: | |
yield self.subscribe(display_image, u'display_image') | |
print("subscribed to topic: display_image") | |
except Exception as e: | |
print("could not subscribe to topic: {0}".format(e)) | |
if __name__ == '__main__': | |
runner = ApplicationRunner(url = u"ws://localhost:8080/ws", realm = u"realm1") | |
runner.run(MyComponent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment