Git Product home page Git Product logo

iamenochchirima / ic-websockets-chat-mo Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 2.0 1012 KB

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/

JavaScript 5.99% Motoko 20.16% CSS 1.47% TypeScript 70.96% HTML 1.41%
internet-computer motoko react typescript blockchain real-time-chat-app websockets

ic-websockets-chat-mo's Introduction

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.

ic-websockets-chat-mo's People

Contributors

iamenochchirima avatar ilbertt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.