Sunil Mohan Adapa 75f6abac1e
*: Make setup method part of App class for all apps
- Primary purpose is to complete the App API and allow for multiple apps to be
present in a module without a single clashing setup() method. Secondary
objective is to get rid of SetupHelper instance simple use App instance instead.

- This brings us closer to not needing to implement setup() method for some of
the typical apps.

- Remove default value None for old_version parameter.

  - A valid integer value is always passed to this call.

  - The value of None is undefined.

  - Simplifies the App API slightly.

- Drop setting 'pre', 'post' values to indicate the stage of setup for the App.

  - Simplifies the setup methods significantly. Eliminates a class of
  bugs (some of them seen earlier).

  - The UI can show a simple 'installing...' or progress spinner instead of
  individual stages.

  - There are currently many inconsistencies where many operations are not
  wrapped in helper.call() calls.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
2022-08-15 10:36:16 -04:00

97 lines
3.3 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""
FreedomBox app for janus.
"""
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from plinth import actions
from plinth import app as app_module
from plinth import frontpage, menu
from plinth.daemon import Daemon
from plinth.modules.apache.components import Webserver
from plinth.modules.backups.components import BackupRestore
from plinth.modules.coturn.components import TurnTimeLimitedConsumer
from plinth.modules.firewall.components import Firewall
from plinth.package import Packages
from plinth.utils import format_lazy
from . import manifest
_description = [
_('Janus is a lightweight WebRTC server.'),
_('A simple video conference room is included.'),
format_lazy(
_('<a href="{coturn_url}">Coturn</a> is required to '
'use Janus.'), coturn_url=reverse_lazy('coturn:index')),
]
app = None
class JanusApp(app_module.App):
"""FreedomBox app for janus."""
app_id = 'janus'
_version = 1
def __init__(self):
"""Create components for the app."""
super().__init__()
info = app_module.Info(self.app_id, self._version, name=_('Janus'),
icon_filename='janus',
short_description=_('Video Room'),
description=_description, manual_page='Janus',
clients=manifest.clients)
self.add(info)
menu_item = menu.Menu('menu-janus', info.name, info.short_description,
info.icon_filename, 'janus:index',
parent_url_name='apps')
self.add(menu_item)
shortcut = frontpage.Shortcut('shortcut-janus', info.name,
info.short_description,
info.icon_filename,
reverse_lazy('janus:room'),
clients=manifest.clients)
self.add(shortcut)
packages = Packages('packages-janus', [
'janus', 'libjs-bootbox', 'libjs-bootstrap', 'libjs-bootswatch',
'libjs-janus-gateway', 'libjs-jquery-blockui', 'libjs-spin.js',
'libjs-toastr', 'libjs-webrtc-adapter'
])
self.add(packages)
firewall = Firewall('firewall-janus', info.name,
ports=['http', 'https',
'janus-freedombox'], is_external=True)
self.add(firewall)
webserver = Webserver('webserver-janus', 'janus-freedombox')
self.add(webserver)
daemon = Daemon(
'daemon-janus', 'janus', listen_ports=[(8088, 'tcp4'),
(8088, 'tcp6'),
(8188, 'tcp4'),
(8188, 'tcp6')])
self.add(daemon)
turn = TurnTimeLimitedConsumer('turn-janus')
self.add(turn)
backup_restore = BackupRestore('backup-restore-janus',
**manifest.backup)
self.add(backup_restore)
def setup(self, old_version):
"""Install and configure the app."""
super().setup(old_version)
actions.superuser_run('janus', ['setup'])
self.enable()