JSPM

  • Created
  • Published
  • Downloads 2476
  • Score
    100M100P100Q113870F
  • License ISC

Integrate Cloudflare Calls into your PartyServer app

Package Exports

  • partytracks
  • partytracks/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (partytracks) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

partycalls 🎶

import { PartyTracks } from "partytracks";
import { of } from "rxjs";

const CALLS_APP_ID = "YOUR_APP_ID_HERE";
const CALLS_APP_TOKEN = "YOUR_APP_TOKEN_HERE";
const localVideo = document.querySelector("video.local-video");
const remoteVideo = document.querySelector("video.remote-video");

const webcamTrack = await navigator.mediaDevices
  .getUserMedia({ video: true })
  .then((ms) => ms.getVideoTracks()[0]);

const localMediaStream = new MediaStream();
localMediaStream.addTrack(webcamTrack);
localVideo.srcObject = localMediaStream;

const partyTracks = new PartyTracks({
  // NOTE: Do not talk directly to the Calls API in your front-end in prod.
  // You should run a proxy that will add the appropriate auth headers.
  apiBase: `https://rtc.live.cloudflare.com/v1/apps/${CALLS_APP_ID}`,
  headers: new Headers({ Authorization: `Bearer ${CALLS_APP_TOKEN}` })
});

const pushedTrackMetadata$ = partyTracks.push(of(webcamTrack));
const pulledTrack$ = partyTracks.pull(pushedTrackMetadata$);

pulledTrack$.subscribe((track) => {
  const remoteMediaStream = new MediaStream();
  remoteMediaStream.addTrack(track);
  remoteVideo.srcObject = remoteMediaStream;
});