npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@shinyoshiaki/skyway-nodejs-sdk-sfu-bot

v1.6.3

Published

The official Next Generation JavaScript SDK for SkyWay

Downloads

6

Readme

SFU Client

SkyWay Core ライブラリ で SFU Bot を利用するためのライブラリです。

本ページを読む場合、事前に Core ライブラリの README を読むことをおすすめします。

インストール方法

npm i @skyway-sdk/sfu-bot

SFU Bot の仕組み

P2P Channel では、各 Person が通信相手すべてに対して映像/音声/データの配信を行います。そのため、 Person の数が多い場合、上りトラフィックの量と、クライアントの音声/映像エンコードにかかる処理負荷が大きくなります。

SFU Bot は、 各 Person から一本の上りトラフィックを受信し、他の Person に対して配信します。これにより、クライアントの負荷は軽減し、大規模な双方向通信が可能となります。

利用方法

プラグインの登録

Core ライブラリ にて SFU 機能を有効化するため、Plugin を Core ライブラリ に登録します。

import { SkyWayContext } from '@skyway-sdk/core';
import { SfuBotPlugin } from '@skyway-sdk/sfu-bot';

const context = await SkyWayContext.Create(tokenString);
const plugin = new SfuBotPlugin();
context.registerPlugin(plugin);

SFU Bot の呼び出し

Channel で SFU Bot を利用するため、対象の Channel 内に SFU Bot を作成します。

const context = await SkyWayContext.Create(tokenString);
const plugin = new SfuBotPlugin();
context.registerPlugin(plugin);

const channel = await Channel.FindOrCreate(context);
// SFU BotをChannel内に作成する。
const bot = await plugin.createBot(channel);

Publication の Forwarding

SFU Bot に Channel 上の Publication を Forwarding させます。

これにより、SFU Bot は、 Person から一本の上りトラフィックを受信し、他の Person に対してそれを配信します。

const person = await channel.join();

const stream = await MediaDevices.createCameraVideoStream();
const publication = await person.publish(stream);

// personのpublicationをSFU BotにForwardingさせる
const forwarding = await bot.startForwarding(publication, {
  maxSubscribers: 99,
});

Person は、 SFU Bot が Forwarding している Publication を Subscribe することで、SFU 経由で Stream を受け取ることができます。

maxSubscribers では Forwarding している Publication を Subscribe できる数の上限値を指定できます。指定しない場合、maxSubscribers には 10 がセットされます。maxSubscribers の最大値は 99 です。

SFU Bot が配信している Publication の識別方法

SFU Bot を利用する場合、Channel 上には Person が Publish した Publication と SFU Bot がその Publication を Forwarding している Publication の 2 種類の Publication が存在します。

SFU Bot 経由で配信されている Publication を識別するには、Publication の Publisher の SubType を確認することで識別できます。

channel.onStreamPublished.add(({ publication }) => {
  if (publication.publisher.subtype === 'sfu') {
    console.log('published by SFU');
    person.subscribe(publication.id);
  }
});

Simulcast 機能の利用方法

VideoStream を Publish する際に複数のエンコード設定を指定することで、受信側クライアントデバイスが通信品質に合わせて自動的に最適なエンコード設定の映像を受け取る機能を利用できます。

const video = await SkyWayStreamFactory.createCameraVideoStream();
const publication = await person.publish(video, {
  encodings: [
    // 複数のパラメータをセットする
    { maxBitrate: 10_000, scaleResolutionDownBy: 8 },
    { maxBitrate: 680_000, scaleResolutionDownBy: 1 },
  ],
});

const forwarding = await bot.startForwarding(publication);

受信する映像の品質を指定する

エンコード設定を行う際に ID を指定することで受信する映像品質の設定を指定できるようになります。

await localPerson.publish(stream, {
  encodings: [
    { maxBitrate: 2000_000, id: 'a' },
    { maxBitrate: 10_000, id: 'b' },
  ],
});

映像品質設定の選択方法は次の 2 種類が用意されています。

subscribe する際に映像品質設定を指定する

await localPerson.subscribe(publication.id, { preferredEncodingId: 'b' });

preferredEncodingIdに受信する映像品質設定の ID を指定することができます。 映像を受信開始した時点で指定された品質の映像が SFU から送信されます。

クライアント端末の通信帯域が輻輳を起こしている場合、高い品質の映像設定を指定していても SFU からは輻輳を解消するために低い品質の映像が送信されます。

subscribe した映像の映像品質設定を変更する

subscription.changePreferredEncoding(id);

Publication を subscribe して subscription を入手し、映像の受信を開始した後に任意のタイミングで受信する映像品質設定を変更することができます。

クライアント端末の通信帯域が輻輳を起こしている場合、高い品質の映像設定を指定しても SFU からは低い品質の映像が送信されます。