@4players/odin 中文文档教程
@4players/odin
4Players ODIN 是一个跨平台软件开发工具包 (SDK),使开发人员能够将实时聊天技术集成到多人游戏、应用程序和网站中。
:警告:重要通知:
请注意,ODIN 目前处于测试版 和功能会随着时间的推移而增加。
TypeScript Example
import { OdinClient } from '@4players/odin';
// Create a media stream for the default input device
const mediaStream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: true,
autoGainControl: false,
noiseSuppression: true,
sampleRate: 48000,
},
});
// Join a room in the ODIN server network using a room token obtained externally
const odinRoom = await OdinClient.joinRoom(token, mediaStream);
// Create a new media for ourselves and start capturing from the microphone
await odinRoom.createMedia().start();
// Start processing voice data of remote peers that were already in the room
odinRoom.remotePeers.forEach((peer) => {
peer.startMedias();
});
// Handle events for new peers joining the room
odinRoom.addEventListener('PeerJoined', (event) => {
console.log(`Peer ${event.payload.peer.id} joined`);
});
// Handle events for peers leaving the room
odinRoom.addEventListener('PeerLeft', (event) => {
console.log(`Peer ${event.payload.peer.id} left`);
});
// Handle events for medias added by remote peers (e.g. start processing voice data)
odinRoom.addEventListener('MediaStarted', (event) => {
event.payload.media.start();
});
// Handle events for medias removed by remote peers (e.g. stop processing voice data)
odinRoom.addEventListener('MediaStopped', (event) => {
event.payload.media.stop();
});
// Handle events for media activity (e.g. user starts/stops talking)
odinRoom.addEventListener('MediaActivity', (event) => {
console.log(`Peer ${event.payload.peer.id} ${event.payload.active ? 'started' : 'stopped'} talking on media ${event.payload.media.id}`);
});
Troubleshooting
通过下面列出的方法联系我们,以获得您的问题的答案并了解更多关于 ODIN 的信息。
Discord
加入我们的官方 Discord 服务器直接与我们聊天,成为 4Players ODIN 社区的一员。
有一个快速的问题吗? 在 @4PlayersBiz 上给我们发推文,我们将帮助您解决任何问题。
不使用 Discord 或 Twitter? 给我们发送电子邮件,我们会尽快回复您。
@4players/odin
4Players ODIN is a cross-platform software development kit (SDK) that enables developers to integrate real-time chat technology into multiplayer games, apps and websites.
:warning: Important Notice:
Please note that ODIN is currently in Beta and features are being added over time.
TypeScript Example
import { OdinClient } from '@4players/odin';
// Create a media stream for the default input device
const mediaStream = await navigator.mediaDevices.getUserMedia({
audio: {
echoCancellation: true,
autoGainControl: false,
noiseSuppression: true,
sampleRate: 48000,
},
});
// Join a room in the ODIN server network using a room token obtained externally
const odinRoom = await OdinClient.joinRoom(token, mediaStream);
// Create a new media for ourselves and start capturing from the microphone
await odinRoom.createMedia().start();
// Start processing voice data of remote peers that were already in the room
odinRoom.remotePeers.forEach((peer) => {
peer.startMedias();
});
// Handle events for new peers joining the room
odinRoom.addEventListener('PeerJoined', (event) => {
console.log(`Peer ${event.payload.peer.id} joined`);
});
// Handle events for peers leaving the room
odinRoom.addEventListener('PeerLeft', (event) => {
console.log(`Peer ${event.payload.peer.id} left`);
});
// Handle events for medias added by remote peers (e.g. start processing voice data)
odinRoom.addEventListener('MediaStarted', (event) => {
event.payload.media.start();
});
// Handle events for medias removed by remote peers (e.g. stop processing voice data)
odinRoom.addEventListener('MediaStopped', (event) => {
event.payload.media.stop();
});
// Handle events for media activity (e.g. user starts/stops talking)
odinRoom.addEventListener('MediaActivity', (event) => {
console.log(`Peer ${event.payload.peer.id} ${event.payload.active ? 'started' : 'stopped'} talking on media ${event.payload.media.id}`);
});
Troubleshooting
Contact us through the listed methods below to receive answers to your questions and learn more about ODIN.
Discord
Join our official Discord server to chat with us directly and become a part of the 4Players ODIN community.
Have a quick question? Tweet us at @4PlayersBiz and we’ll help you resolve any issues.
Don’t use Discord or Twitter? Send us an email and we’ll get back to you as soon as possible.