#2486 Added option to use websocket protocol options. #2486
authordporopat <denis.poropat@smarteh.si>
Mon, 09 Apr 2018 14:38:38 +0200
branch#2486
changeset 2195 2cef75d036c2
parent 2194 35d6b9321ffd
child 2196 9017e830ae70
#2486 Added option to use websocket protocol options.
runtime/WampClient.py
tests/wamp/project_files/wampconf.json
--- a/runtime/WampClient.py	Tue Mar 27 10:11:04 2018 +0200
+++ b/runtime/WampClient.py	Mon Apr 09 14:38:38 2018 +0200
@@ -26,6 +26,7 @@
 from __future__ import print_function
 import time
 import json
+import inspect
 from autobahn.twisted import wamp
 from autobahn.twisted.websocket import WampWebSocketClientFactory, connectWS
 from autobahn.wamp import types, auth
@@ -110,6 +111,25 @@
 
 
 class ReconnectingWampWebSocketClientFactory(WampWebSocketClientFactory, ReconnectingClientFactory):
+    def __init__(self, config, *args, **kwargs):
+        WampWebSocketClientFactory.__init__(self, *args, **kwargs)
+
+        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:
+            self.setProtocolOptions(**validProtocolOptions)
+            print(_("Added custom protocol options"))
+
+        del validProtocolOptions
+        del protocolOptions
+
     def buildProtocol(self, addr):
         self.resetDelay()
         return ReconnectingClientFactory.buildProtocol(self, addr)
@@ -168,6 +188,7 @@
 
     # create a WAMP-over-WebSocket transport client factory
     transport_factory = ReconnectingWampWebSocketClientFactory(
+        component_config,
         session_factory,
         url=WSClientConf["url"],
         serializers=[MsgPackSerializer()])
--- a/tests/wamp/project_files/wampconf.json	Tue Mar 27 10:11:04 2018 +0200
+++ b/tests/wamp/project_files/wampconf.json	Mon Apr 09 14:38:38 2018 +0200
@@ -3,5 +3,6 @@
     "realm":"Automation",
     "ID":"wamptest",
     "password":"1234567890",
-    "key":"ABCDEFGHIJ"
+    "key":"ABCDEFGHIJ",
+    "protocolOptions":{"autoPingTimeout":20, "autoPingInterval":60}
 }