#2486 Added option to use websocket register options. Added function getValidOptins to read options from wampconf.json. #2486
authordporopat <denis.poropat@smarteh.si>
Tue, 10 Apr 2018 09:54:22 +0200
branch#2486
changeset 2196 9017e830ae70
parent 2195 2cef75d036c2
child 2197 bec80ff35282
#2486 Added option to use websocket register options. Added function getValidOptins to read options from wampconf.json.
runtime/WampClient.py
tests/wamp/project_files/wampconf.json
--- a/runtime/WampClient.py	Mon Apr 09 14:38:38 2018 +0200
+++ b/runtime/WampClient.py	Tue Apr 10 09:54:22 2018 +0200
@@ -70,6 +70,15 @@
         obj = getattr(obj, names.pop(0))
     return obj
 
+def getValidOptins(options, arguments):
+    validOptions = {}
+    for key in options:
+        if key in arguments:
+            validOptions[key] = options[key]
+    if len(validOptions) > 0:
+        return validOptions
+    else:
+        return None
 
 class WampSession(wamp.ApplicationSession):
     def onConnect(self):
@@ -92,8 +101,16 @@
         global _WampSession
         _WampSession = self
         ID = self.config.extra["ID"]
+        regoption = None
+
+        registerOptions = self.config.extra.get('registerOptions', None)
+        arguments = inspect.getargspec(types.RegisterOptions.__init__).args
+        validRegisterOptions = getValidOptins(registerOptions, arguments)
+        if validRegisterOptions:
+            regoption = types.RegisterOptions(**validRegisterOptions)
+            #print(_("Added custom register options"))
+
         for name in ExposedCalls:
-            regoption = types.RegisterOptions(u'exact', u'last')
             yield self.register(GetCallee(name), u'.'.join((ID, name)), regoption)
 
         for name in SubscribedEvents:
@@ -114,21 +131,12 @@
     def __init__(self, config, *args, **kwargs):
         WampWebSocketClientFactory.__init__(self, *args, **kwargs)
 
+        protocolOptions = config.extra.get('protocolOptions', None)
         arguments = inspect.getargspec(self.setProtocolOptions).args
-        protocolOptions = config.extra.get('protocolOptions', None)
-
-        validProtocolOptions = {}
-
-        for key in protocolOptions:
-            if key in arguments:
-                validProtocolOptions[key] = protocolOptions[key]
-
-        if len(validProtocolOptions) > 0:
+        validProtocolOptions = getValidOptins(protocolOptions, arguments)
+        if validProtocolOptions:
             self.setProtocolOptions(**validProtocolOptions)
-            print(_("Added custom protocol options"))
-
-        del validProtocolOptions
-        del protocolOptions
+            #print(_("Added custom protocol options"))
 
     def buildProtocol(self, addr):
         self.resetDelay()
--- a/tests/wamp/project_files/wampconf.json	Mon Apr 09 14:38:38 2018 +0200
+++ b/tests/wamp/project_files/wampconf.json	Tue Apr 10 09:54:22 2018 +0200
@@ -4,5 +4,6 @@
     "ID":"wamptest",
     "password":"1234567890",
     "key":"ABCDEFGHIJ",
-    "protocolOptions":{"autoPingTimeout":20, "autoPingInterval":60}
+    "protocolOptions":{"autoPingTimeout":20, "autoPingInterval":60},
+    "registerOptions":{"match":"exact", "invoke":"last", "concurrency": 2}
 }