我想通过webtorrent使用p2p webrtc进行实时视频流.
https://github.com/feross/webtorrent
它可以显然流视频,但它可以作为输入网络摄像头和其他来源?
你会怎么做?
谢谢.
我在https://github.com/feross/webtorrent#usage中显示的示例有一些问题 我正在尝试在浏览器中使用该代码.所以我首先创建一个名为app.js的文件
app.js
var WebTorrent = require('webtorrent')
var concat = require('concat-stream')
var client = new WebTorrent()
console.log('Hi there');
client.download('magnet:?xt=urn:btih:XXXXXXXX', function (torrent) {
// Got torrent metadata!
console.log('Torrent info hash:', torrent.infoHash)
torrent.files.forEach(function (file) {
// Get the file data as a Buffer (Uint8Array typed array)
file.createReadStream().pipe(concat(function (buf) {
// Append a link to download the file
var a = document.createElement('a')
a.download = file.name
a.href = URL.createObjectURL(new Blob([ buf ]))
a.textContent = 'download ' + file.name
document.body.appendChild(a)
}))
})
}) …Run Code Online (Sandbox Code Playgroud)