Skip to content

Keyboard socket

Alvin Cheng edited this page Apr 23, 2023 · 3 revisions

Description

This is the keyboard socket, this socket will change the typing status of the user with the 'server-keyboard' event. For instance, if a user is typing this socket can change it to not typing. This socket will accept a 'room' argument which is the room of the user who is typing, a 'user' argument which is the user that is typing, a 'key' which is the API key, 'responseToken' which is the response token of the socket and finally, a 'mode' argument which is a start or stops value, needless to say, it's the status of the user typing. Also as I mentioned before, we are NOT using the default websockets, we are using the socket.io library for web sockets.

If you'd like to listen for if a user is typing just listen to the 'keyboard-MODE:room(ROOM)' event. If the 'EVENT' is 'start', then the user started typing and vice versa.

What is a response token??

A response token is a token to send a request to if an error occurs.

Example

const io = require("socket.io");

const socket = io("<URL>", { transports: ["websocket"] });

// Send to server
socket.emit(
  "server-keyboard",
  "<ROOM>",
  "<USER>",
  "<KEY>",
  "<TOKEN>",
  "<MODE>"
);

socket.on("keyboard-start:room(<ROOM>)", () => {
  /* This will run when a user in the same room types*/
});

socket.on("keyboard-stop:room(<ROOM>)", () => {
  /* This will run when a user in the same room stops typing*/
});
Clone this wiki locally