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)
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 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_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
object # for all other key, remove }) def load_conf(path): if path is None or path == '': config = config_schema.validate({}) else: config = parse_config(path, config_schema) for i in range(len(config['posters'])): if config['posters'][i]['post_type'] == 'http': config['posters'][i] = http_poster_schema.validate( config['posters'][i]) else: raise JanusCloudError( 'poster_type {} not support'.format( config['posters'][i]['post_type']), JANUS_ERROR_NOT_IMPLEMENTED) # check other configure option is valid or not # TODO return config if __name__ == '__main__': conf = config_schema.validate({}) import pprint pprint.pprint(conf)