runtime/WampClient.py
changeset 1898 d2dbdeffc426
parent 1894 f224383cc883
child 1899 ff4410112b67
equal deleted inserted replaced
1897:62f9cae9a25f 1898:d2dbdeffc426
    52     "RemoteExec",
    52     "RemoteExec",
    53     "GetLogMessage",
    53     "GetLogMessage",
    54     "ResetLogCount",
    54     "ResetLogCount",
    55 ]
    55 ]
    56 
    56 
       
    57 # Those two lists are meant to be filled by customized runtime
       
    58 # or User python code. 
       
    59 
       
    60 """ crossbar Events to register to """  
    57 SubscribedEvents = []
    61 SubscribedEvents = []
    58 
    62 
       
    63 """ things to do on join (callables) """  
    59 DoOnJoin = []
    64 DoOnJoin = []
    60 
    65 
    61 
    66 
    62 def GetCallee(name):
    67 def GetCallee(name):
    63     """ Get Callee or Subscriber corresponding to '.' spearated object path """
    68     """ Get Callee or Subscriber corresponding to '.' spearated object path """
    86 
    91 
    87     @inlineCallbacks
    92     @inlineCallbacks
    88     def onJoin(self, details):
    93     def onJoin(self, details):
    89         global _WampSession
    94         global _WampSession
    90         _WampSession = self
    95         _WampSession = self
    91         ID = self.config.extra["ID"]
    96         ID = self.config.extra["ID"] # this is unicode
    92         print('WAMP session joined by :', ID)
    97         print('WAMP session joined by :', ID)
    93         for name in ExposedCalls:
    98         for name in ExposedCalls:
    94             regoption = types.RegisterOptions(u'exact',u'last',None, None)
    99             regoption = types.RegisterOptions(u'exact',u'last',None, None)
    95             yield self.register(GetCallee(name), '.'.join((ID, name)), regoption)
   100             yield self.register(GetCallee(name), u'.'.join((ID, name)), regoption)
    96 
   101 
    97         for name in SubscribedEvents:
   102         for name in SubscribedEvents:
    98             yield self.subscribe(GetCallee(name), name)
   103             yield self.subscribe(GetCallee(name), unicode(name))
    99 
   104 
   100         for func in DoOnJoin:
   105         for func in DoOnJoin:
   101             yield func(self)
   106             yield func(self)
   102 
   107 
   103     def onLeave(self, details):
   108     def onLeave(self, details):
   148     WampSecret = LoadWampSecret(secretfname)
   153     WampSecret = LoadWampSecret(secretfname)
   149 
   154 
   150     # create a WAMP application session factory
   155     # create a WAMP application session factory
   151     component_config = types.ComponentConfig(
   156     component_config = types.ComponentConfig(
   152         realm=WSClientConf["realm"],
   157         realm=WSClientConf["realm"],
   153         extra=WSClientConf)
   158         extra=WSClientConf) # pass a dict containing unicode values
   154     session_factory = wamp.ApplicationSessionFactory(
   159     session_factory = wamp.ApplicationSessionFactory(
   155         config=component_config)
   160         config=component_config)
   156     session_factory.session = WampSession
   161     session_factory.session = WampSession
   157 
   162 
   158     # create a WAMP-over-WebSocket transport client factory
   163     # create a WAMP-over-WebSocket transport client factory