我正在运行一个节点服务器,我想从使用WebTorrent(https://webtorrent.io/docs)的磁力链接中流式传输视频.当我运行它时,即使我已将变量设置为.mp4文件,看起来好像文件未被正确引用.
为了清楚起见,我在这个例子中添加了一个给定的torrentID(磁力链接),以消除我对express和URL可能遇到的任何问题.该磁铁链接导致下载MP4格式的音乐视频.
视频播放器正在显示,但没有播放视频.我假设这意味着我没有尝试访问正确的文件.如果您需要了解更多关于WebTorrent的信息,请访问https://webtorrent.io/docs
var fs = require("fs"),
http = require("http"),
url = require("url"),
path = require("path"),
request = require('request'),
host = '127.0.0.1',
port = 3000,
express = require("express"),
app = express(),
server = http.createServer(app),
WebTorrent = require('webtorrent'),
client = new WebTorrent();
app.get('/streamvid/:magLink', function(req, res){
//var torrentID = req.params.magLink;
var torrentID = 'magnet:?xt=urn:btih:84123E8B4E850A796403736E0CF02E409F0EF00B';
client.add(torrentID, function (torrent) {
var file = torrent.files[0]
file.name = 'movie.mp4';
if (req.url != "/movie.mp4") {
res.writeHead(200, { "Content-Type": "text/html" });
res.end('<video width="1024" height="768" controls> …Run Code Online (Sandbox Code Playgroud) 我想通过webtorrent使用p2p webrtc进行实时视频流.
https://github.com/feross/webtorrent
它可以显然流视频,但它可以作为输入网络摄像头和其他来源?
你会怎么做?
谢谢.
我正在开发使用WebTorrent(谷歌演员定制接收器应用https://webtorrent.io,https://github.com/feross/webtorrent)使用JavaScript(铬)SDK和谷歌演员发件人应用.
我的应用程序的想法是从Google Cast发送者向Google Cast接收器发送torrent id(类似磁铁URI magnet:?xt=urn:btih:6a9759bffd5c0af65319979fb7832189f4f3c35d或HTTP/HTTPS URL到*.torrent文件https://webtorrent.io/torrents/sintel.torrent),并使用Google Cast接收器中的WebTorrent显示媒体(视频或音频)来自洪流.
请注意,torrent ID不是媒体文件的直接URL.
现在我正在使用Google Cast命名空间和messageBus来发送和接收torrent ID.
WebTorrent API提供了两种显示媒体的方法:
file.appendTo:https://webtorrent.io/docs#-file-appendto-rootelem-function-callback-err-elem-file.renderTo:https://webtorrent.io/docs#-file-renderto-elem-function-callback-err-elem-这是我的接收器的代码:
<html>
<head>
<script src="https://www.gstatic.com/cast/sdk/libs/receiver/2.0.0/cast_receiver.js"></script>
<script src="https://cdn.jsdelivr.net/webtorrent/latest/webtorrent.min.js"></script>
</head>
<body>
<video autoplay id='media' />
<script>
window.mediaElement = document.getElementById('media');
window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
window.messageBus = window.castReceiverManager.getCastMessageBus('urn:x-cast:com.google.cast.sample.helloworld');
window.messageBus.onMessage = function(event) {
displayVideo(event.data);
// Inform all senders on the CastMessageBus of the incoming message event
// sender …Run Code Online (Sandbox Code Playgroud) 我在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) 我的目标是制作一个 Electron 应用程序,它将客户端的文件夹与服务器同步。为了更清楚地解释它:
简单地说,应用程序必须确保该客户端具有主机服务器文件夹的精确副本。
到目前为止,我是通过 wget -m 完成的,但是 wget 经常无法识别,某些文件已更改并给客户端留下过时的文件。
最近我听说了 zsync-windows 和 webtorrent npm 包,但我不确定哪种方法是正确的以及如何真正实现我的目标。谢谢你的帮助。
我正在尝试html在 Nodejs 中使用 WebTorrent为文件做种。我从 WebTorrent 收到回调,这表明客户端开始播种,但是当我在客户端复制粘贴哈希以下载文件时,什么也没发生。
这是我在服务器端的代码:
client.seed(file, function (torrent) {
debug('started seeding %s - %s', torrent.infoHash, torrent.files[0].name);
});
Run Code Online (Sandbox Code Playgroud)
有什么问题,我如何调试以查看发生了什么?
我想知道为什么我找不到支持的 webtorrent 跟踪器webtorrent-hybrid。我只是想设置一个自己的跟踪器,例如 openwebtorrent-www,但是该跟踪器在 github 上只有 html 代码(https://github.com/openwebtorrent/openwebtorrent-www)。有谁知道一些开源 webtorrent 跟踪器(我的意思不是 bittorrent)。
谢谢你!
//艾伦
webtorrent ×7
javascript ×2
node.js ×2
browserify ×1
chromecast ×1
electron ×1
google-cast ×1
html ×1
mp4 ×1
npm ×1
tracker ×1
webrtc ×1
zsync ×1