npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vuurrood-sockets

v2.2.20

Published

vuurrood sockets package for api

Readme

Install

yarn add vuurrood-sockets@latest

# OR

npm install vuurrood-sockets@latest

Basic usage

Initializing the socket server:

import type { Server } from 'http'
import { initSocketServer } from 'vuurrood-sockets'

const startServer = (): Promise<Server> => new Promise(async (resolve) => {
  const server = app.listen(config.PORT, async () => {
    await initSocketServer(server, '*')
    resolve(server)
  })
})

startServer()

Publishing to NPM

IMPORTANT: Do not forget to upgrade (major, minor, patch) version in package.json

yarn publish

Small examples

Example 1

interface IRoomClearInteraction {
  hostSocketId: string
  code: string
}

router.post('/clear-last-interaction', async (req, res, next) => {
  const body = req.body as IRoomClearInteraction

  if (!isSocketIdHost(body.hostSocketId, body.code)) {
    return res.status(403).json({})
  }

  const updatedRoom = removeInteractionFromRoom(body.code)

  if (!updatedRoom) {
    return res.sendStatus(404)
  }

  emitRoomUpdatedToHost(updatedRoom, 'roomUpdated')
  emitNewInteractionToRoom(updatedRoom, 'lastInteractionUpdated')

  res.sendStatus(201)
})

Example 2

interface IRoomCreateBody {
  hostSocketId: string
  code?: string
}

router.post('/create-room', async (req, res, next) => {
  try {
    const body = req.body as IRoomCreateBody
    let room

    if (body.code) {
      room = recoverRoom(body.hostSocketId, body.code)

      if (!isSocketIdHost(body.hostSocketId, body.code)) {
        return res.sendStatus(403)
      }

      emitRoomUpdatedToHost(room, 'roomUpdated')
      emitRoomUpdatedToAllParticipants(room, 'roomParticipantUpdated')
    } else {
      room = createRoom(body.hostSocketId)
      rooms.push(room)

      emitRoomUpdatedToHost(room, 'roomUpdated')
    }

    res.json({
      code: room.code
    })
  } catch (e) {
    res.status(500).json({
      error: e
    })
  }
})

Functions

Server

const initSocketServer: (server: HttpServer, origin: string) => Promise<Server>

Emitters

// Emits Room to Host
const emitRoomUpdatedToHost: (room: Room, eventName: string) => void

// Emits lastInteraction to Room
const emitNewInteractionToRoom: (room: Room, eventName: string) => void

// Emits Room to all participants
const emitRoomUpdatedToAllParticipants: (room: Room, eventName: string) => void

// Emits Room to specific participant
const emitRoomUpdatedToParticipant: (participant: RoomParticipant, room: Room, eventName: string) => void

// Emits lastInteraction to specific participant
const emitInteractionToParticipant: (participant: RoomParticipant, eventName: string, interaction: RoomInteraction) => void

// Emits interaction to random participant
const emitInteractionToRandomParticipant: (room: Room, eventName: string, interaction: RoomInteraction) => void

// Emits to whole Room
const emitHostDisconnected: (room: Room, eventName: string) => void
const emitHostReconnected: (room: Room, eventName: string) => void

Participants

// Adds RoomParticipant to room if Room is open, returns Room if updated or undefined if Room is not found
const addParticipantToRoom: (code: string, participant: RoomParticipant) => Room | undefined

// Removes RoomParticipant from Room, returns Room if updated or undefined if Room is not found
const removeParticipantFromRoom: (code: string, participantId: string) => Room | undefined

// Gets specific RoomParticipant by participantId or undefined if RoomParticipant is not found
const getParticipantFromRoomById: (code: string, participantId: any) => RoomParticipant | undefined

// Adds a new interaction to RoomParticipant and returns Room if updated or undefined if Room is not found
const participantAddInteraction: (code: string, participantId: string, interaction: NewRoomParticipantInteraction) => Room | undefined

// Sets RoomParticipant to connected and returns Room if updated or undefined if Room is not found
const setParticipantConnected: (code: string, participantId: string, socketId: string) => Room | undefined

// Sets RoomParticipant to disconnected and returns Room if updated or undefined if Room is not found
const setParticipantDisconnected: (code: string, participantId: string) => Room | undefined

// Creates and returns a new RoomParticipant object 
const createRoomParticipant: (socketId: string, name?: string | undefined) => RoomParticipant

Interactions

// Creates and returns a new MESSAGE RoomInteraction object
const createMessageInteraction: (interactionData: string, interactionId?: string | undefined) => RoomInteraction

