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

@pplink/media-infra-client

v0.1.27

Published

- https://github.com/pplink/mediasoup-client - It is a core package for communicating with [media-infra](https://github.com/pplink/media-infra) server using mediasoup. - It is forked from [versatica/mediasoup-client](https://github.com/versatica/mediasoup

Downloads

118

Readme

@pplink/mediasoup-client

Structure

MediaInfraClient

  • media-infra-client 외부에서 직접적으로 사용하도록 유도된 대표 클래스

MediaDevice

  • mediasoup-clientDevice 를 래핑
    • Device: 하나의 MR에 대한 RTP 연결을 담당
    • 현재는 한개의 MR과만 연결되고 한개의 Device만 생성함.

MediaSignalingService

  • MA와의 소켓 메시징 담당

ProduceManager

  • 송출중인 트랙을 관리
  • 네트워크가 끊기더라도 기억했다가 다시 송출
  • Pause, Resume, Close 등 한번 송출한 트랙에 대한 작업들을 하도록 노출되는 클래스

ConsumeManager

  • 수신중인 트랙을 관리
  • 네트워크가 끊기는 경우 파괴된 후 새롭게 만들어진다 (기존 인스턴스 사용 불가)
  • Pause, Resume을 통해 일시정지, 다시 수신가능

연결흐름

MIC 사용 시작하기

  1. 유저가 고객사 서비스(페이지콜)에 접속

  2. 고객사 서버에서 MA에 접속 요청 → MA는 인증 후 토큰 발급. 발급된 토큰 정보는 Session 테이블에 3일동안 저장, 이후 만료됨

  3. 고객사 클라이언트에서 이 토큰을 넣어 MIC 사용

    // 2. PCA Server
    const { url, token } = await fetch("https://media.pplink.io/v1/api/connect");
    return {
      statusCode: 200,
      body: { url, token }
    };
    
    // 3. PCA Client
    const { url, token } = await fetch("https://pagecall.io/connect");
    const mic = new MediaInfraClient(url, token);

MIC 생성 직후 준비작업

소켓 연결

  • 미디어는 UDP(RTP)로 교환되지만, 어디로 어떻게 보내야 하는지, 다른 어떤 미디어를 받아야 하는지에 대한 정보는 직접 구현한 시그널링으로 교환 해주어야 한다. (여기서는 WebSocket 이용)
    • RTP Capabilities 교환하고 결정된 내용을 바탕으로 transport 생성
    • MR이 클라이언트끼리 서로 produce, consume할 수 있는지 조율 → 거의 발생하지 않으나 browser에서 지원하는 코덱의 종류에 따라 실패할 수 있음
  • MA가 MR과 클라이언트 사이의 필요한 정보 교환을 중개해준다.
  • MIC가 생성되자마자 넣어준 URL, Token으로 소켓연결 요청을 보냄
  • MA는 토큰을 확인해 허가된 유저일 경우 연결을 맺고, 그렇지 않으면 끊어버림

RTP Capabilities 교환

  • RTP capabilities
    • 코덱, RTP Header Extension
      • 서버 또는 클라이언트가 받을 수 있는 코덱, extension이 무엇인지 명세된 정보이다.
  • RTP parameters
    • 코덱, RTP Header Extension, 인코딩, RTCP
      • 보내는 미디어의 코덱과 extension등이 어떻게 설정되어 있는지에 대한 정보이다.
    • RTP send parameters: Producer가 서버에 보내는 내용
    • RTP receive parameters: Consumer가 서버에게 받는 내용
  • 보내는 사람은 받는 사람의 RTP capabilities를 알아야 뭘 보내줄 지 정할 수 있음
    • MIC는 MR의 RTP cap을 알아야 어떻게 전송해야 하는지 결정할 수 있음
    • MR은 MIC의 RTP cap을 알아야 어떻게 전송해야 하는지 결정할 수 있음
  • RTP capabilties의 교환이 필요하다 → 연결이 되자마자 MR은 자신의 RTP capabilities를 알려주면서 MIC에게도 알려달라고 요청함

Produce and Consume

Produce

  • 미디어를 보내는 행위를 Produce라고 함
  • MIC.produceTrack 을 호출해 트랙 송출을 시작

Consume

  • 미디어를 받는 행위를 Consume이라고 함
  • 받을 준비가 되었다는 메시지를 보내야 Consume이 시작된다. MIC.listenTrack
  • MIC.listenTrack 함수에 콜백함수를 넣어 이후 생성되는 ConsumeManager를 subscribe 할 수 있음.

Record

  • produceTrack을 통해 생성된 ProduceManager에서 startRecord, stopRecord를 통해 녹화 시작, 중단 가능.