Source code for oursin.client

"""Client for communicating with the echo server"""
import socketio
import uuid
import asyncio

from . import camera
from . import volumes
from . import meshes
from . import dock

from vbl_aquarium.models.logging import *

[docs]class bcolors: WARNING = '\033[93m' FAIL = '\033[91m'
ID = str(uuid.uuid1())[:8] sio = socketio.Client()
[docs]@sio.event def connect(): print("(URN) connected to server") change_id(ID)
[docs]@sio.event def disconnect(): print("(URN) disconnected from server")
@sio.on('log') def message(data): print(data) out = Log.model_validate_json(data) print('(Renderer) ' + out.msg) @sio.on('log-warning') def message(data): out = LogWarning.model_validate_json(data) print('(Renderer) ' + bcolors.WARNING + out.msg)
[docs]@sio.on('log-error') def message(data): out = LogError.model_validate_json(data) print('(Renderer) ' + bcolors.FAIL + out.msg)
###### CALLBACKS #######
[docs]@sio.on('CameraImgMeta') def receive_camera_img_meta(data): camera.on_camera_img_meta(data)
[docs]@sio.on('CameraImg') def receive_camera_img(data): camera.on_camera_img(data)
[docs]@sio.on('VolumeClick') def receive_volume_click(data): volumes._volume_click(data)
[docs]@sio.on('NeuronCallback') def receive_neuron_callback(data): meshes._neuron_callback(data)
[docs]@sio.on('urchin-dock-callback') def receive_dock_callback(data): dock._save_callback(data)
[docs]@sio.on('urchin-loaded-callback') def urchin_loaded_callback(data): camera._on_loaded()
# Helper functions
[docs]def connected(): return sio.connected
[docs]def close(): """Disconnect from the echo server """ sio.disconnect()
[docs]def change_id(newID): """Change the ID used to connect to the echo server Parameters ---------- newID : string New ID to connect with """ sio.emit('ID',[newID,"send"]) print(f'Login sent with ID: {newID}, copy this ID into the renderer to connect.')