This repository contains the Motoko 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.
You can install the library using mops following these steps:
- first, install the dependencies (this step won't be necessary when the ic-websocket-cdk will be available on mops):
mops add [email protected] mops add [email protected] mops add [email protected] mops add [email protected]
- install the ic-websocket-cdk:
mops add https://github.com/omnia-network/ic-websocket-cdk-mo#<last-commit-hash-on-this-repo>
For example, a valid installation script is:
mops add [email protected]
mops add [email protected]
mops add [email protected]
mops add [email protected]
mops add https://github.com/omnia-network/ic-websocket-cdk-mo#1d3320626e3c476632fc46ebdb9b5402e6207999
The ic-websocket-cdk package will be available on mops soon.
TODO: Add usage instructions
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_register" : (CanisterWsRegisterArguments) -> (CanisterWsRegisterResult);
"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.
Note: dfx
should already generate the Candid interface for you, so you don't need to write it yourself.
The ic-websocket-cdk library implementation can be found in the src folder.
There are integration tests available: 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 the integration tests, taking care of installing the Node.js dependencies, setting up the replica and deploying the canister. To run the script, execute the following command:
./scripts/test_canister.sh
TODO: Add a license
Feel free to open issues and pull requests.