ic-websocket-cdk 0.1.1

IC Websocket Canister Development Kit
Documentation

ic-websocket-cdk-rs

This repository contains the Rust implementation of IC WebSocket CDK. For more information about IC WebSockets, see IC WebSocket Gateway.

⚠️ This library is still in development and is not ready for production use. Expect breaking changes.

Installation

You can install the library by running:

cargo add ic-websocket-cdk

Usage

Refer to the ic_websocket_example repository for an example of how to use the library.

Candid interface

In order for the frontend clients and the Gateway to work properly, the canister must expose some specific methods in its Candid interface, between the custom methods that you've implemented for your logic. A valid Candid interface for the canister is the following:

import "./ws_types.did";

service : {
  "ws_open" : (CanisterWsOpenArguments) -> (CanisterWsOpenResult);
  "ws_close" : (CanisterWsCloseArguments) -> (CanisterWsCloseResult);
  "ws_message" : (CanisterWsMessageArguments) -> (CanisterWsMessageResult);
  "ws_get_messages" : (CanisterWsGetMessagesArguments) -> (CanisterWsGetMessagesResult) query;
};

This snipped is copied from the service.example.did file and the types imported are defined in the ws_types.did file.

Development

The ic-websocket-cdk library implementation can be found in the src/ic-websocket-cdk folder.

Testing

There are two types of tests available:

  • Unit tests: tests for CDK functions, written in Rust.
  • Integration tests: for these tests a local IC replica is set up and the CDK is deployed to a test canister. Tests are written in Node.js and are available in the tests folder.

There's a script that runs all the tests together, taking care of setting up the replica and deploying the canister. To run the script, execute the following command:

./scripts/test_canister.sh

License

TODO: Add a license

Contributing

Feel free to open issues and pull requests.