@4players/odin
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 (Recommended)
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(globalODIN) - 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
- Install the package and ensure audio is started after a user interaction (e.g. button click).
- Register event handlers before calling
room.join()so you receive events that occur while joining (e.g. remote peers already in the room). - Transmit audio only after
room.addAudioInput(audioInput). - 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 checkroom.datagramStatus(or listen toDatagramStatusChanged) and show its state. PasswaitForAudiotoroom.join()to wait longer, orfalseto 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.
X (formerly Twitter)
Tweet us at @ODIN4Players.
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.
