Socket
Book a DemoInstallSign in
Socket

@rtco/peer

Package Overview
Dependencies
Maintainers
1
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@rtco/peer

artico peer library

0.3.6
latest
Source
npmnpm
Version published
Weekly downloads
82
100%
Maintainers
1
Weekly downloads
 
Created
Source

@rtco/peer

Artico peer library. Please refer to the documentation for more information.

Installation

npm install @rtco/peer

Usage

The following example show how to connect two peers and share audio/video or any data between them:

import Peer from "@rtco/peer";

const p1 = new Peer({ initiator: true });
const p2 = new Peer();

p1.on("signal", (data) => {
  // signal p2 somehow
  p2.signal(data);
});

p2.on("signal", (data) => {
  // signal p1 somehow
  p1.signal(data);
});

p1.on("connect", () => {
  // data channel is connected and ready to be used
  p1.send("Hey Peer 2, this is Peer 1!");
});

p2.on("data", (data) => {
  console.log("Received a message from Peer 1:", data);
});

p2.on("stream", (stream) => {
  console.log("Received new stream from Peer 1:", stream);
});

p1.on("replacetrack", (oldTrack, newTrack) => {
  console.log("Track replaced:", oldTrack.id, "->", newTrack.id);
});

// ...

navigator.mediaDevices
  .getUserMedia({
    video: true,
    audio: true,
  })
  .then((stream) => {
    // send stream to Peer 2
    p1.addStream(stream);

    // Example: Replace video track (e.g., switch camera)
    navigator.mediaDevices
      .getUserMedia({ video: { facingMode: "environment" }, audio: false })
      .then((newStream) => {
        const oldVideoTrack = stream.getVideoTracks()[0];
        const newVideoTrack = newStream.getVideoTracks()[0];

        // Replace the track
        p1.replaceTrack(oldVideoTrack, newVideoTrack);

        // Stop the old track
        oldVideoTrack.stop();
      })
      .catch(console.error);
  })
  .catch(console.error);

Keywords

artico

FAQs

Package last updated on 18 Aug 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.