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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@muguilin/webrtc-player

v0.0.4

Published

webrtc、WebRTC、WebRTCPlayer、WebRTC播放器

Downloads

73

Readme

WebRTCPlayer 播放器

MIT License

Web前端,一个能在Web浏览器中,通过JavaScript实时播放WebRTC多媒体视频流的播放器 。


🏡 下载安装:

# 使用npm命令下载安装
$ npm i @muguilin/webrtc-player

# 使用yarn命令下载安装
$ yarn add @muguilin/webrtc-player

🚀 使用方法:

  • 获取或创建一个 HTMLVideoElement,并将其传递给 WebRTCPlayer类。
  • 调用 play() 方法,传入 WebRTC 流地址(要确保WebRTC 流是正常可用的)。
  • 如果需要停止播放,可以调用 stop() 方法。
  • 这样就可以轻松地在不同的Web浏览器页面中播放WebRTC 流。
  • 通过 JS Module(模块化)的方式导入使用

    <!-- ES6模块导入使用 -->
    <script type="module">
      // const WebRTCPlayer require('@muguilin/webrtc-player');
        
      import { WebRTCPlayer } from '@muguilin/webrtc-player';
      
      // WebRTCPlayer实例化
      const webrtc = new WebRTCPlayer(videoRef);
        
    </script>
  • 通过 <script src=""> 标签以 CDN 的形式引入使用

    <!-- 将@muguilin/webrtc-player的js文件下载后,在html文件中引入本地脚本 -->
    <script src="./js/webrtc-player.js"></script>
      
    <script>
      // 在浏览器控制台中打印WebRTCP类是否引入成功
      console.log(WebRTCP);
          
      const { WebRTCPlayer } = WebRTC;
      
      // WebRTCPlayer实例化
      const webrtc = new WebRTCPlayer(videoRef)
    </script>

🎬使用实例:

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>WebRTC播放器</title>
	<style>
		body {
			padding: 50px;
		}

		h1,
		section {
			text-align: center;
		}

		video {
			display: block;
			margin: 30px auto;
			width: 960px;
		}

		input {
			display: block;
			margin: 10px auto;
			padding: 10px;
			width: 938px;
		}

		button {
			padding: 5px 20px;
			font-size: 16px;
		}
	</style>
</head>

<body>
	<h1 class="h1">WebRTC播放器</h1>
	<hr>

	<section>
		<video id="videoRef" controls autoplay playsinline></video>
		<input type="text" id="url" value="" />
		<button id="playBtn">▶️ 开始播放</button>
		<button id="stopBtn">⏺️ 停止播放</button>
	</section>

	<script src="./main.umd.js"></script>
	<script type="module">

		// https://www.npmjs.com/package/@muguilin/webrtc-player
		// import { WebRTCPlayer } from '@muguilin/webrtc-player';

		console.log("WebRTC", WebRTC);
		const { WebRTCPlayer } = WebRTC;

		const videoRef = document.querySelector('#videoRef');
		const webrtc = new WebRTCPlayer(videoRef, {
			onPlay: (res) => {
				console.log('视频已开始播放', res);
			},
			onFirstFrame: () => {
				console.log('第一帧已渲染')
			},
			onStop: () => {
				console.log('视频已停止')
			},
			onError: (error) => {
				console.error('播放出错:', error)
				webrtc.destroy();
			},
			reconnect: (player) => {
				console.log('尝试重新连接...', player, player.reconnectCount)
				if (player.reconnectCount > 3) {
					player.destroy();
				}
			},
			onBuffering: () => {
				console.log('视频缓冲中...')
			}
		});

		// 实例属性/方法
		console.log('webrtc ', webrtc)

		// 播放
		playBtn['onclick'] = function () {
			const url = document.querySelector('#url').value;
			webrtc.play(url);
		};

		// 停止
		stopBtn['onclick'] = function () {
			webrtc.stop();
		};

	</script>
</body>

</html>