pub fn ws_message<T: CandidType + for<'a> Deserialize<'a>>(
    args: CanisterWsMessageArguments,
    _message_type: Option<T>
) -> CanisterWsMessageResult
Expand description

Handles the WS messages received either directly from the client or relayed by the WS Gateway.

The second argument is only needed to expose the type of the message on the canister Candid interface and get automatic types generation on the client side. This way, on the client you have the same types and you don’t have to care about serializing and deserializing the messages sent through IC WebSocket.

§Example

use ic_cdk_macros::*;
use candid::{CandidType};
use ic_websocket_cdk::{CanisterWsMessageArguments, CanisterWsMessageResult};
use serde::Deserialize;

#[derive(CandidType, Deserialize)]
struct MyMessage {
    some_field: String,
}

// method called by the WS Gateway to send a message of type GatewayMessage to the canister
#[update]
fn ws_message(
    args: CanisterWsMessageArguments,
    msg_type: Option<MyMessage>,
) -> CanisterWsMessageResult {
    ic_websocket_cdk::ws_message(args, msg_type)
}