Happenn
  • Introduction
  • System Architect
  • For Dev
    • AWS
      • Domain & CNAME
      • Rescale Instance
      • Request AWS Certificate
      • Generate Certificate with Certbot
      • S3
      • SSH & FTP
      • Auto Scaling
      • RDS MySQL
    • Digital Ocean
      • Virtual Host & Certificate
      • SSH & FTP
    • Server
      • Git
      • Setup the Server
    • Code
      • Laravel/Lumen
      • Vue.js
      • Webpack
      • JavaScript Library
        • Lodash
        • axios
        • Moment.js
      • Code Style Guide
      • Useful Tools
    • HAM Admin
      • Install locally
      • Deploy
    • Happenn API
      • Install locally
      • Install DB locally
      • Make DB changes
    • Happenn IO
      • Install locally
    • Happenn Virtual
      • Install locally
      • Folders and file structure
      • Deploy code
        • Happenn AWS
        • Delegia AWS
    • Happenn Event app
      • Deploy
      • Install locally
Powered by GitBook
On this page
  • Introduction
  • Node.js, Socket.IO, and Express
  • Socket Code
  • Force Emit Event via API
  • Emit Data
  1. For Dev

Happenn IO

Explain the structure and how the socket interact with other applications.

Introduction

This application handle real-time transfer data via web socket. This make something like Chat, Vote, and Poll can show and change the data in real-time instead of wait until the user refresh the page to update the data. In most case, only Happenn API will be the only application that request the emit data (tell the server to send specific data to the page that has an on(<event>) with the same event name and let the code handle the data). There are also some case which we let the client handle the socket directly, such as join room, leave room, and get the connection in the room.

Node.js, Socket.IO, and Express

Node.js - as we're using Socket.IO. It requires Node.js to function.

Socket.IO - A simple web socket library. Make the client and server transfer the data in real-time via ws/wss protocol.

Express - Node.js framework. We're using it for routing in general.

Socket Code

locate: src/socket.js

There are 3 main events that has specific code

  1. join-room - Use for when the user join something either access the page or enter the session room. This help for logging and get the number of connect in the room.

  2. leave-room - Use for when the user close the connection either from closing the browser/tab or internet connection not working. This also sending logging.

  3. emit-room-count - Use for staying in sync with the number of connection inside the room to be able to update the connection amount in real-time.

You can check the send log code at the top of the file via function sendLog.

Force Emit Event via API

locate: src/Routes/api/socket.js

Emit Data

POST https://io.happenn.com/socket

Request Body

Name
Type
Description

key

string

Secret key

event

string

Event name to emit the data to

data

string

JSON encode string.

PreviousMake DB changesNextInstall locally

Last updated 2 years ago