是否可以仅使用 HTML(5) 和 JavaScript 来构建 Torrent 客户端?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4776112/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 14:02:25  来源:igfitidea点击:

Is it possible to build a torrent client using only HTML(5) and JavaScript?

javascripthtmlwebsocketbittorrent

提问by quilby

There isnt much more to add. Is it possible to build a torrent client using only HTML and JavaScript. You can not use things like Java, ActiveX, NaCl... If yes, please give a high level description.

没有更多要添加的了。是否可以仅使用 HTML 和 JavaScript 构建 Torrent 客户端。你不能使用 Java、ActiveX、NaCl 之类的东西……如果是,请给出高层次的描述。

I dont have much knowledge about front end dev, but I think websockets will be able to do the networking (is it possible to connect one client to another without having all data go through a server?). I know that you cant write files using JavaScript so I think the file thats being downloaded will either have to be saved completely in the memory, or the client will have to use one of the new APIs in HTML5 for storing content.

我对前端开发没有太多了解,但我认为 websockets 将能够进行网络连接(是否可以将一个客户端连接到另一个客户端而无需所有数据通过服务器?)。我知道您不能使用 JavaScript 编写文件,所以我认为正在下载的文件要么必须完全保存在内存中,要么客户端必须使用 HTML5 中的新 API 之一来存储内容。

采纳答案by Laurent VB

There's a recent implementation based on WebRTC that works in node and the browser: https://github.com/feross/webtorrent

最近有一个基于 WebRTC 的实现,可在节点和浏览器中运行:https: //github.com/feross/webtorrent

回答by quilby

No. It's not.

不,这不对。

This is because the WebSocket specification falls outside of HTML5 and JavaScript ;-) That being said, opening up the question to "using features supported natively in [progressive/upcoming] browsers" then...

这是因为 WebSocket 规范不属于 HTML5 和 JavaScript ;-) 话虽如此,但问题是“使用 [渐进式/即将推出] 浏览器中本机支持的功能”然后......

...still no:-)

...仍然没有:-)

This is because WebSocket requires a special handshake to setup with restrictions. It's not a free-for-all open-TCP-fest. The approach would require either

这是因为 WebSocket 需要特殊的握手来设置限制。这不是一场免费的开放 TCP 盛会。该方法需要

  1. clients to be modified to accept WebSocket requests (as well as dealing with any cross-site access issues)

  2. or, more realistically, a server to bounce through

  1. 要修改的客户端以接受 WebSocket 请求(以及处理任何跨站点访问问题)

  2. 或者,更现实地说,是一个可以通过的服务器

回答by Yahor

This is possible using Chrome Apps APIs: chrome.socketand chrome.fileSystem.

这可以使用Chrome 应用程序 API 实现chrome.socketchrome.fileSystem

There is at least one pure JavaScript implementation for Google Chrome: JSTorrent.

谷歌浏览器至少有一个纯 JavaScript 实现:JSTorrent

回答by kzahel

There's no good reason why this can't be done today. BitTorrent/uTorrent both have code to support websocket connections with binary frames. However, they are currently compiled without support (due to political/product reasons I think). I used to work at BitTorrent and another engineer (Arty) wrote the support. For a while it was really cool being able to download torrents onto iPads from mobile Safari. (saving directly to Google Drive funnily enough)

今天没有充分的理由不能做到这一点。BitTorrent/uTorrent 都有代码来支持带有二进制帧的 websocket 连接。但是,它们目前是在没有支持的情况下编译的(我认为是由于/产品原因)。我曾经在 BitTorrent 工作,另一位工程师 ( Arty) 编写了支持。有一段时间,能够从移动 Safari 下载种子到 iPad 上真的很酷。(有趣的是直接保存到 Google Drive)

HTTP trackers could be configured to send Access-Control-Allow-Origin headers.

HTTP 跟踪器可以配置为发送 Access-Control-Allow-Origin 标头。

Also the tracker announce protocol could use a bit in the "key" field to indicate that the client accepts websocket connections. Then a special argument like "typewant" could indicate that the announce response should only return clients who have sent that bit.

此外,跟踪器公告协议可以在“key”字段中使用一点来指示客户端接受 websocket 连接。然后像“typewant”这样的特殊参数可以指示宣布响应应该只返回发送该位的客户端。

The tracker protocol could also be extended similarly to support negotiation of WebRTC P2P DataChannel connections, so that connections could be made directly browser<->browser.

跟踪器协议也可以类似地扩展以支持 WebRTC P2P DataChannel 连接的协商,以便可以直接通过浏览器<->浏览器进行连接。

For now, we have the chrome.socket platform API, and jstorrent, a chrome packaged app (designed for ChromeOS mainly)

目前,我们有 chrome.socket 平台 API 和jstorrent,这是一个 chrome 封装的应用程序(主要为 ChromeOS 设计)

回答by CAFxX

You can't with WebSockets because those are strictly client-server. But the upcoming WebRTC standard, while being mostly targeted at audio/video conferencing, has a provisionfor generic client-client data transfers. If this provision makes it to the final version, then you'll have a viable way to implement generic peer-to-peer data transfers between browsers.

您不能使用 WebSockets,因为它们是严格的客户端-服务器。但是即将推出的 WebRTC 标准虽然主要针对音频/视频会议,但也提供了通用的客户端-客户端数据传输。如果此条款成为最终版本,那么您将有一种可行的方法来实现浏览器之间的通用点对点数据传输。

回答by L. Daniel Nordstrom

I'm late to the party, but since this question is still among the top on Google's results, I'll answer anyway.

我迟到了,但由于这个问题仍然是谷歌搜索结果的前列,我还是会回答。

You may write BitTorrent-related web apps or browser extensions with Btapp.js, which uses a Javascript interface provided by BitTorrent Torque. When you call the connect method, the user will be prompted to install BitTorrent Torque, that's all. Some cool stuff going on if you check out existing projects using it—streaming media, drag-and-drop sharing, etc.

您可以使用Btapp.js编写与 BitTorrent 相关的网络应用程序或浏览器扩展,它使用BitTorrent Torque提供的 Javascript 接口。当你调用connect方法时,会提示用户安装BitTorrent Torque,仅此而已。如果您查看使用它的现有项目,则会发生一些很酷的事情——流媒体、拖放共享等。

As for solutions without any dependency, the ones mentioned by Nick Russler still seem to be the only feasible options.

至于没有任何依赖的解决方案,Nick Russler 提到的那些似乎仍然是唯一可行的选择。