ODIN Node.js SDK
Native Node.js bindings for the ODIN Voice SDK. Build powerful voice chat applications, recording bots, AI integrations, and real-time audio processing tools.
📖 Full Documentation | 💬 Discord Community | 🎮 4Players ODIN
Features
- 🎙️ Real-time Voice Chat - Low-latency voice communication
- 🔐 End-to-End Encryption - Built-in E2EE with OdinCipher
- 🤖 Bot Integration - Perfect for recording bots, AI assistants, and moderation tools
- 📊 Raw Audio Access - Get PCM audio data for processing, recording, or transcription
- 🌍 Proximity Chat - 3D positional audio support
- ⚡ High Performance - Native C++ bindings for maximum efficiency
- 📈 Diagnostics - Real-time connection and audio quality monitoring
Installation
Prerequisites
This SDK includes prebuilt binaries for:
- macOS (x86_64 and arm64)
- Windows (x86_64)
- Linux (x86_64)
For other platforms, you'll need a C++ compiler. See node-gyp requirements.
Quick Start
1. Get Your Access Key
Sign up at 4Players ODIN to get your free access key.
2. Basic Connection Example
Event Handlers
The SDK provides typed event handlers for easy integration:
Audio Recording Example
Record audio from peers to WAV files:
Sending Audio
The SDK provides two approaches for sending audio: a high-level API for convenience and a low-level API for full control.
High-Level API (Recommended)
The high-level API handles all the complexity automatically - media ID allocation, StartMedia RPC, and timing:
Low-Level API
For full control over audio transmission, use the low-level API:
See tests/sending-audio/ for complete examples of both APIs.
End-to-End Encryption (E2EE)
Enable encryption for secure voice communication:
⚠️ All participants in a room must use the same cipher password to communicate.
Verifying Peer Encryption Status
Proximity Chat (3D Audio)
Enable distance-based audio for spatial applications:
Connection Diagnostics
Monitor connection quality and troubleshoot issues:
API Reference
OdinClient
| Method | Description |
|---|---|
generateToken(accessKey, roomId, userId) | Generate a room token locally |
createRoom(token) | Create a room instance (recommended) |
createRoomWithToken(token) | Alias for createRoom |
OdinRoom
| Method | Description |
|---|---|
join(gateway, userData?) | Connect to the room |
close() | Disconnect from the room |
sendMessage(data, peerIds?) | Send a message to peers |
updatePosition(x, y, z) | Update 3D position |
setPositionScale(scale) | Set position scale factor |
setCipher(cipher) | Enable E2EE |
createAudioStream(sampleRate, channels) | Create audio output stream |
getConnectionId() | Get connection identifier |
getConnectionStats() | Get connection quality metrics |
getJitterStats(mediaId) | Get audio jitter metrics |
OdinRoom Properties
| Property | Type | Description |
|---|---|---|
ownPeerId | number | Your peer ID |
connected | boolean | Connection status |
availableMediaIds | number[] | Available media IDs for audio streams |
OdinMedia (Audio Stream)
| Method | Description |
|---|---|
setMediaId(mediaId) | Set server-assigned media ID |
close() | Release the stream |
sendAudioData(samples) | Send raw audio samples |
sendMP3(filePath) | Stream an MP3 file (convenience) |
sendWAV(filePath) | Stream a WAV file (convenience) |
sendBuffer(audioBuffer) | Stream AudioBuffer (convenience) |
OdinCipher (E2EE)
| Method | Description |
|---|---|
setPassword(password) | Set encryption password |
getPeerStatus(peerId) | Get peer's encryption status |
Events
| Event | Payload |
|---|---|
ConnectionStateChanged | { state, message } |
Joined | { roomId, ownPeerId, room, mediaIds } |
Left | { reason } |
PeerJoined | { peerId, userId, userData, peer } |
PeerLeft | { peerId } |
MediaStarted | { peerId, media } |
MediaStopped | { peerId, mediaId } |
MediaActivity | { peerId, mediaId, state } |
MessageReceived | { senderPeerId, message } |
AudioDataReceived | { peerId, mediaId, samples16, samples32 } |
Comparison with Web SDK
| Feature | Node.js SDK | Web SDK |
|---|---|---|
| Platform | Node.js (server) | Browser |
| Performance | Native C++ | WebRTC/JavaScript |
| Raw Audio Access | ✅ Full PCM data | ⚠️ Web Audio API |
| Use Cases | Bots, recording, AI | Client apps |
| E2EE | ✅ OdinCipher | ✅ OdinCipher |
The Node.js SDK is optimized for server-side use cases like:
- 🎙️ Audio recording bots
- 🤖 AI-powered voice assistants
- 📝 Speech-to-text transcription
- 🛡️ Content moderation
- 🔊 Audio processing pipelines
Examples
Check the tests/ folder for complete examples:
- connection-test - Basic connection, events, and diagnostics
- audio-recording - Recording peer audio to WAV files
- sending-audio - Sending audio with both high-level and low-level APIs
Troubleshooting
Build Errors
If you encounter build errors, ensure you have the required tools:
macOS Security Warnings
If you see "code signature not valid" errors:
Connection Issues
- Verify your access key is correct
- Check your network allows WebSocket connections
- Ensure the token hasn't expired
Development
Building for Other Platforms
This package includes prebuilt binaries for common platforms (macOS x64/arm64, Windows x64, Linux x64). If you need to build for a different platform or architecture, follow these steps:
1. Install Build Requirements
You'll need a C++ compiler toolchain:
2. Download ODIN SDK Libraries
Download the ODIN SDK libraries from the official releases:
- Download the appropriate archive for your platform from the release assets
- Extract the libraries to the correct location:
| Platform | Architecture | Target Directory |
|---|---|---|
| Linux | x64 | libs/bin/linux/x64/ |
| Linux | arm64 | libs/bin/linux/arm64/ |
| Linux | ia32 | libs/bin/linux/ia32/ |
| macOS | Universal | libs/bin/macos/universal/ |
| Windows | x64 | libs/bin/windows/x64/ |
| Windows | ia32 | libs/bin/windows/ia32/ |
The SDK archive contains these library files:
- Linux:
libodin_static.a,libodin.so,libodin_crypto_static.a,libodin_crypto.so - macOS:
libodin.dylib,libodin_crypto.dylib,libodin_static.a,libodin_crypto_static.a - Windows:
odin_static.lib,odin.dll,odin_crypto_static.lib,odin_crypto.dll
3. Build the Native Module
4. Verify the Build
Project Structure
Support
- 📖 Documentation: docs.4players.io
- 💬 Discord: Join our community
- 📧 Email: support@4players.io
- 🐛 Issues: GitHub Issues
License
MIT License - see LICENSE for details.
Made with ❤️ by 4Players GmbH