@4players/odin 中文文档教程

发布于 3年前 浏览 61 项目主页 更新于 3年前

@4players/odin

npmnpmnpm

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 社区的一员。

加入我们的 Discord

Twitter

有一个快速的问题吗? 在 @4PlayersBiz 上给我们发推文,我们将帮助您解决任何问题。

Email

不使用 Discord 或 Twitter? 给我们发送电子邮件,我们会尽快回复您。

@4players/odin

npmnpmnpm

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.

Online Documentation

: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.

Join us on Discord

Twitter

Have a quick question? Tweet us at @4PlayersBiz and we’ll help you resolve any issues.

Email

Don’t use Discord or Twitter? Send us an email and we’ll get back to you as soon as possible.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文