def _handle_trickle(self, request): trickle_params_schema = Schema({ Optional('candidate'): dict, Optional('candidates'): [dict], AutoDel(str): object # for all other key we don't care }) params = trickle_params_schema.validate(request.message) candidate = params.get('candidate') candidates = params.get('candidates') if candidate is None and candidates is None: raise JanusCloudError( 'Missing mandatory element (candidate|candidates)', JANUS_ERROR_MISSING_MANDATORY_ELEMENT) if candidate and candidates: raise JanusCloudError('Can\'t have both candidate and candidates', JANUS_ERROR_INVALID_JSON) # dispatch to plugin handle handle = self._get_plugin_handle(request) handle.handle_trickle(candidate=candidate, candidates=candidates) return create_janus_msg('ack', request.session_id, request.transaction)
class Request(object): request_schema = Schema({ "janus": StrRe(r"^\S+$"), "transaction": StrRe(r"^\S+$"), Optional("session_id"): IntVal(), Optional("handle_id"): IntVal(), Optional("apisecret"): StrVal(), DoNotCare(str): object # for all other key we don't care }) def __init__(self, transport_session, message): message = self.request_schema.validate(message) self.transport = transport_session self.message = message self.janus = message['janus'] self.transaction = message['transaction'] self.session_id = message.get('session_id', 0) self.handle_id = message.get('handle_id', 0) self.apisecret = message.get('apisecret', '')
def read_config(config_file): p2pcall_config_schema = Schema({ Optional("general"): Default({ Optional("user_db"): Default(StrVal(), default='memory'), AutoDel(str): object # for all other key we don't care }, default={}), DoNotCare(str): object # for all other key we don't care }) #print('config file:', config_file) if config_file is None or config_file == '': config = p2pcall_config_schema.validate({}) else: log.info('P2Pcall plugin loads the config file: {}'.format(os.path.abspath(config_file))) config = parse_config(config_file, p2pcall_config_schema) # check other configure option is valid or not return config
def read_config(config_file): videocall_config_schema = Schema({ Optional("general"): Default( { Optional("user_db"): Default(StrVal(), default='memory'), AutoDel(str): object # for all other key we don't care }, default={}), DoNotCare(str): object # for all other key we don't care }) #print('config file:', config_file) if config_file is None or config_file == '': config = videocall_config_schema.validate({}) else: config = parse_config(config_file, videocall_config_schema) # check other configure option is valid or not return config
def _handle_attach(self, request): session = self._get_session(request) attach_params_schema = Schema({ 'plugin': StrVal(max_len=64), Optional('opaque_id'): StrVal(max_len=64), AutoDel(str): object # for all other key we don't care }) params = attach_params_schema.validate(request.message) handle = session.attach_handle(**params) return create_janus_msg('success', request.session_id, request.transaction, data={'id': handle.handle_id})
def _handle_create(self, request): create_params_schema = Schema({ Optional('id'): IntVal(min=1, max=9007199254740992), AutoDel(str): object # for all other key we don't care }) params = create_params_schema.validate(request.message) session_id = params.get('id', 0) session = self._frontend_session_mgr.create_new_session( session_id, request.transport) return create_janus_msg('success', 0, request.transaction, data={'id': session.session_id})
def _handle_message(self, request): message_params_schema = Schema({ 'body': dict, Optional('jsep'): dict, AutoDel(str): object # for all other key we don't care }) params = message_params_schema.validate(request.message) # dispatch to plugin handle handle = self._get_plugin_handle(request) result, content = handle.handle_message(request.transaction, **params) if result == JANUS_PLUGIN_OK: if content is None or not isinstance(content, dict): raise JanusCloudError( "Plugin didn't provide any content for this synchronous response" if content is None else "Plugin returned an invalid JSON response", JANUS_ERROR_PLUGIN_MESSAGE) response = create_janus_msg('success', request.session_id, request.transaction, sender=request.handle_id) if handle.opaque_id: response['opaque_id'] = handle.opaque_id response['plugindata'] = { 'plugin': handle.plugin_package_name, 'data': content } elif result == JANUS_PLUGIN_OK_WAIT: response = create_janus_msg('ack', request.session_id, request.transaction) if content: response['hint'] = content else: raise JanusCloudError('Plugin returned a severe (unknown) error', JANUS_ERROR_PLUGIN_MESSAGE) return response
# -*- coding: utf-8 -*- from januscloud.common.error import JanusCloudError, JANUS_ERROR_NOT_IMPLEMENTED from januscloud.common.schema import Schema, StrVal, Default, AutoDel, Optional, BoolVal, IntVal, \ StrRe, EnumVal, Or, DoNotCare from januscloud.common.confparser import parse as parse_config import os config_schema = Schema({ Optional("general"): Default( { Optional("daemonize"): Default(BoolVal(), default=False), AutoDel(str): object # for all other key remove }, default={}), Optional("log"): Default( { Optional('log_to_stdout'): Default(BoolVal(), default=True), Optional('log_to_file'): Default(StrVal(), default=''), Optional('debug_level'): Default(EnumVal(['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']), default='DEBUG'), Optional('log_file_size'): Default(IntVal(), default=104857600), Optional('log_file_rotate'): Default(IntVal(), default=10), AutoDel(str): object # for all other key remove
JANUS_VIDEOCALL_API_SYNC_VERSION JANUS_VIDEOCALL_NAME = 'JANUS VideoCall plugin' JANUS_VIDEOCALL_AUTHOR = 'opensight.cn' JANUS_VIDEOCALL_PACKAGE = 'janus.plugin.videocall' JANUS_VIDEOCALL_API_BASE_PATH = '/plugins/videocall' INCOMMING_CALL_TIMEOUT = 10 username_schema = Schema({ 'username': StrRe('^\w{1,128}$'), DoNotCare(str): object # for all other key we don't care }) set_schema = Schema({ Optional('audio'): BoolVal(), Optional('video'): BoolVal(), Optional('bitrate'): IntVal(min=1), Optional('record'): BoolVal(), Optional('restart'): BoolVal(), Optional('filename'): StrVal(), Optional('substream'): IntVal(min=0, max=2), Optional('temporal'): IntVal(min=0, max=2), Optional('fallback'): IntVal(min=0), AutoDel(str): object # for all other key we must delete }) post_videocall_user_schema = Schema({ 'caller_username': StrRe('^\w{1, 128}$'), 'backend_server_url':
@get_view(route_name='backend_server_list') def get_backend_server_list(request): backend_server_manager = request.registry.backend_server_manager server_list = backend_server_manager.get_all_server_list() return server_list server_update_schema = Schema({ 'name': StrRe('^\S{1,64}$'), 'url': StrRe('^(ws|wss)://\S+$'), 'status': IntVal(values=(JANUS_SERVER_STATUS_NORMAL, JANUS_SERVER_STATUS_ABNORMAL, JANUS_SERVER_STATUS_MAINTENANCE)), Optional("session_timeout"): IntVal(min=0, max=86400), Optional("session_num"): IntVal(min=0, max=10000), Optional("handle_num"): IntVal(min=0, max=100000), Optional("location"): StrVal(min_len=0, max_len=64), Optional("isp"): StrVal(min_len=0, max_len=64), Optional("expire"): IntVal(min=0, max=86400), AutoDel(str): object # for all other key we must delete })
# -*- coding: utf-8 -*- from januscloud.common.schema import Schema, StrVal, Default, AutoDel, Optional, BoolVal, IntVal, \ StrRe, EnumVal, Or from januscloud.common.confparser import parse as parse_config from pkg_resources import Requirement, resource_filename import os config_schema = Schema({ Optional("general"): Default({ Optional("daemonize"): Default(BoolVal(), default=False), Optional("configs_folder"): Default(StrVal(), default=''), Optional("server_name"): Default(StrRe(r'^\S*$'), default=''), Optional("session_timeout"): Default(IntVal(min=0, max=86400), default=60), Optional("server_db"): Default(StrVal(), default='memory'), Optional("server_select"): Default(StrVal(), default='rr'), Optional('api_secret'): Default(StrVal(), default=''), AutoDel(str): object # for all other key we don't care }, default={}), Optional("log"): Default({ Optional('log_to_stdout'): Default(BoolVal(), default=True), Optional('log_to_file'): Default(StrVal(), default=''), Optional('debug_level'): Default(EnumVal(['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL']), default='DEBUG'), Optional('log_file_size'): Default(IntVal(), default=104857600), Optional('log_file_rotate'): Default(IntVal(), default=10), AutoDel(str): object # for all other key we don't care }, default={}), Optional("certificates"): Default({ Optional("cert_pem"): StrVal(), Optional("cert_key"): StrVal(), Optional("cert_pwd"): StrVal(),
# -*- coding: utf-8 -*- from januscloud.common.schema import Schema, StrVal, Default, AutoDel, Optional, BoolVal, IntVal, \ StrRe, EnumVal, Or from januscloud.common.confparser import parse as parse_config from pkg_resources import Requirement, resource_filename import os import logging log = logging.getLogger(__name__) config_schema = Schema({ Optional("general"): Default( { Optional("daemonize"): Default(BoolVal(), default=False), Optional("configs_folder"): Default(StrVal(), default=''), Optional("server_name"): Default(StrRe(r'^\S*$'), default=''), Optional("session_timeout"): Default(IntVal(min=0, max=86400), default=60), Optional("server_db"): Default(StrVal(), default='memory'), Optional("server_select"): Default(StrVal(), default='rr'), Optional('api_secret'): Default(StrVal(), default=''), AutoDel(str): object # for all other key we don't care