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

@nhanaka/call

v2.0.2

Published

WebRTC call library with group calls, permissions, and realtime chat for Node.js, Next.js, and React

Readme

@nhanaka/call

Thư viện WebRTC call đơn giản và mạnh mẽ cho Node.js, Next.js và React. Hỗ trợ cuộc gọi thoại, video và group call với Socket.IO signaling.

✨ Tính năng

  • 🎥 Cuộc gọi video & thoại: Hỗ trợ cả video call và voice call 1-1
  • 👥 Group call: Cuộc gọi nhóm nhiều người với phân quyền 3 cấp
  • 💬 Chat realtime: Gửi tin nhắn trong cuộc gọi với validation
  • 🔐 Phân quyền: HOST, MODERATOR, MEMBER với quyền hạn khác nhau
  • ⚛️ React hooks: Tích hợp sẵn với React Context và hooks
  • 🔒 Bảo mật: Xác thực token và domain validation
  • 🌐 WebRTC: Kết nối peer-to-peer chất lượng cao
  • 📡 Socket.IO: Signaling server với rooms support
  • 🎛️ Tùy chỉnh: Callbacks linh hoạt cho mọi sự kiện
  • 📱 Responsive: Hoạt động tốt trên mọi thiết bị

📦 Cài đặt

npm install @nhanaka/call socket.io socket.io-client react

🚀 Quick Start

Server-side

import { createCallServer } from '@nhanaka/call';
import { Server } from 'socket.io';
import { createServer } from 'http';

const httpServer = createServer();
const io = new Server(httpServer, {
  cors: { origin: 'http://localhost:3000', credentials: true }
});

const callServer = createCallServer({
  io,
  callbacks: {
    onValidateToken: async (token) => token === 'valid-token',
    onCallInitiated: async (data) => {
      console.log('New call:', data);
      return true;
    },
    onCallMessage: async (message) => {
      await db.messages.create(message);
      return true;
    }
  }
});

httpServer.listen(3001);

Client-side (React)

import { CallProvider, useCall, CallType } from '@nhanaka/call';

function App() {
  return (
    <CallProvider config={{
      serverUrl: 'http://localhost:3001',
      userId: 'user-123',
      token: 'your-token'
    }}>
      <VideoCall />
    </CallProvider>
  );
}

function VideoCall() {
  const { initiateCall } = useCall();
  
  const handleCall = () => {
    initiateCall('user-456', CallType.VIDEO, { audio: true, video: true });
  };
  
  const handleGroupCall = () => {
    initiateCall(['user-2', 'user-3'], CallType.GROUP, { audio: true, video: true });
  };
  
  return <button onClick={handleCall}>Call</button>;
}

📞 Group Call

Hệ thống phân quyền 3 cấp

enum ParticipantLevel {
  HOST = 0,        // Chủ phòng - quyền cao nhất
  MODERATOR = 1,   // Người điều hành
  MEMBER = 2       // Thành viên thường
}

| Quyền | HOST | MODERATOR | MEMBER | |-------|------|-----------|--------| | Kick người khác | ✅ | ✅ (chỉ MEMBER) | ❌ | | Mute người khác | ✅ | ✅ (chỉ MEMBER) | ❌ | | Tắt camera người khác | ✅ | ✅ (chỉ MEMBER) | ❌ | | Mời người vào call | ✅ | ✅ | ❌ | | Gửi tin nhắn | ✅ | ✅ | ✅ |

Lưu ý về Force Toggle:

  • Khi admin tắt mic/camera với forced: true, user KHÔNG THỂ tự bật lại
  • User chỉ có thể bật lại khi admin unmute/unblock họ
  • Dùng cho trường hợp cần kiểm soát chặt chẽ (lớp học, hội nghị quan trọng)

Quản lý participants

// Kick participant
await client.kickParticipant(callId, 'user-3', 'Spam');

// Mute participant - user có thể tự bật lại
await client.toggleRemoteMedia(callId, 'user-3', 'audio', false);

// Force mute - user KHÔNG THỂ tự bật lại
await client.toggleRemoteMedia(callId, 'user-3', 'audio', false, true);

// Mời thêm người vào group call
await client.inviteParticipants(callId, ['user-5', 'user-6'], ParticipantLevel.MEMBER);

Chat trong cuộc gọi

// Gửi tin nhắn
await client.sendMessage(callId, 'Hello everyone!');

// Nhận tin nhắn
client.on('callMessage', (message) => {
  console.log(`: `);
});

🎯 API Reference

Server API

createCallServer(config)

  • io: Socket.IO server instance
  • callbacks: onValidateToken, onCallInitiated, onCallMessage, etc.

Methods:

  • getIO(): Lấy Socket.IO instance
  • getActiveCalls(): Danh sách cuộc gọi
  • getOnlineUsers(): Danh sách user online

Client API

createCallClient(config)

  • serverUrl: URL server
  • userId: ID user hiện tại
  • token: Token xác thực

Methods:

  • connect(): Kết nối server
  • initiateCall(to, type, constraints): Tạo cuộc gọi
  • joinCall(callId, constraints, level?): Join group call
  • sendMessage(callId, message): Gửi tin nhắn
  • kickParticipant(callId, userId, reason?): Kick participant
  • toggleRemoteMedia(callId, userId, type, enabled, forced?): Toggle media
  • inviteParticipants(callId, userIds, level?): Mời thêm người

React Hooks

useCall()

  • initiateCall(), acceptCall(), rejectCall(), endCall()
  • toggleAudio(), toggleVideo()
  • localStream, remoteStreams, incomingCall

useVideoElement(stream)

const videoRef = useVideoElement(localStream);
return <video ref={videoRef} autoPlay muted />;

📝 Types

enum CallType {
  VOICE = 'voice',
  VIDEO = 'video',
  GROUP = 'group'
}

interface Participant {
  userId: string;
  level: ParticipantLevel;
  isAudioEnabled: boolean;
  isVideoEnabled: boolean;
  isAudioForcedOff: boolean;
  isVideoForcedOff: boolean;
}

🎯 Use Cases

Online Class

const callId = await client.initiateCall(
  students,
  CallType.GROUP,
  { audio: true, video: true }
);

// Force mute all students
for (const student of students) {
  await client.toggleRemoteMedia(callId, student, 'audio', false, true);
}

// Cho phép 1 học sinh phát biểu
await client.toggleRemoteMedia(callId, studentId, 'audio', true);

📄 License

MIT

🙏 Credits

Built with ❤️ using WebRTC, Socket.IO, and TypeScript

Repository: https://github.com/fo-nhan/call