IC WebSocket: Stable Release

New release!

Today we’re releasing new IC WebSocket versions that affect both the SDKs and the gateway.

New versions

SDKs:

Gateway:

What’s changed

SDKs

We suggest you to update all your SDKs to the latest version.

  • you can close the connection with the client from the canister using the newly introduced close CDK method:
    • Rust:
      ic_websocket_cdk::close(client_principal);
      
    • Motoko:
      await ws.close(client_principal);
      // or (but doesn't call the on_close callback):
      // await IcWebSocketCdk.close(ws_state, client_principal);
      
  • you don’t have to specify the keep alive timeout parameter anymore (if you were doing it)
    • Rust: the WsInitParams struct doesn’t have the keep_alive_timeout_ms field anymore.
    • Motoko: WsInitParams are now initialized with one argument less:
      - let params = IcWebSocketCdkTypes.WsInitParams(null, null, null);
      + let params = IcWebSocketCdkTypes.WsInitParams(null, null);
      
  • ws_send is deprecated, use send instead:
    • Rust:
      - ic_websocket_cdk::ws_send(client_principal, message_bytes);
      + ic_websocket_cdk::send(client_principal, message_bytes);
      
    • Motoko:
      - await IcWebSocketCdk.ws_send(ws_state, client_principal, msg_bytes)
      + await IcWebSocketCdk.send(ws_state, client_principal, msg_bytes)
      

You can also follow the updated tutorial for reference.

Gateway

  • fix: call ws_close when canister closes connection (even with an error)
4 Likes