iamenochchirima / ic-websockets-chat-mo

A real-time chat example on how to use IC WebSockets to send and receive messages between the frontend and a backend canister

Home Page:https://a3wil-byaaa-aaaal-qccgq-cai.icp0.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

IC WebSocket example - A simple realtime chat app

This is an example of how to use IC WebSockets to send and receive messages between the frontend (browser) and the backend canister demonstrated by a simple real-time group chat app, using motoko in the backend canister.

The example uses the IC WebSocket libraries:

The frontend connects to an IC WebSocket Gateway hosted on AWS under the gatewayv1.icws.io domain and maintained by the Omnia Network team. To know more about how the IC WebSocket Gateway works, please refer to the IC WebSocket Gateway repository.

Demo

A live demo is available at https://a3wil-byaaa-aaaal-qccgq-cai.icp0.io.

Understanding the example

Frontend

The frontend canister is simple a React app written in TypeScript.

Backend

The backend canister is a Motoko canister. The relevant code to understand how to use the ic-websocket-cdk-mo library is in the main.mo file.

Development

Running the project locally

If you want to test your project locally, follow these preparation steps:

  • make sure you are running an IC WebSocket Gateway locally. See the IC WebSocket Gateway repository for more details.
  • change the addresses of the local replica and the local IC WebSocket Gateway at the top of the ws.ts file.
  • change the GATEWAY_PRINCIPAL value in the main.mo file, using the principal that the IC WebSocket Gateway prints when it starts.

After completing the preparation steps, run the following commands:

# Install the mops packages
mops install

# Install the npm packages
npm install

# Starts the replica, running in the background
dfx start --clean --background

# Deploys your canisters to the replica and generates your candid interface
dfx deps deploy
dfx deploy

If you are making frontend changes, you can start a development server with

npm start

License

Licensed under the MIT License.

About

A real-time chat example on how to use IC WebSockets to send and receive messages between the frontend and a backend canister

https://a3wil-byaaa-aaaal-qccgq-cai.icp0.io/


Languages

Language:TypeScript 67.9%Language:Motoko 16.6%Language:JavaScript 12.4%Language:HTML 1.9%Language:CSS 1.2%