-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow to mark commands as in progress in long polling | refs #37780
- Loading branch information
Showing
10 changed files
with
221 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,100 @@ | ||
#!/usr/bin/env python3 | ||
''' | ||
An example of Miris Manager client usage. | ||
This script is intended to control a recorder. | ||
Fake MediaCoder client for tests. | ||
''' | ||
import json | ||
import logging | ||
import os | ||
import sys | ||
import time | ||
from mm_client.client import MirisManagerClient | ||
|
||
logger = logging.getLogger('recorder_controller') | ||
|
||
|
||
class RecorderController(MirisManagerClient): | ||
DEFAULT_CONF = { | ||
'CAPABILITIES': ['record', 'shutdown'], | ||
'CAPABILITIES': ['record', 'network_record', 'web_control', 'screenshot'], | ||
} | ||
PROFILES = { | ||
'main': { | ||
'has_password': False, | ||
'can_live': False, | ||
'name': 'main', | ||
'label': 'Main', | ||
'type': 'recorder' | ||
} | ||
} | ||
PROFILES = {'main': {'has_password': False, 'can_live': False, 'name': 'main', 'label': 'Main', 'type': 'recorder'}} | ||
|
||
def handle_action(self, action, params): | ||
if action == 'SHUTDOWN': | ||
logger.info('Shutdown requested.') | ||
# TODO | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
elif action == 'REBOOT': | ||
logger.info('Reboot requested.') | ||
# TODO | ||
self.update_capabilities() | ||
self.set_status( | ||
status='ready', | ||
status_message='Ready to record', | ||
remaining_space='auto' | ||
) | ||
try: | ||
self.long_polling_loop() | ||
except KeyboardInterrupt: | ||
logger.info('KeyboardInterrupt received, stopping application.') | ||
|
||
elif action == 'START_RECORDING': | ||
def handle_action(self, uid, action, params): | ||
# See help on the handle action function: | ||
# https://github.com/UbiCastTeam/miris-manager-client/blob/main/mm_client/client.py#L184 | ||
# Possible actions: | ||
# https://mirismanager.ubicast.eu/static/skyreach/docs/api/values.html#system-command-actions | ||
if action == 'START_RECORDING': | ||
logger.info('Starting recording with params %s', params) | ||
self.set_status(status='recording', remaining_space='auto') | ||
# TODO | ||
self.set_status( | ||
status='initializing', | ||
status_message='', | ||
remaining_space='auto' | ||
) | ||
time.sleep(3) | ||
self.set_status( | ||
status='running', | ||
status_message='', | ||
status_info='{"playlist": "/videos/BigBuckBunny_320x180.m3u8"}', | ||
remaining_space='auto' | ||
) | ||
return 'DONE', '' | ||
|
||
elif action == 'STOP_RECORDING': | ||
logger.info('Stopping recording.') | ||
self.set_status(status='recorder_idle', remaining_space='auto') | ||
# TODO | ||
self.set_status( | ||
status='ready', | ||
status_message='', | ||
remaining_space='auto' | ||
) | ||
return 'DONE', '' | ||
|
||
elif action == 'LIST_PROFILES': | ||
logger.info('Returning list of profiles.') | ||
return json.dumps(self.PROFILES) | ||
return 'DONE', json.dumps(self.PROFILES) | ||
|
||
elif action == 'GET_SCREENSHOT': | ||
self.set_status(remaining_space='auto') # Send remaining space to Miris Manager | ||
self.set_screenshot( | ||
path='/var/lib/AccountsService/icons/%s' % (os.environ.get('USER') or 'root'), | ||
file_name='screen.png' | ||
) | ||
logger.info('Screenshot sent.') | ||
return 'DONE', '' | ||
|
||
elif action == 'UPGRADE': | ||
logger.info('Starting upgrade.') | ||
|
||
# Start your asynchronous upgrade process here then call: | ||
# self.set_command_status(uid, 'DONE', '') | ||
|
||
return 'IN_PROGRESS', '' | ||
|
||
else: | ||
raise Exception('Unsupported action: %s.' % action) | ||
raise NotImplementedError('Unsupported action: %s.' % action) | ||
|
||
|
||
if __name__ == '__main__': | ||
local_conf = sys.argv[1] if len(sys.argv) > 1 else None | ||
client = RecorderController(local_conf) | ||
try: | ||
client.long_polling_loop() | ||
except KeyboardInterrupt: | ||
logger.info('KeyboardInterrupt received, stopping application.') | ||
RecorderController(local_conf) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.