# HG changeset patch
# User dporopat <denis.poropat@smarteh.si>
# Date 1523277518 -7200
# Node ID 2cef75d036c291370c70367bdfefd27dc49821ab
# Parent  35d6b9321ffd87b8d4e19fc91d64808874c6ded9
#2486 Added option to use websocket protocol options.

diff -r 35d6b9321ffd -r 2cef75d036c2 runtime/WampClient.py
--- 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()])
diff -r 35d6b9321ffd -r 2cef75d036c2 tests/wamp/project_files/wampconf.json
--- 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}
 }