Skip to content

Instantly share code, notes, and snippets.

@voluntas
Last active April 24, 2020 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voluntas/885c9d7769f98693e8eacf70a6ef466f to your computer and use it in GitHub Desktop.
Save voluntas/885c9d7769f98693e8eacf70a6ef466f to your computer and use it in GitHub Desktop.
WebRTC Insertable Streams コトハジメ

WebRTC Insertable Streams コトハジメ

更新

2020-04-24

作者

@voluntas

バージョン

2020.1

URL

https://voluntas.github.io/

対象読者

  • W3C WebRTC API は理解している
  • WebRTC 利用プロトコルは一通り理解している
  • WebRTC SFU を仕事で利用している

概要

WebRTC Insertable Streams は Chrome M83 から利用できる RTP パケタライズ前のデータを JavaScript から直接いじれるようになる仕組みです。

何が嬉しいのか

  • RTP パケタライズ前ということもあり、分割を意識する必要はありません
  • RTP パケタライズ前の payload を自由にできるようになります
  • 音声データにモーションデータをつけたりできるようになります
  • E2EE が実現できるようになります

利用例

RTCPeerConnection を作るときに forceEncodedVideoInsertableStreams と forceEncodedAudioInsertableStreams を有効にする必要があります。

音声とモーションデータだけであれば、音声だけを有効にすれば大丈夫です。

let pc = new RTCPeerConnection({
    forceEncodedVideoInsertableStreams: true,
    forceEncodedAudioInsertableStreams: true
});

function transform(chunk, controller) {
    controller.enqueue(chunk);
};

let senderTransform = new TransformStream({
    transform: transform
});

senderStreams.readableStream, senderStreams.writableStream

readableStream.pipeThrough(transformStream)
              .pipeTo(writableStream);

資料

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment