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

webgameapi

v1.0.0

Published

Eine TypeScript Library für Web-Games mit Room-Management, Chat und Channels

Readme

WebGameAPI

Eine TypeScript Library für Web-Games mit Room-Management, Chat und generischen Channels über Websockets.

Features

  • 🎮 Room-Management: Erstelle und verwalte Spielräume mit maximaler Spieleranzahl
  • 💬 Chat-System: Globaler und Room-basierter Chat
  • 📡 Channel-System: Generische Channels für beliebigen Datenaustausch
  • 👥 Player-Management: Verwaltung von Spielern mit benutzerdefinierten Daten
  • 🔌 WebSocket-Support: Basierend auf Socket.IO
  • 📝 TypeScript: Vollständig in TypeScript geschrieben mit Typen

Installation

Für die Library selbst

npm install
npm run build

In einem anderen Projekt verwenden

Es gibt mehrere Möglichkeiten, die Library in einem anderen Projekt zu verwenden:

Option 1: Lokale Verlinkung (empfohlen für Entwicklung)

# Im webgameapi Verzeichnis
npm link

# In deinem Projekt
npm link webgameapi

Option 2: Direkter Pfad-Import

In deiner package.json:

{
  "dependencies": {
    "webgameapi": "file:../pfad/zur/webgameapi"
  }
}

Option 3: Als npm Package (nach Veröffentlichung)

npm install webgameapi

Siehe USAGE.md für detaillierte Anleitung und example-project/ für ein vollständiges Beispiel.

Schnellstart

Server erstellen

import { GameServer } from 'webgameapi';

const server = new GameServer({
  port: 3000,
  cors: {
    origin: '*',
    credentials: false,
  },
  maxRooms: 100,
  maxPlayersPerRoom: 10,
});

// Custom Event Handler
server.on('game:move', (data, player) => {
  console.log(`Player ${player.id} bewegt sich:`, data);
});

server.start();

Client (Browser)

<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
<script>
  const socket = io('http://localhost:3000');

  // Player beitreten
  socket.emit('player:join', { 
    playerId: 'player1', 
    name: 'Spieler 1' 
  });

  // Room erstellen
  socket.emit('room:create', { 
    roomId: 'room1', 
    name: 'Mein Raum',
    maxPlayers: 10 
  });

  // Chat-Nachricht senden
  socket.emit('chat:send', { 
    message: 'Hallo!',
    roomId: 'room1' // optional
  });

  // Channel abonnieren
  socket.emit('channel:subscribe', { channel: 'game-updates' });
</script>

API Dokumentation

GameServer

Konfiguration

interface ServerConfig {
  port?: number;                    // Port für den Server (Standard: 3000)
  cors?: {                          // CORS-Konfiguration
    origin: string | string[];
    credentials?: boolean;
  };
  maxRooms?: number;                // Maximale Anzahl von Rooms
  maxPlayersPerRoom?: number;       // Maximale Spieler pro Room
}

Methoden

  • start(): Startet den Server
  • stop(): Stoppt den Server
  • on(event: string, handler: EventHandler): Registriert einen Event-Handler
  • off(event: string, handler: EventHandler): Entfernt einen Event-Handler
  • getRoomManager(): Gibt den RoomManager zurück
  • getChatManager(): Gibt den ChatManager zurück
  • getChannelManager(): Gibt den ChannelManager zurück
  • getPlayerManager(): Gibt den PlayerManager zurück

Socket Events (Client → Server)

Player Management

  • player:join - Player tritt bei
    { playerId: string, name?: string, data?: Record<string, any> }

Room Management

  • room:create - Erstellt einen neuen Room

    { roomId: string, name: string, maxPlayers?: number }
  • room:join - Tritt einem Room bei

    { roomId: string }
  • room:leave - Verlässt einen Room

    { roomId: string }
  • room:list - Listet alle Rooms auf

Chat

  • chat:send - Sendet eine Chat-Nachricht

    { message: string, roomId?: string }
  • chat:history - Ruft Chat-Verlauf ab

    { roomId?: string, limit?: number }

Channels

  • channel:subscribe - Abonniert einen Channel

    { channel: string }
  • channel:unsubscribe - Meldet sich von einem Channel ab

    { channel: string }
  • channel:broadcast - Sendet eine Nachricht an einen Channel

    { channel: string, data: any }

Custom Events

  • event - Sendet ein benutzerdefiniertes Event
    { event: string, payload: any }

Socket Events (Server → Client)

Player Events

  • player:joined - Bestätigung, dass Player beigetreten ist
  • player:connected - Anderer Player hat sich verbunden
  • player:disconnected - Player hat sich getrennt

Room Events

  • room:created - Room wurde erstellt
  • room:joined - Room wurde beigetreten
  • room:left - Room wurde verlassen
  • room:list - Liste aller Rooms
  • room:playerJoined - Spieler ist Room beigetreten
  • room:playerLeft - Spieler hat Room verlassen

Chat Events

  • chat:message - Neue Chat-Nachricht
  • chat:history - Chat-Verlauf

Channel Events

  • channel:subscribed - Channel wurde abonniert
  • channel:unsubscribed - Channel wurde abgemeldet
  • channel:message - Neue Channel-Nachricht

Error Events

  • error - Fehler aufgetreten
    { message: string }

Beispiele

Siehe examples/ Verzeichnis für vollständige Beispiele:

  • basic-server.ts - Einfacher Server-Setup
  • client-example.html - Vollständiges Client-Beispiel mit UI

Entwicklung

# TypeScript kompilieren
npm run build

# Watch-Modus für Entwicklung
npm run dev

# Server starten
npm start

Lizenz

MIT