Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def on_disconnect():
if not conn.opt.daemon:
conn.exit(1)
conn.emit = emit
self.sio.on("disconnect", on_disconnect)
self.sio.on("to_plugin_" + conn.secret, sio_plugin_message)
emit({"type": "initialized", "dedicatedThread": True})
logger.info("Plugin %s initialized", conn.opt.id)
def run_forever(self, conn):
"""Run forever."""
raise NotImplementedError
class Client(BaseClient):
"""Represent a sync socketio client."""
def __init__(self):
"""Set up client instance."""
super(Client, self).__init__()
self.queue = queue.Queue()
self.task_worker = task_worker
def run_forever(self, conn):
"""Run forever."""
self.task_worker(conn, self.queue, logger, conn.abort)
if method is None:
raise Exception(
"Callback function can only called once, "
"if you want to call a function for multiple times, "
"please make it as a plugin api function. "
"See https://imjoy.io/docs for more details."
)
args = conn.unwrap(job["args"], True)
result = method(*args)
if result is not None and inspect.isawaitable(result):
await result
except Exception: # pylint: disable=broad-except
logger.error("Error in method %s: %s", job["num"], traceback.format_exc())
class AsyncClient(BaseClient):
"""Represent an async socketio client."""
# pylint: disable=too-few-public-methods
def __init__(self, conn, opt):
"""Set up client instance."""
super().__init__(conn, opt)
self.loop = asyncio.get_event_loop()
self.janus_queue = janus.Queue(loop=self.loop)
self.queue = self.janus_queue.sync_q
def run_forever(self):
"""Run forever."""
workers = [
task_worker(self.conn, self.janus_queue.async_q, logger, self.conn.abort)
for i in range(10)
def __init__(self, id=None):
"""Set up client instance."""
self.id = id or str(uuid.uuid4())
self.sio = socketio.Client()
BaseClient._clients[self.id] = self
if method is None:
raise Exception(
"Callback function can only called once, "
"if you want to call a function for multiple times, "
"please make it as a plugin api function. "
"See https://imjoy.io/docs for more details."
)
args = conn.unwrap(job["args"], True)
result = method(*args)
if result is not None and inspect.isawaitable(result):
await result
except Exception: # pylint: disable=broad-except
logger.error("Error in method %s: %s", job["num"], traceback.format_exc())
class AsyncClient(BaseClient):
"""Represent an async socketio client."""
# pylint: disable=too-few-public-methods
def __init__(self, id=None):
"""Set up client instance."""
super().__init__(id)
self.loop = asyncio.get_event_loop()
self.janus_queue = janus.Queue(loop=self.loop)
self.queue = self.janus_queue.sync_q
self.task_worker = task_worker
def run_forever(self, conn):
"""Run forever."""
if self.loop.is_running():
def add_plugin(plugin_id, client_id):
opt = dotdict(id=plugin_id, secret="", work_dir="")
client = BaseClient.get_client(client_id)
p = PluginConnection(client, opt)
return p