tc-whip-whep
v1.0.1
Published
whip and whep client
Readme
使用方式
npm i tc-whip-whep导入
import { WHIPClient, WHEPClient } from "tc-whip-whep";whip使用案例
const whipMediaStream = await navigator.mediaDevices.getUserMedia({audio:true});
const pc = new RTCPeerConnection({ bundlePolicy: "max-bundle" });
for (const track of whipMediaStream.getTracks()) {
pc.addTrack(track);
}
const whipClient = new WHIPClient();
const url = "流媒体服务器URL";
const token = "流媒体服务器token";
await whipClient.publish(pc, url, token);whep使用案例
const pc = new RTCPeerConnection({ bundlePolicy: "max-bundle" });
pc.addTransceiver("audio", {direction: "recvonly"});
pc.ontrack = (event) =>{
whepAudio.srcObject = event.streams[0];
}
const whepClient = new WHEPClient();
const url = "流媒体服务器URL";
const token = "流媒体服务器token";
await whepClient.view(pc, url, token);
// 监听 ICE 连接状态变化
pc.oniceconnectionstatechange = () => {
if (pc.iceConnectionState === 'failed' || pc.iceConnectionState === 'disconnected') {
console.log("whepClient连接已断开...");
}
};