Socket Authentication (WS)

Why WebSockets?

Because of the considerable need for real-time data transfer (eg. updated assignments in real-time) and the speed boost that fetching data can give (eg. fetching classmates individually), Disadus also offers a WebSocket (WS) API that allows for fast, real-time communication.

Caveats

  • WS connections must be made with a registered, verified user. (All WS requests are Authenticated)

  • WS Data will stream in, without a specific identifier.

Acquiring the Authentication Token

Visit the Basic Authentication page to learn how to get the auth token.

Basic Authentication (REST)

Connecting to the Server

Disadus uses Socket.io to handle Web Socket connections. Example of connecting to the server with TypeScript and then getting a user.

import { io, Socket } from 'socket.io-client'
const socket = io("https://api.disadus.app/", {
  auth: {
    token: `Bearer ${AuthToken}`,
  },
});

// Socket connected;

socket.emit("user.id","TET00"); // get user with id TET00

socket.on("userResponse",(data)=>{
    const { user, id } = data;
    console.log(user as );
    console.log(id as string)
)

Read more into getting user info by ID via WS

Get User Info By ID (WS)

Last updated

Was this helpful?