// Creates and returns a new SURVEY RoomInteraction object
const createSurveyInteraction: (interactionData: any, interactionId?: string | undefined) => RoomInteraction

// Creates and returns a new CHOICE RoomInteraction object
const createChoiceInteraction: (interactionData: any, interactionId?: string | undefined) => RoomInteraction

// Creates and returns a new RATING RoomInteraction object
const createRatingInteraction: (interactionData: any, interactionId?: string | undefined) => RoomInteraction

// Creates and returns a new RoomInteraction object
const createInteraction: (interactionType: InteractionType, interactionData: any, interactionId?: string | undefined) => RoomInteraction

// Adds RoomInteraction object to Room and returns Room if updated or undefined if Room is not found
const addLastInteractionToRoom: (code: string, interaction: RoomInteraction) => Room | undefined

// Removes RoomInteraction object from Room and returns Room if updated or undefined if Room is not found
const removeInteractionFromRoom: (code: string) => Room | undefined

// Gets all RoomInteractions from RoomParticipants by interactionId and returns RoomParticipantInteractions as array or undefined if no interactions with interactionId are found
const getInteractionsByInteractionId: (code: string, interactionId: string) => RoomParticipantInteraction[] | undefined

Connecting / Disconnecting

// Sets host to disconnected and returns Room if updated or undefined if Room is not found
const setHostDisconnected: (code: string) => Room | undefined

// Sets host to connected and returns Room if updated or undefined if Room is not found
const setHostConnected: (code: string, socketId: string) => Room | undefined

// If Host is disconnect, closes the Room and emits Room if updated to all RoomParticipants
// If RoomParticipant is disconnected, sets RoomParticipant to disconnected and emits Room if updated to Host 
const findDisconnectedUser: (socket: Socket) => void

// If Host connects/reconnects, opens the Room and emits Room if updated to all RoomParticipants
// If RoomParticipant connects/reconnects, sets RoomParticipant to connected and emits Room if updated to Host 
const findConnectedUser: (socket: Socket) => void

Room

// Generates unique code for Room and returns new code
const generateRoomCode: () => string

// Find and opens the Room, if no Room could be found a new Room is created with code
const recoverRoom: (hostSocketId: string, code: string, meta?: object | undefined, roomId?: string | undefined) => Room

// Creates and returns a new Room object
const createRoom: (hostSocketId: string, meta?: object | undefined, code?: string | undefined, roomId?: string | undefined) => Room

// Updates Room in global Room[] where all Rooms are stored in
// IMPORTANT: All functions updated a room do this automatically
const updateRoomInRoomArray: (room: Room) => void

// Returns the index of the Room in Room[]
const getRoomIndexByCode: (code: string) => number

// Returns the Room object or undefined if Room is not found
const getRoomByCode: (code: string) => Room | undefined

// Closes the Room and returns Room if updated or undefined if room is not found
const closeRoom: (code: string) => Room | undefined

// Opens the Room and returns Room if updated or undefined if room is not found
const openRoom: (code: string) => Room | undefined

// Finishes the Room and returns Room if updated or undefined if room is not found
const finishRoom: (code: string) => Room | undefined

// Resets the global Room[] back to empty Room[]
const resetRoomArray: () => void

Types

Room

interface Room {
  id: string;
  code: string;
  meta: object;
  hostSocketId: string;
  isHostConnected: boolean;
  status: RoomStatus;
  participants: RoomParticipant[];
  lastInteraction?: RoomInteraction;
  hasVoting: boolean;
  finished?: Date;
  created: Date;
}

enum RoomStatus {
  CLOSED = "CLOSED",
  OPEN = "OPEN",
  FINISHED = "FINISHED"
}

Participant

interface RoomParticipant {
  id: string;
  name?: string;
  socketId: string;
  isConnected: boolean;
  interactions: RoomParticipantInteraction[];
}

Interaction

interface RoomParticipantInteraction {
  id: string;
  interactionId: string;
  interactionType: InteractionType;
  interactionData: any;
}

interface NewRoomParticipantInteraction {
  interactionId: string;
  interactionType: InteractionType;
  interactionData: any;
}

interface RoomInteraction {
  interactionId: string;
  interactionType: InteractionType;
  interactionData: any;
}

enum InteractionType {
  CHOICE = "CHOICE",
  SURVEY = "SURVEY",
  RATING = "RATING",
  MESSAGE = "MESSAGE"
}