--- a/runtime/WampClient.py Tue Oct 19 09:41:48 2021 +0200
+++ b/runtime/WampClient.py Tue Oct 19 15:15:03 2021 +0200
@@ -75,7 +75,14 @@
- "url": "ws://127.0.0.1:8888"
+ "url": "ws://127.0.0.1:8888", + "clientFactoryOptions": { + "autoPingInterval": 10, # Those two lists are meant to be filled by customized runtime
@@ -162,6 +169,14 @@
WampWebSocketClientFactory.__init__(self, *args, **kwargs)
+ clientFactoryOptions = config.extra.get("clientFactoryOptions") + if clientFactoryOptions: + self.setClientFactoryOptions(clientFactoryOptions) + print(_("Custom client factory options failed : "), e) + _transportFactory = None protocolOptions = config.extra.get('protocolOptions', None)
self.setProtocolOptions(**protocolOptions)
@@ -170,6 +185,11 @@
print(_("Custom protocol options failed :"), e)
+ def setClientFactoryOptions(self, options): + for key, value in options.items(): + if key in ["maxDelay", "initialDelay", "maxRetries", "factor", "jitter"]: + setattr(self, key, value) def buildProtocol(self, addr):
return ReconnectingClientFactory.buildProtocol(self, addr)
@@ -194,6 +214,9 @@
{"url": "Invalid URL: {}".format(url)},
_("WAMP configuration error:"))
+def UpdateWithDefault(d1, d2): + for k, v in d2.items(): @@ -203,6 +226,7 @@
if os.path.exists(_WampConf):
WampClientConf = json.load(open(_WampConf))
+ UpdateWithDefault(WampClientConf, defaultWampConfig) @@ -320,7 +344,9 @@
def StartReconnectWampClient():
+ # do reconnect and reset continueTrying and initialDelay parameter + if _transportFactory is not None: + _transportFactory.resetDelay() _WampSession.disconnect()
@@ -360,12 +386,25 @@
# WEB CONFIGURATION INTERFACE
WAMP_SECRET_URL = "secret"
-webExposedConfigItems = ['active', 'url', 'ID']
+webExposedConfigItems = [ + "clientFactoryOptions.maxDelay", + "protocolOptions.autoPingInterval", + "protocolOptions.autoPingTimeout" def wampConfigDefault(ctx, argument):
if lastKnownConfig is not None:
- return lastKnownConfig.get(argument.name, None)
+ # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is + argument_name_path = argument.name.split(".") + searchValue = lastKnownConfig + while argument_name_path: + searchValue = searchValue.get(argument_name_path.pop(0), None) def wampConfig(**kwargs):
@@ -378,9 +417,16 @@
newConfig = lastKnownConfig.copy()
for argname in webExposedConfigItems:
+ # Check if name is composed with an intermediate dot symbol and go deep in lastKnownConfig if it is + # and then set a new value. + argname_path = argname.split(".") + arg_last = argname_path.pop() arg = kwargs.get(argname, None)
- newConfig[argname] = arg
+ tmpConf = tmpConf.setdefault(argname_path.pop(0), {}) + tmpConf[arg_last] = arg SetConfiguration(newConfig)
@@ -427,8 +473,17 @@
default=wampConfigDefault)),
annotate.String(label=_("WAMP Server URL"),
- default=wampConfigDefault))]
+ default=wampConfigDefault)), + ("clientFactoryOptions.maxDelay", + annotate.Integer(label=_("Max reconnection delay (s)"), + default=wampConfigDefault)), + ("protocolOptions.autoPingInterval", + annotate.Integer(label=_("Auto ping interval (s)"), + default=wampConfigDefault)), + ("protocolOptions.autoPingTimeout", + annotate.Integer(label=_("Auto ping timeout (s)"), + default=wampConfigDefault)) def deliverWampSecret(ctx, segments):
# filename = segments[1].decode('utf-8')