Skip to content

Realtime chat built with Go, Next & Typescript

Notifications You must be signed in to change notification settings

vandyahmad24/go-next-ts_chat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Realtime Chat

This is a realtime chat built with Go, Next, and Typescript.

The tutorial is available here

Hub Architecture

Initial Hub Architecture

First, we have the hub running on a separate goroutine which is the central place that manages different channels and contains a map of rooms. The hub has a Register and an Unregister channel to register/unregister clients, and a Broadcast channel that receives a message and broadcasts it out to all the other clients in the same room.

Client joins room

A room is initially empty. Only when a client hits the /ws/joinRoom endpoint, that will create a new client object in the room and it will be registered through the hub's Register channel.

Hub Architecture

Each client has a writeMessage and a readMessage method. readMessage reads the message through the client's websocket connection and send the message to the Broadcast channel in the hub, which will then broadcast the message out to every client in the same room. The writeMessage method in each of those clients will write the message to its websocket connection, which will be handled on the frontend side to display the messages accordingly.

About

Realtime chat built with Go, Next & Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 41.8%
  • Go 38.6%
  • CSS 15.6%
  • Makefile 2.1%
  • JavaScript 1.9%