-
Notifications
You must be signed in to change notification settings - Fork 892
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
[WIP] WebTorrent Support #353
Changes from 6 commits
6097ae4
10e4414
c6bdc63
353bf79
2e007a9
a482b14
32c0fe2
6ffc16f
236614c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,11 @@ | |
<include name="IDR_BRAVE_EXTENSON_EN_US_MESSAGES_JSON" file="brave_extension/_locales/en_US/messages.json" type="BINDATA" /> | ||
<include name="IDR_BRAVE_EXTENSON_BRAVE_SHIELDS_HTML" file="brave_extension/braveShieldsPanel.html" type="BINDATA" /> | ||
<include name="IDR_BRAVE_EXTENSON_BRAVELIZER_JS" file="brave_extension/bravelizer.css" type="BINDATA" /> | ||
|
||
<!-- Brave Webtorrent --> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see 88818ab - it handles both local and generated resources There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed by 32c0fe2 |
||
<include name="IDR_BRAVE_WEBTORRENT_BACKGROUND_JS" file="brave_webtorrent/brave_webtorrent_background.bundle.js" type="BINDATA" /> | ||
<include name="IDR_BRAVE_WEBTORRENT_HTML" file="brave_webtorrent/brave_webtorrent.html" type="BINDATA" /> | ||
<include name="IDR_BRAVE_WEBTORRENT_BUNDLE_JS" file="brave_webtorrent/brave_webtorrent.bundle.js" type="BINDATA" /> | ||
</includes> | ||
</release> | ||
</grit> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import("//tools/grit/grit_rule.gni") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should all move into There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed by 32c0fe2 |
||
|
||
action("brave_webtorrent") { | ||
script = "//brave/script/build-brave-webtorrent.py" | ||
inputs = [ | ||
"background.ts", | ||
"brave_webtorrent.tsx", | ||
] | ||
outputs = [ | ||
"$target_out_dir/brave_webtorrent_background.bundle.js", | ||
"$target_out_dir/brave_webtorrent.bundle.js", | ||
] | ||
gen_dir = rebase_path(root_gen_dir, "//") | ||
args = [ | ||
"--target_gen_dir=$gen_dir" | ||
] | ||
if (is_official_build) { | ||
args += [ | ||
"--production", | ||
] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { action } from 'typesafe-actions' | ||
|
||
// Constants | ||
import { types } from '../constants/tab_types' | ||
|
||
export const tabCreated = (tab: chrome.tabs.Tab) => action(types.TAB_CREATED, { | ||
tab | ||
}) | ||
|
||
export const tabUpdated = (tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => | ||
action(types.TAB_UPDATED, { | ||
tabId, changeInfo, tab | ||
}) | ||
|
||
export const tabRemoved = (tabId: number) => action(types.TAB_REMOVED, { | ||
tabId | ||
}) | ||
|
||
export const activeTabChanged = (tabId: number, windowId: number) => action(types.ACTIVE_TAB_CHANGED, { | ||
tabId, windowId | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { action } from 'typesafe-actions' | ||
import { Torrent } from 'webtorrent' | ||
|
||
// Constants | ||
import { types } from '../constants/webtorrent_types' | ||
|
||
export const progressUpdated = (torrent: Torrent) => action(types.WEBTORRENT_PROGRESS_UPDATED, { torrent }) | ||
export const infoUpdated = (torrent: Torrent) => action(types.WEBTORRENT_INFO_UPDATED, { torrent }) | ||
export const serverUpdated = (torrent: Torrent, serverURL: string) => | ||
action(types.WEBTORRENT_SERVER_UPDATED, { torrent, serverURL }) | ||
export const startTorrent = (torrentId: string, tabId: number) => action(types.WEBTORRENT_START_TORRENT, { torrentId, tabId }) | ||
export const stopDownload = (tabId: number) => action(types.WEBTORRENT_STOP_DOWNLOAD, { tabId }) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { action } from 'typesafe-actions' | ||
|
||
// Constants | ||
import { types } from '../constants/window_types' | ||
|
||
export const windowCreated = (window: chrome.windows.Window) => action(types.WINDOW_CREATED, { | ||
window | ||
}) | ||
|
||
export const windowRemoved = (windowId: number) => action(types.WINDOW_REMOVED, { | ||
windowId | ||
}) | ||
|
||
export const windowFocusChanged = (windowId: number) => action(types.WINDOW_FOCUS_CHANGED, { | ||
windowId | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { init } from './background/webtorrent' | ||
init() | ||
|
||
require('./background/store') | ||
require('./background/events/tabsEvents') | ||
require('./background/events/windowsEvents') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { bindActionCreators } from 'redux' | ||
import store from '../store' | ||
import * as tabActions from '../../actions/tab_actions' | ||
export default bindActionCreators(tabActions, store.dispatch) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { bindActionCreators } from 'redux' | ||
import store from '../store' | ||
import * as webtorrentActions from '../../actions/webtorrent_actions' | ||
export default bindActionCreators(webtorrentActions, store.dispatch) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { bindActionCreators } from 'redux' | ||
import store from '../store' | ||
import * as windowActions from '../../actions/window_actions' | ||
export default bindActionCreators(windowActions, store.dispatch) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import tabActions from '../actions/tabActions' | ||
|
||
chrome.tabs.onCreated.addListener((tab: chrome.tabs.Tab) => { | ||
tabActions.tabCreated(tab) | ||
}) | ||
|
||
chrome.tabs.onUpdated.addListener((tabId: number, changeInfo: chrome.tabs.TabChangeInfo, tab: chrome.tabs.Tab) => { | ||
tabActions.tabUpdated(tabId, changeInfo, tab) | ||
}) | ||
|
||
chrome.tabs.onRemoved.addListener((tabId: number, removeInfo: chrome.tabs.TabRemoveInfo) => { | ||
tabActions.tabRemoved(tabId) | ||
}) | ||
|
||
chrome.tabs.onActivated.addListener((activeInfo: chrome.tabs.TabActiveInfo) => { | ||
tabActions.activeTabChanged(activeInfo.tabId, activeInfo.windowId) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { Torrent } from 'webtorrent' | ||
import * as throttle from 'throttleit' | ||
|
||
import webtorrentActions from '../actions/webtorrentActions' | ||
import { createServer } from '../webtorrent' | ||
|
||
export const addTorrentEvents = (torrent: Torrent) => { | ||
torrent.on('done', () => { | ||
webtorrentActions.progressUpdated(torrent) | ||
}) | ||
torrent.on('infoHash', () => { | ||
console.log('infoHash event') | ||
webtorrentActions.infoUpdated(torrent) | ||
}) | ||
torrent.on('metadata', () => { | ||
console.log('metadata event') | ||
webtorrentActions.infoUpdated(torrent) | ||
}) | ||
torrent.on('download', throttle((bytes: number) => { | ||
webtorrentActions.progressUpdated(torrent) | ||
}, 1000)) | ||
torrent.on('upload', throttle((bytes: number) => { | ||
webtorrentActions.progressUpdated(torrent) | ||
}, 1000)) | ||
torrent.on('ready', () => { | ||
console.log('ready', torrent) | ||
createServer(torrent, (serverURL: string) => { | ||
webtorrentActions.serverUpdated(torrent, serverURL) | ||
}) | ||
}) | ||
torrent.on('warning', (e: Error | string) => { | ||
console.log('warning: ', torrent, e) | ||
}) | ||
torrent.on('error', (e: Error | string) => { | ||
console.log('error: ', torrent, e) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { Instance } from 'webtorrent' | ||
|
||
export const addWebtorrentEvents = (webtorrent: Instance) => { | ||
webtorrent.on('error', (e: Error | string) => { | ||
console.log('WebTorrent error: ', e) | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import windowActions from '../actions/windowActions' | ||
|
||
chrome.windows.onFocusChanged.addListener((windowId: number) => { | ||
windowActions.windowFocusChanged(windowId) | ||
}) | ||
|
||
chrome.windows.onCreated.addListener((window: chrome.windows.Window) => { | ||
windowActions.windowCreated(window) | ||
}) | ||
|
||
chrome.windows.onRemoved.addListener((windowId: number) => { | ||
windowActions.windowRemoved(windowId) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
import { combineReducers } from 'redux' | ||
|
||
// Utils | ||
import webtorrentReducer from './webtorrent_reducer' | ||
import { ApplicationState } from '../../constants/webtorrentState' | ||
|
||
export default combineReducers<ApplicationState>({ | ||
torrentsData: webtorrentReducer | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't be writing back into the source directory. Please see the wip sync branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we couldn't access these *.bundle.js files from the extension if it's in gen, so I'm still generating webpack output files into src, they're now under
components/brave_webtorrent/entension/out
.