Skip to content

messaging

framewise_meet_client.messaging

MessageSender

Manages sending messages to the server.

Source code in framewise_meet_client/messaging.py
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
class MessageSender:
    """Manages sending messages to the server."""

    def __init__(self, connection):
        """Initialize the message sender.

        Args:
            connection: WebSocketConnection instance
        """
        self.connection = connection

    async def _send_message(self, message: Dict[str, Any]) -> None:
        """Send a message over the WebSocket connection.

        Args:
            message: Message data to send

        Raises:
            ConnectionError: If the connection is not established
        """
        if not self.connection or not self.connection.connected:
            raise ConnectionError("Not connected to server")

        try:
            await self.connection.send_json(message)
            logger.debug(f"Sent message: {json.dumps(message)[:100]}...")
        except Exception as e:
            logger.error(f"Error sending message: {str(e)}")
            raise ConnectionError(f"Failed to send message: {str(e)}")

    def send_generated_text(self, text: str, is_generation_end: bool = False, loop: asyncio.AbstractEventLoop = None) -> None:
        """Send generated text to the server.

        Args:
            text: The generated text
            is_generation_end: Whether this is the end of generation
            loop: Event loop to use for coroutine execution (uses current loop if None)
        """
        message = {
            "type": "generated_text",
            "content": {
                "text": text,
                "is_generation_end": is_generation_end
            }
        }

        if loop:
            asyncio.run_coroutine_threadsafe(self._send_message(message), loop)
        else:
            asyncio.create_task(self._send_message(message))

    def send_custom_ui_element(self, ui_type: str, data: Dict[str, Any], loop: asyncio.AbstractEventLoop = None) -> None:
        """Send a custom UI element to the server.

        Args:
            ui_type: Type of UI element (e.g., 'mcq_question')
            data: Element-specific data
            loop: Event loop to use for coroutine execution (uses current loop if None)
        """
        message = {
            "type": "custom_ui_element",
            "content": {
                "type": ui_type,
                "data": data
            }
        }

        if loop:
            asyncio.run_coroutine_threadsafe(self._send_message(message), loop)
        else:
            asyncio.create_task(self._send_message(message))

    def send_mcq_question(self, question_id: str, question: str, options: List[str], 
                         loop: asyncio.AbstractEventLoop = None) -> None:
        """Send an MCQ question as a custom UI element.

        Args:
            question_id: Unique identifier for the question
            question: The question text
            options: List of answer options
            loop: Event loop to use for coroutine execution (uses current loop if None)
        """
        data = {
            "id": question_id,
            "question": question,
            "options": options
        }
        self.send_custom_ui_element("mcq_question", data, loop)

    def send_notification(self, message: str, level: str = "info", duration: int = 8000,
                         loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
        """Send a notification to all users in the meeting.

        Args:
            message: The notification message to display
            level: The notification level (info, warning, error, success)
            duration: How long the notification should display (in milliseconds)
            loop: Event loop to run the coroutine in
        """
        data = {
            "message": message,
            "level": level,
            "duration": duration
        }

        self.send_custom_ui_element("notification_element", data, loop)

__init__(connection)

Initialize the message sender.

Parameters:

Name Type Description Default
connection

WebSocketConnection instance

required
Source code in framewise_meet_client/messaging.py
19
20
21
22
23
24
25
def __init__(self, connection):
    """Initialize the message sender.

    Args:
        connection: WebSocketConnection instance
    """
    self.connection = connection

_send_message(message) async

Send a message over the WebSocket connection.

Parameters:

Name Type Description Default
message Dict[str, Any]

Message data to send

required

Raises:

Type Description
ConnectionError

If the connection is not established

Source code in framewise_meet_client/messaging.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
async def _send_message(self, message: Dict[str, Any]) -> None:
    """Send a message over the WebSocket connection.

    Args:
        message: Message data to send

    Raises:
        ConnectionError: If the connection is not established
    """
    if not self.connection or not self.connection.connected:
        raise ConnectionError("Not connected to server")

    try:
        await self.connection.send_json(message)
        logger.debug(f"Sent message: {json.dumps(message)[:100]}...")
    except Exception as e:
        logger.error(f"Error sending message: {str(e)}")
        raise ConnectionError(f"Failed to send message: {str(e)}")

send_generated_text(text, is_generation_end=False, loop=None)

Send generated text to the server.

Parameters:

Name Type Description Default
text str

The generated text

required
is_generation_end bool

Whether this is the end of generation

False
loop AbstractEventLoop

Event loop to use for coroutine execution (uses current loop if None)

None
Source code in framewise_meet_client/messaging.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def send_generated_text(self, text: str, is_generation_end: bool = False, loop: asyncio.AbstractEventLoop = None) -> None:
    """Send generated text to the server.

    Args:
        text: The generated text
        is_generation_end: Whether this is the end of generation
        loop: Event loop to use for coroutine execution (uses current loop if None)
    """
    message = {
        "type": "generated_text",
        "content": {
            "text": text,
            "is_generation_end": is_generation_end
        }
    }

    if loop:
        asyncio.run_coroutine_threadsafe(self._send_message(message), loop)
    else:
        asyncio.create_task(self._send_message(message))

send_custom_ui_element(ui_type, data, loop=None)

Send a custom UI element to the server.

Parameters:

Name Type Description Default
ui_type str

Type of UI element (e.g., 'mcq_question')

required
data Dict[str, Any]

Element-specific data

required
loop AbstractEventLoop

Event loop to use for coroutine execution (uses current loop if None)

None
Source code in framewise_meet_client/messaging.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
def send_custom_ui_element(self, ui_type: str, data: Dict[str, Any], loop: asyncio.AbstractEventLoop = None) -> None:
    """Send a custom UI element to the server.

    Args:
        ui_type: Type of UI element (e.g., 'mcq_question')
        data: Element-specific data
        loop: Event loop to use for coroutine execution (uses current loop if None)
    """
    message = {
        "type": "custom_ui_element",
        "content": {
            "type": ui_type,
            "data": data
        }
    }

    if loop:
        asyncio.run_coroutine_threadsafe(self._send_message(message), loop)
    else:
        asyncio.create_task(self._send_message(message))

send_mcq_question(question_id, question, options, loop=None)

Send an MCQ question as a custom UI element.

Parameters:

Name Type Description Default
question_id str

Unique identifier for the question

required
question str

The question text

required
options List[str]

List of answer options

required
loop AbstractEventLoop

Event loop to use for coroutine execution (uses current loop if None)

None
Source code in framewise_meet_client/messaging.py
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def send_mcq_question(self, question_id: str, question: str, options: List[str], 
                     loop: asyncio.AbstractEventLoop = None) -> None:
    """Send an MCQ question as a custom UI element.

    Args:
        question_id: Unique identifier for the question
        question: The question text
        options: List of answer options
        loop: Event loop to use for coroutine execution (uses current loop if None)
    """
    data = {
        "id": question_id,
        "question": question,
        "options": options
    }
    self.send_custom_ui_element("mcq_question", data, loop)

send_notification(message, level='info', duration=8000, loop=None)

Send a notification to all users in the meeting.

Parameters:

Name Type Description Default
message str

The notification message to display

required
level str

The notification level (info, warning, error, success)

'info'
duration int

How long the notification should display (in milliseconds)

8000
loop Optional[AbstractEventLoop]

Event loop to run the coroutine in

None
Source code in framewise_meet_client/messaging.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
def send_notification(self, message: str, level: str = "info", duration: int = 8000,
                     loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
    """Send a notification to all users in the meeting.

    Args:
        message: The notification message to display
        level: The notification level (info, warning, error, success)
        duration: How long the notification should display (in milliseconds)
        loop: Event loop to run the coroutine in
    """
    data = {
        "message": message,
        "level": level,
        "duration": duration
    }

    self.send_custom_ui_element("notification_element", data, loop)