Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2022-06-20 15:42:36 +0300
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2022-06-20 19:38:04 +0300
commitbb238e39b5622866e37c0e65affe01dd10806502 (patch)
tree28934d4652f6a0b197a75e6fa1ba59a8ad760eb7 /docs
parentc042d67ac0ac155d385ff755a9978e8ea6cd0103 (diff)
Extract code specific to siege mode
In order to add support for the virtual participant mode in a following commit the Talkbuchet wrapper class was split in a base class with the common code and a subclass with the code specific to siege mode. Similarly, the global helper functions were also split between the common ones and the siege specific ones, which will only be defined when "switchToSiegeMode()" is called (done by default). Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'docs')
-rw-r--r--docs/Talkbuchet-cli.py231
1 files changed, 131 insertions, 100 deletions
diff --git a/docs/Talkbuchet-cli.py b/docs/Talkbuchet-cli.py
index 7816e3877..43341e486 100644
--- a/docs/Talkbuchet-cli.py
+++ b/docs/Talkbuchet-cli.py
@@ -492,9 +492,9 @@ class SeleniumHelper:
self.printLogs()
-class Talkbuchet:
+class TalkbuchetCommon:
"""
- Wrapper for Talkbuchet.
+ Base class for Talkbuchet wrappers.
Talkbuchet wrappers load Talkbuchet on a given Nextcloud URL and provide
methods to call the different Talkbuchet functions in the browser.
@@ -513,11 +513,6 @@ class Talkbuchet:
the local server is used by default.
"""
- # Set default values from Talkbuchet.js.
- self.publishersCount = 5
- self.subscribersPerPublisherCount = 40
- self.connectionWarningTimeout = 5000
-
self.seleniumHelper = SeleniumHelper()
if browser == 'chrome':
@@ -640,6 +635,27 @@ class Talkbuchet:
self.seleniumHelper.executeAsync('await startMedia(' + ('true' if audio else 'false') + ', ' + ('true' if video else 'false') + ')')
+
+class Siege(TalkbuchetCommon):
+ """
+ Wrapper for Talkbuchet in siege mode.
+
+ Besides the common functions this wrapper exposes only the Talkbuchet
+ functions for siege mode.
+ """
+
+ def __init__(self, browser, nextcloudUrl, headless = True, remoteSeleniumUrl = None):
+ """
+ See :py:meth:`TalkbuchetCommon.__init__`.
+ """
+
+ super().__init__(browser, nextcloudUrl, headless, remoteSeleniumUrl)
+
+ # Set default values from Talkbuchet.js.
+ self.publishersCount = 5
+ self.subscribersPerPublisherCount = 40
+ self.connectionWarningTimeout = 5000
+
def closeConnections(self):
"""
Stops the siege by closing the publisher and subscriber connections
@@ -914,140 +930,153 @@ _subscribersPerPublisherCount = None
sieges = []
-def _isValidConfiguration():
- if not _isValidBrowser():
- return False
+def switchToSiegeMode():
+ """
+ Sets the siege mode as the active one.
- if not _nextcloudUrl:
- print("Set target Nextcloud URL first")
- return False
+ This adjusts the global helper functions to those relevant for this mode.
+ """
- if not _user or not _appToken:
- print("Set credentials (user and app token) first")
- return False
+ def _isValidConfiguration():
+ if not _isValidBrowser():
+ return False
- return True
+ if not _nextcloudUrl:
+ print("Set target Nextcloud URL first")
+ return False
-def setPublishersAndSubscribersCount(publishersCount, subscribersPerPublisherCount):
- """
- Sets the number of publishers and subscribers per publisher to use.
+ if not _user or not _appToken:
+ print("Set credentials (user and app token) first")
+ return False
- By the default the number from Talkbuchet.js is used, which is 5 publishers
- and 40 subscribers per publisher.
+ return True
- This is used only for the global helper functions and is not taken into
- account if a Talkbuchet wrapper is manually created.
+ def setPublishersAndSubscribersCount(publishersCount, subscribersPerPublisherCount):
+ """
+ Sets the number of publishers and subscribers per publisher to use.
- :param publishersCount: the number of publishers.
- :param subscribersPerPublisherCount: the number of subscribers for each
- publisher.
- """
+ By the default the number from Talkbuchet.js is used, which is 5
+ publishers and 40 subscribers per publisher.
- global _publishersCount, _subscribersPerPublisherCount
- _publishersCount = publishersCount
- _subscribersPerPublisherCount = subscribersPerPublisherCount
+ This is used only for the global helper functions and is not taken into
+ account if a Talkbuchet wrapper is manually created.
-def startSiege():
- """
- Starts a siege.
+ :param publishersCount: the number of publishers.
+ :param subscribersPerPublisherCount: the number of subscribers for each
+ publisher.
+ """
- The global target Nextcloud URL and credentials need to be set first.
+ global _publishersCount, _subscribersPerPublisherCount
+ _publishersCount = publishersCount
+ _subscribersPerPublisherCount = subscribersPerPublisherCount
- If global token, media or publishers and subscribers count were set they
- will be applied to the siege.
+ def startSiege():
+ """
+ Starts a siege.
- Note that changing any of those values later will have no effect on a
- running siege, the updated value will be used only on sieges started after
- they were changed.
+ The global target Nextcloud URL and credentials need to be set first.
- If there is already a running siege it will not be ended when a new one is
- started; the new one will run along the previous one.
- """
+ If global token, media or publishers and subscribers count were set they
+ will be applied to the siege.
- if not _isValidConfiguration():
- return
+ Note that changing any of those values later will have no effect on a
+ running siege, the updated value will be used only on sieges started
+ after they were changed.
- siege = Siege(_getBrowser(), _nextcloudUrl, _headless, _remoteSeleniumUrl)
+ If there is already a running siege it will not be ended when a new one
+ is started; the new one will run along the previous one.
+ """
- sieges.append(siege)
+ if not _isValidConfiguration():
+ return
- siege.setCredentials(_user, _appToken)
+ siege = Siege(_getBrowser(), _nextcloudUrl, _headless, _remoteSeleniumUrl)
- if _token:
- siege.setToken(_token)
+ sieges.append(siege)
- if _audio or _video:
- siege.startMedia(_audio, _video)
+ siege.setCredentials(_user, _appToken)
- if _publishersCount != None and _subscribersPerPublisherCount != None:
- siege.setPublishersAndSubscribersCount(_publishersCount, _subscribersPerPublisherCount)
+ if _token:
+ siege.setToken(_token)
- siege.siege()
+ if _audio or _video:
+ siege.startMedia(_audio, _video)
-def _getSiegeIndex(index = None):
- if not sieges:
- return -1
+ if _publishersCount != None and _subscribersPerPublisherCount != None:
+ siege.setPublishersAndSubscribersCount(_publishersCount, _subscribersPerPublisherCount)
- if index == None and len(sieges) > 1:
- print("Index needs to be specified")
- return -1
+ siege.siege()
- if index == None and len(sieges) == 1:
- index = 0
+ def _getSiegeIndex(index = None):
+ if not sieges:
+ return -1
- if index < 0 or index >= len(sieges):
- print("Index out of range")
- return -1
+ if index == None and len(sieges) > 1:
+ print("Index needs to be specified")
+ return -1
- return index
+ if index == None and len(sieges) == 1:
+ index = 0
-def checkPublishersConnections(index = None):
- """
- Checks the publisher connections of the siege with the given index.
+ if index < 0 or index >= len(sieges):
+ print("Index out of range")
+ return -1
- If a single siege is active the index does not need to be specified.
+ return index
- :param index: the index in :py:data:`sieges` of the siege to check its
- publisher connections.
- """
+ def checkPublishersConnections(index = None):
+ """
+ Checks the publisher connections of the siege with the given index.
- index = _getSiegeIndex(index)
- if index < 0:
- return
+ If a single siege is active the index does not need to be specified.
- sieges[index].checkPublishersConnections()
+ :param index: the index in :py:data:`sieges` of the siege to check its
+ publisher connections.
+ """
-def checkSubscribersConnections(index = None):
- """
- Checks the subscriber connections of the siege with the given index.
+ index = _getSiegeIndex(index)
+ if index < 0:
+ return
- If a single siege is active the index does not need to be specified.
+ sieges[index].checkPublishersConnections()
- :param index: the index in :py:data:`sieges` of the siege to check its
- subscriber connections.
- """
+ def checkSubscribersConnections(index = None):
+ """
+ Checks the subscriber connections of the siege with the given index.
- index = _getSiegeIndex(index)
- if index < 0:
- return
+ If a single siege is active the index does not need to be specified.
- sieges[index].checkSubscribersConnections()
+ :param index: the index in :py:data:`sieges` of the siege to check its
+ subscriber connections.
+ """
-def endSiege(index = None):
- """
- Ends the siege with the given index.
+ index = _getSiegeIndex(index)
+ if index < 0:
+ return
- If a single siege is active the index does not need to be specified.
+ sieges[index].checkSubscribersConnections()
- :param index: the index in :py:data:`sieges` of the siege to remove.
- """
+ def endSiege(index = None):
+ """
+ Ends the siege with the given index.
- index = _getSiegeIndex(index)
- if index < 0:
- return
+ If a single siege is active the index does not need to be specified.
+
+ :param index: the index in :py:data:`sieges` of the siege to remove.
+ """
- sieges[index].closeConnections()
- del sieges[index]
+ index = _getSiegeIndex(index)
+ if index < 0:
+ return
+
+ sieges[index].closeConnections()
+ del sieges[index]
+
+ globals()['setPublishersAndSubscribersCount'] = setPublishersAndSubscribersCount
+ globals()['startSiege'] = startSiege
+ globals()['checkPublishersConnections'] = checkPublishersConnections
+ globals()['checkSubscribersConnections'] = checkSubscribersConnections
+ globals()['endSiege'] = endSiege
def _deleteTalkbuchetInstancesOnExit():
@@ -1061,3 +1090,5 @@ atexit.register(_deleteTalkbuchetInstancesOnExit)
_findDefaultBrowser()
print('Full documentation can be shown by calling help(__name__)')
+
+switchToSiegeMode()