-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebRTC #16
Comments
WebRTC 学习资料 |
MediaStream 处理https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/setSinkId https://developer.mozilla.org/en-US/docs/Web/API/MediaDevices/getUserMedia 通过 https://developer.mozilla.org/en-US/docs/Web/API/MediaRecorder const recordedBlobs = [];
const mimeType = 'video/mp4;codecs=h264,aac';
const mediaRecorder = new MediaRecorder(window.stream, { mimeType });
mediaRecorder.onstop = (event) => {
const blob = new Blob(recordedBlobs, { type: 'video/webm' });
const url = window.URL.createObjectURL(blob);
// Do something
};
mediaRecorder.ondataavailable = (e) => {
e.data && e.data.size > 0 && recordedBlobs.push(e.data);
};
mediaRecorder.start(); https://developer.mozilla.org/en-US/docs/Web/API/MediaStreamTrack
|
WebRTC
获取音频和视频
MediaDevices.getUserMedia()
MediaDevices.getUserMedia()
会提示用户给予使用媒体输入的许可,媒体输入会产生一个 MediaStream,里面包含了请求的媒体类型的轨道。此流可以包含一个视频轨道(来自硬件或者虚拟视频源,比如相机、视频采集设备和屏幕共享服务等等)、一个音频轨道(同样来自硬件或虚拟音频源,比如麦克风、A/D 转换器等等),也可能是其它轨道类型。其中
audio
、audio
均为MediaTrackConstraints
,可以通过指定deviceId
来使用指定的设备。MediaDevices.enumerateDevices()
通过
enumerateDevices
就可获取到不同设备的基本信息。MediaDevices.getDisplayMedia()
navigator.mediaDevices.getDisplayMedia
和navigator.mediaDevices.getUserMedia
使用方法类似,返回一个窗口内容的MediaStream
。通过上述方方法获取到 媒体流,可以借助
canvas
来实现拍照/截屏:RTC 通信
使用补充库 Adapter.js 可以抹平浏览器之间的差异。
RTCPeerConnection
RTCPeerConnection
接口代表一个由本地计算机到远端的 WebRTC 连接。该接口提供了创建,保持,监控,关闭连接的方法的实现。iceServers
可以使用 https://github.com/DamonOehlman/freeice 来提供。RTCDataChannel
RTCDataChannel
接口代表在两者之间建立了一个双向数据通道的连接。与WebSocket
类似。https://developer.mozilla.org/en-US/docs/Web/API/RTCDataChannel
The text was updated successfully, but these errors were encountered: