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

realtime-player

v1.0.20

Published

A realtime player based on webrtc

Downloads

66

Readme

RealtimePlayer

A realtime player based on webrtc.

Getting Started

Demo

import RealtimePlayer from 'realtimeplayer';

const player = new RealtimePlayer({
  videoElement: document.querySelector('#video'),
  textHelperElement: document.querySelector('.video-input-helper'),
  wsAddress: 'ws://xxx',
  buildJoinRoomMessage: () => {
    return {
      "type":"joinRoom",
      "user_type":"web",
      "token":""
    }
  },
  buildMediaCandidateMessage: (candidate) => {
    return {
      "type": "candidate",
      "candidate": candidate
    }
  },
  buildMediaOfferMessage: (desc) => {
    return {
      "type": "offer",
      "description": desc
    }
  },
  getMessageType: (msg) => {
    const parsedMessage = JSON.parse(msg);
    const { type, ...rest } = parsedMessage;
    let payload = { ...rest };
    return { type, payload }
  },
  initPeerCase: (parsed) => {
    return parsed.type === 'roomStatus';
  },
  hooksOnSignalMessage: (parsedMessage) => {
    // hooks
  }
})

Options

videoElement HTMLVideoElement required

用来展示画面的video元素

textHelperElement HTMLInputElement required

用来辅助粘贴的text input元素

videoMode String

可选,视频流格式 webrtc or image,默认为webrtc;

imageElement HTMLImageElement

可选,图片流时用来展示图片的元素

wsAddress String required

websocket信令地址

buildMediaOfferMessage (desc: RTCSessionDescriptionInit) => any required

用来构造Media Offer信息的模版函数

buildMediaCandidateMessage (candidate: any) => any required

用来构造Media Candidate信息的模版函数

buildJoinRoomMessage () => any required

用来构造JoinRoom信息的模版函数

getMessageType () => (msg: string) => { type: string, payload: any, toPeerType: string } required

用于从信令信息中解析消息类型的函数

hooksOnSignalMessage (parsed: { type: string; payload: Record<string,any> }) => void required

信令服务器收到所有消息后的回调,可以在这里根据收到的信令消息自定义行为

initPeerCase (parsed: { type: string; payload: Record<string,any> }) => void

可选, 标志可以开始初始化PeerConnection的判断函数, 默认为判断message-type是否等于roomStuats

answerType string

可选, 标志是对等方Sdp的消息类型, 默认为answer

candidateType string

可选, 标志是对等方Candiadte的消息类型, 默认为candidate

keyFrame any

可选, 请求关键帧,如果需要可以设置

iceConfig any

可选, 用于配置PeerConnection的ICE配置

peerType Enum 'text'

可选,用于配置需要额外创建的PeerConenction类型,暂时只支持传入'text',默认只创建media类型

heartBeatMsg any

可选,用于配置信令心跳信息,默认{ type: "heartbeat" }

heartBeatInterval number

可选,用于配置信令心跳间隔,单位为ms,默认10000ms(即10s)

buildTextOfferMessage (desc: RTCSessionDescriptionInit) => any

可选,用来构造Text Offer信息的模版函数

buildTextCandidateMessage (candidate: any) => any

可选,用来构造Text Candidate信息的模版函数

isPC boolean

可选,用于指定当前投流终端是否为PC终端(与Mouse Move触发条件相关)

Methods

controller get Method

返回Video Controller的实例,获取控制流对象

emitter () => Emitter

返回Player的事件总线实例,组件会在部分情况(如: 重连,重连失败,重连成功)下发送事件信号, 用户可以自定义事件监听器

replay (force: boolean) => void

强制重新连接,失败会发送事件信号 Player.RetryFailed, 成功会发送事件信号 Player.RetrySuccess, 类型见dist/emitter.d.ts

streamerInstance () => WebrtcMediaStreamSimple|undefined

返回Player内部的webrtc-streamer实例(视频流Peer实例包装类,定义见dist/signal/webrtc-stream.d.ts)

signalInstance () => SignalSimple|undefined

返回Player内部的SignalpSimle实例(信令服务器实例包装类,定义见dist/signal/signal-simple.d.ts)

textInstance () => WebRtcTextSimple|undefined

默认为空, 如果指定了需要'text'的Peertype,则返回Player内部的webrtc-text实例(文本流Peer实例包装类,定义见dist/signal/webrtc-text.d.ts)

keyPress (code: AndroidKeycode) => void

模拟点击对端手机的某个功能按键键,code值见dist/const.d.ts

rotate () => void

模拟转屏信号,发送给对端手机

develop

to run local-phone demo
npm install
npm run build
npm run local-server
npm run start-local
open localhost:9090
to run udt-phone demo
npm install
npm run build
npm run start-udt
open localhost:9090
to run camera demo
npm install
npm run build
npm run local-signal
npm run start-camera
open localhost:9090

develop as package

npm install -g yalc
yalc publish

// yalc add xxxx in other project

release

npm run build
npm publish

Project Structure

title