runtime/WampClient.py
branchpython3
changeset 3752 9f6f46dbe3ae
parent 3750 f62625418bff
child 3881 0b3ac94f494c
equal deleted inserted replaced
3751:a80a66ba52d6 3752:9f6f46dbe3ae
    20 # You should have received a copy of the GNU Lesser General Public
    20 # You should have received a copy of the GNU Lesser General Public
    21 # License along with this library; if not, write to the Free Software
    21 # License along with this library; if not, write to the Free Software
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    23 
    23 
    24 
    24 
    25 
       
    26 
       
    27 import time
    25 import time
    28 import json
    26 import json
    29 import os
    27 import os
    30 import re
    28 import re
    31 from six import text_type as text
       
    32 from autobahn.twisted import wamp
    29 from autobahn.twisted import wamp
    33 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
    30 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
    34 from autobahn.wamp import types, auth
    31 from autobahn.wamp import types, auth
    35 from autobahn.wamp.serializer import MsgPackSerializer
    32 from autobahn.wamp.serializer import MsgPackSerializer
    36 from twisted.internet.protocol import ReconnectingClientFactory
    33 from twisted.internet.protocol import ReconnectingClientFactory
   140                 print(_("TypeError register option: {}".format(e)))
   137                 print(_("TypeError register option: {}".format(e)))
   141 
   138 
   142             self.register(GetCallee(name), '.'.join((ID, name)), registerOptions)
   139             self.register(GetCallee(name), '.'.join((ID, name)), registerOptions)
   143 
   140 
   144         for name in SubscribedEvents:
   141         for name in SubscribedEvents:
   145             self.subscribe(GetCallee(name), text(name))
   142             self.subscribe(GetCallee(name), str(name))
   146 
   143 
   147         for func in DoOnJoin:
   144         for func in DoOnJoin:
   148             func(self)
   145             func(self)
   149 
   146 
   150         print(_('WAMP session joined (%s) by:' % time.ctime()), ID)
   147         print(_('WAMP session joined (%s) by:' % time.ctime()), ID)
   156         _transportFactory = None
   153         _transportFactory = None
   157         print(_('WAMP session left'))
   154         print(_('WAMP session left'))
   158 
   155 
   159     def publishWithOwnID(self, eventID, value):
   156     def publishWithOwnID(self, eventID, value):
   160         ID = self.config.extra["ID"]
   157         ID = self.config.extra["ID"]
   161         self.publish(text(ID+'.'+eventID), value)
   158         self.publish(str(ID+'.'+eventID), value)
   162 
   159 
   163 
   160 
   164 class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
   161 class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
   165 
   162 
   166     def __init__(self, config, *args, **kwargs):
   163     def __init__(self, config, *args, **kwargs):
   368     return "Disconnected"
   365     return "Disconnected"
   369 
   366 
   370 
   367 
   371 def PublishEvent(eventID, value):
   368 def PublishEvent(eventID, value):
   372     if getWampStatus() == "Attached":
   369     if getWampStatus() == "Attached":
   373         _WampSession.publish(text(eventID), value)
   370         _WampSession.publish(str(eventID), value)
   374 
   371 
   375 
   372 
   376 def PublishEventWithOwnID(eventID, value):
   373 def PublishEventWithOwnID(eventID, value):
   377     if getWampStatus() == "Attached":
   374     if getWampStatus() == "Attached":
   378         _WampSession.publishWithOwnID(text(eventID), value)
   375         _WampSession.publishWithOwnID(str(eventID), value)
   379 
   376 
   380 
   377 
   381 # WEB CONFIGURATION INTERFACE
   378 # WEB CONFIGURATION INTERFACE
   382 WAMP_SECRET_URL = "secret"
   379 WAMP_SECRET_URL = "secret"
   383 webExposedConfigItems = [
   380 webExposedConfigItems = [
   444                 formless.iformless.ITypedRenderer)
   441                 formless.iformless.ITypedRenderer)
   445 
   442 
   446 
   443 
   447 def getDownloadUrl(ctx, argument):
   444 def getDownloadUrl(ctx, argument):
   448     if lastKnownConfig is not None:
   445     if lastKnownConfig is not None:
   449         return url.URL.fromContext(ctx).\
   446         return url.URL.fromConstr(ctx).\
   450             child(WAMP_SECRET_URL).\
   447             child(WAMP_SECRET_URL).\
   451             child(lastKnownConfig["ID"] + ".secret")
   448             child(lastKnownConfig["ID"] + ".secret")
   452 
   449 
   453 
   450 
   454 webFormInterface = [
   451 webFormInterface = [