@4players/odin

中文文档
1.11.0发布于 2026/11/02ISCTypeScriptES Module近 30 天下载 3275

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

原始使用文档
文档目录14 节
  1. Installation
  2. NPM (Recommended)
  3. CDN (Browser)
  4. Features
  5. Advanced Audio Processing
  6. WebTransport (HTTP/3) support
  7. End-to-End Encryption (Cipher)
  8. Quick Start
  9. JavaScript / TypeScript Example
  10. Troubleshooting
  11. Discord
  12. X (formerly Twitter)
  13. Email
  14. Dependency maintenance

@4players/odin

npm npm npm

ODIN is a versatile cross-platform Software Development Kit (SDK) engineered to seamlessly integrate real-time voice chat into multiplayer games, applications, and websites. Regardless of whether you're employing a native application or your preferred web browser, ODIN simplifies the process of maintaining connections with your significant contacts. Through its intuitive interface and robust functionality, ODIN enhances interactive experiences, fostering real-time engagement and collaboration across various digital platforms.

You can choose between a managed cloud and a self-hosted solution. Let 4Players GmbH deal with the setup, administration and bandwidth costs or run our server software on your own infrastructure allowing you complete control and customization of your deployment environment.

Online Documentation · API Reference

Installation

npm install @4players/odin

Type definitions are included. The audio plugin (@4players/odin-plugin-web) is a dependency and is loaded automatically when needed (e.g. when calling ensurePlugin() or setOutputDevice()).

CDN (Browser)

For browser-only use you can load the SDK via CDN. Prefer pinning a specific version to avoid breaking changes:

  • IIFE: https://cdn.odin.4players.io/client/js/sdk/<version>/odin-sdk.js (global ODIN)
  • ESM: https://cdn.odin.4players.io/client/js/sdk/<version>/odin-sdk.esm.js

See the documentation for current version and usage.

Features

Advanced Audio Processing

ODIN enhances your audio experience during VoIP chats by offering a comprehensive set of filters beyond the basic audio processing features found in web browsers. These enhancements are activated by default, ensuring clear and interruption-free communication.

  • Voice Activity Detection
    When enabled, ODIN analyzes the audio input signal using a smart voice detection algorithm to determine the presence of speech. You can define both the probability required to start and stop transmitting.
  • Input Volume Gate
    When enabled, the volume gate measures the volume of the input audio signal, thus deciding when a user is speaking loud enough to transmit voice data. You can define both the root mean square power (dBFS) for when the gate should engage and disengage.

WebTransport (HTTP/3) support

We use the latest WebTransport API to transmit voice data in real time, with a seamless fallback to WebRTC for compatibility with older browsers.

End-to-End Encryption (Cipher)

ODIN supports end-to-end encryption (E2EE) through the use of a pluggable OdinCipher module. This enables you to secure all datagrams, messages and peer user data with a shared room password — without relying on the server as a trust anchor.

Quick Start

  1. Install the package and ensure audio is started after a user interaction (e.g. button click).
  2. Register event handlers before calling room.join() so you receive events that occur while joining (e.g. remote peers already in the room).
  3. Transmit audio only after room.addAudioInput(audioInput).
  4. Call setOutputDevice({}) to hear other peers (can be called anytime to set or switch the output device).

JavaScript / TypeScript Example

import {
  setOutputDevice,
  Room,
  DeviceManager,
} from '@4players/odin';

let room;
let audioInput;

async function joinRoom(token) {
  await setOutputDevice({});

  room = new Room();
  room.onJoined = (payload) => console.log('Joined', payload.room.id);
  room.onLeft = (payload) => console.log('Left', payload?.reason);
  room.onPeerJoined = (payload) => console.log('Peer joined', payload.peer.userId);
  room.onPeerLeft = (payload) => console.log('Peer left', payload.peer.userId);
  room.onDatagramStatusChanged = (payload) => console.log('Audio', payload.newState.status);

  // Waits up to 5 s for the audio path to open; see `waitForAudio`
  await room.join(token, { gateway: 'https://gateway.odin.4players.io' });

  audioInput = await DeviceManager.createAudioInput();
  await room.addAudioInput(audioInput);
}

async function leaveRoom() {
  if (audioInput && room) {
    room.removeAudioInput(audioInput);
    audioInput.close();
  }
  if (room) room.leave();
  room = undefined;
  audioInput = undefined;
}

// Call from a user gesture (e.g. button click).
joinRoom('__YOUR_TOKEN__');

Tokens must be generated server-side. See the documentation for authentication and gateway options.

Troubleshooting

  • No audio from peers: Ensure setOutputDevice({}) has been called to configure the output device.
  • Microphone not transmitting: Ensure room.addAudioInput(audioInput) is called after joining.
  • AudioContext not allowed: Start the flow from a user interaction (click/tap).
  • Joined, but audio does not connect: room.join() waits up to 5 s for the audio path and then resolves anyway, so check room.datagramStatus (or listen to DatagramStatusChanged) and show its state. Pass waitForAudio to room.join() to wait longer, or false to not wait at all.
  • Events not firing: Register all event handlers before calling room.join() so you receive events that occur while joining (e.g. remote peers already in the room).

Discord

Join our official Discord server to chat with us and become part of the 4Players ODIN community.

Join us on Discord

X (formerly Twitter)

Tweet us at @ODIN4Players.

Email

[email protected]

Dependency maintenance

Use npm 12 or newer when updating dependencies so both the ten-day release age and the @4players/* exception are enforced. Check npm --version and npm config get min-release-age before installing. Keep registry credentials in your user configuration or CI secrets, outside tracked policy files.

Select stable releases at least ten days old, including transitive dependencies. First-party @4players/* packages are exempt; their third-party dependencies are not. Keep TypeScript on 6.x and align shared versions across the ODIN repositories where peer requirements permit. Preserve and review lockfiles; existing locked versions are not evidence of release-age eligibility.

Install with npm install --min-release-age=10 --min-release-age-exclude='@4players/*'. Use npm ci for reproducible installs from the reviewed lockfile.

Each independently installed example or test application carries its own .npmrc, because npm project configuration is local to the installation root.

版本与发布记录

@4players/odin 共发布 130 个版本,首次发布于 2022/02/20;过去 12 个月发布了 32 个版本。

版本发布日期距今
1.11.0latest2026/11/026 天前
1.10.22026/10/1226 天前
1.10.12026/08/132 个月前
1.10.02026/07/273 个月前
1.9.12026/07/213 个月前
1.9.02026/07/213 个月前

其他发布通道:next → 1.0.0-alpha.52。

关于 @4players/odin 的常见问题

@4players/odin 是什么?

A cross-platform SDK enabling developers to integrate real-time VoIP chat technology into their projects

如何安装 @4players/odin?

在项目目录运行 npm install @4players/odin,或使用 pnpm add / yarn add / bun add。

@4players/odin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@4players/odin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@4players/odin 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.12。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@4players/odin 可以商用吗?

@4players/odin 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@4players/odin 的下载量有多少?

根据 npm 官方下载统计,@4players/odin 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,275 次,日均约 109 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@4players/odin 还在维护吗?

最新版本 1.11.0 发布于 2026/11/02(6 天前);至今共发布 130 个版本,其中过去 12 个月发布了 32 个;首次发布于 2022/02/20。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。