WebTorrent 는 Node.js 및 브라우저 의 스트리밍 토렌트 클라이언트입니다. 네, 맞습니다. 브라우저. 웹의 언어 인 JavaScript로 완전히 작성되었으므로 동일한 코드가 두 Runtimes에서 작동합니다.
Node.js 에서이 모듈은 TCP 및 UDP를 사용하여 다른 토런트 클라이언트와 대화하는 간단한 토런트 클라이언트입니다.
브라우저에서 WebTorrent는 피어 투 피어 전송에 WEBRTC (데이터 채널)를 사용합니다. 브라우저 플러그인, 확장자 또는 설치 없이 사용할 수 있습니다. JavaScript ™입니다. 참고 : WebTorrent는 브라우저에서 UDP/TCP 피어를 지원 하지 않습니다 .
BitTorrent 프로토콜을 사용하여 WebRTC를 통해 파일을 가져 오거나 Browserify 또는 WebPack을 사용하여 import WebTorrent from 'webtorrent' 위해 페이지에 webtorrent.min.js 스크립트를 포함시키기 만하면됩니다. 아래의 데모 앱 및 코드 예제를 참조하십시오.
WebRTC (웹에서 작동하는 유일한 P2P 전송)에 비해 Bittorrent가 작동하기 위해 프로토콜을 변경했습니다. 따라서 브라우저 기반 WebTorrent 클라이언트 또는 "웹 피어" 는 WebTorrent/WebRTC를 지원하는 다른 클라이언트에만 연결할 수 있습니다.
웹 피어에게 파일을 시드하려면 WebTorrent (예 : WebTorrent Desktop)을 지원하는 클라이언트를 사용하여 웹 피어, WebTorrent-Hybrid, Command Line 프로그램 또는 웹 사이트 instant.io에 연결할 수있는 친숙한 UI가있는 데스크톱 클라이언트 인 Desktop 클라이언트를 사용하십시오. Vuze 와 같은 기존의 토런트 클라이언트는 이미 WebTorrent 지원을 추가하여 일반 및 웹 피어에 연결할 수있었습니다. 우리는 다른 고객들이 따라갈 수 있기를 바랍니다.
<video> 태그 ( webm, mkv, mp4, ogv, mov, etc (AV1, H264, HEVC*, VP8, VP9, AAC, FLAC, MP3, OPUS, Vorbis, etc) import WebTorrent from 'webtorrent' 있는 노드 또는 브라우저에서 사용하기 위해 WebTorrent를 설치하려면 : 실행 :
npm install webtorrent webtorrent Command Line 프로그램을 설치하려면 실행하십시오.
npm install webtorrent-cli -gMac, Windows 또는 Linux 용 WebTorrent 데스크톱 응용 프로그램을 설치하려면 WebTorrent 데스크탑을 참조하십시오.
#webtorrent 의 Gitter 또는 Freenode에서 우리와 함께 개발을 돕거나 미친 과학 해커들과 어울리십시오 :)많은 사람들!
전체 API 문서를 읽으십시오.
WebTorrent는 개방형 웹 표준 (플러그인 없음, HTML5 및 WEBRTC)을 사용하여 브라우저에서 작동하는 최초의 BitTorrent 클라이언트입니다! 시작하기 쉽습니다!
import WebTorrent from 'webtorrent'
const client = new WebTorrent ( )
const magnetURI = '...'
client . add ( magnetURI , torrent => {
// Got torrent metadata!
console . log ( 'Client is downloading:' , torrent . infoHash )
for ( const file of torrent . files ) {
document . body . append ( file . name )
}
} ) import dragDrop from 'drag-drop'
import WebTorrent from 'webtorrent'
const client = new WebTorrent ( )
// When user drops files on the browser, create a new torrent and start seeding it!
dragDrop ( 'body' , files => {
client . seed ( files , torrent => {
console . log ( 'Client is seeding:' , torrent . infoHash )
} )
} )문서/get-started.md에는 더 많은 예가 있습니다.
WebTorrent는 노드 스타일 require ()를 사용하여 NPM에서 설치 한 브라우저 코드와로드 모듈을 구성 할 수있는 NPM 패키지 인 Browserify와 잘 작동합니다 (이전 예제에서 볼 수 있음).
WebTorrent는 다른 모듈 Bundler 인 WebPack 과도 작동합니다. 그러나 WebPack에는 WebTorrent에서 사용하는 WebPack Bundle Config에서 찾을 수있는 추가 구성이 필요합니다.
또는 import WebTorrent from 'webtorrent/dist/webtorrent.min.js' 를 통해 사전 구축 된 버전을 사용할 수 있고 웹 팩 구성을 건너 뛸 수 있습니다.
WebTorrent는 또한 window 객체에 WebTorrent 노출시키는 독립형 스크립트 ( webtorrent.min.js )로도 제공되므로 스크립트 태그만으로 사용할 수 있습니다.
< script type =' module ' >
import WebTorrent from 'webtorrent.min.js'
</ script >WebTorrent Script는 또한 사이트에 쉽게 포함시키기 위해 빠르고 신뢰할 수있는 CDN 인프라 (CloudFlare 및 MaxCDN)에서 호스팅됩니다.
< script type =' module ' >
import WebTorrent from 'https://esm.sh/webtorrent'
</ script > Chrome 앱에서 WebTorrent를 사용하려면 다음 스크립트를 포함 할 수 있습니다.
< script type =' module ' >
import WebTorrent from 'webtorrent.chromeapp.js'
</ script > chrome.sockets.udp 및 chrome.sockets.tcp 권한을 활성화하십시오!
WebTorrent는 또한 동일한 NPM 패키지를 사용하여 Node.js에서 작동합니다! 미친 과학입니다!
참고 : 일반 Bittorrent 피어 외에 "웹 피어"(브라우저)에 연결하려면 Node에 대한 WebRTC 지원이 포함 된 WebTorrent-Hybrid를 사용하십시오.
WebTorrent는 명령 줄 앱으로도 제공됩니다. 사용 방법은 다음과 같습니다.
$ npm install webtorrent-cli -g
$ webtorrent --help급류를 다운로드하려면 :
$ webtorrent magnet_uriAirPlay 또는 Chromecast 와 같은 장치로 급류를 스트리밍하려면 깃발을 전달하십시오.
$ webtorrent magnet_uri --airplay지원되는 스트리밍 옵션이 많이 있습니다.
--airplay Apple TV
--chromecast Chromecast
--mplayer MPlayer
--mpv MPV
--omx [jack] omx [default: hdmi]
--vlc VLC
--xbmc XBMC
--stdout standard out [implies --quiet]Magnet Uris 외에도 WebTorrent는 급류를 지정하는 여러 가지 방법을 지원합니다.
활성 개발의 대부분은 WebTorrent에서 사용하는 작은 NPM 패키지 내부에서 발생합니다.
"애플리케이션이 잘 완료되면, 이들은 실제로 쉽게 추상화 할 수없는 응용 분야에 따른 괄호 잔류 물 일뿐입니다. 모든 멋지고 재사용 가능한 구성 요소는 모두가 공동 작업을 위해 협력 할 수있는 Github 및 NPM으로 승화시킵니다." - "모듈 작성 방법"의 Subsack
이것들은 WebTorrent를 구성하는 주요 모듈입니다.
| 기준 치수 | 테스트 | 버전 | 설명 |
|---|---|---|---|
| WebTorrent | 토런트 클라이언트 (이 모듈) | ||
| Bittorrent-dht | 분산 된 해시 테이블 클라이언트 | ||
| Bittorrent-Peerid | 클라이언트 이름/버전을 식별합니다 | ||
| Bittorrent-Protocol | Bittorrent 프로토콜 스트림 | ||
| Bittorrent- 트래커 | BitTorrent 추적기 서버/클라이언트 | ||
| Bittorrent-LSD | Bittorrent 지역 서비스 발견 | ||
| 생성 토렌트 | .TORRENT 파일을 만듭니다 | ||
| 마그넷 오리 | 마그넷 우리스를 구문 분석합니다 | ||
| 구문 분석 | 토런트 식별자를 구문 분석합니다 | ||
| 토런트 중심 | DHT, 트래커 및 LSD를 통해 피어를 찾으십시오 | ||
| UT_METADATA | 자석 URIS 메타 데이터 (프로토콜 확장) | ||
| UT_PEX | 피어 디스커버리 (프로토콜 확장) |
노드 에서 DEBUG 환경 변수를 디버그하려는 모듈의 이름으로 설정하여 디버그 로그를 활성화하십시오 (예 : bittorrent-protocol 또는 * 모든 로그를 인쇄하려면).
DEBUG= * webtorrent브라우저 에서 개발자 콘솔에서이를 실행하여 디버그 로그를 활성화하십시오.
localStorage . setItem ( 'debug' , '*' )이것을 실행하여 비활성화합니다.
localStorage . removeItem ( 'debug' )MIT. 저작권 (C) Feross Aboukhadijeh 및 WebTorrent, LLC.