default settings, settings for webtorrent and public peer discovery

This commit is contained in:
Martti Malmi 2021-02-03 14:27:03 +02:00
parent 9323b79a87
commit 3da5677adf
4 changed files with 43 additions and 11 deletions

View File

@ -92,6 +92,7 @@ function getRandomPeers() {
}
var askForPeers = _.once(pub => {
if (!Session.settings.local.enablePublicPeerDiscovery) { return; }
_.defer(() => {
State.public.user(pub).get('peers').once().map().on(peer => {
if (peer && peer.url) {

View File

@ -13,6 +13,21 @@ let ourActivity;
let hasFollowers;
const follows = {};
const DEFAULT_SETTINGS = {
electron: {
openAtLogin: true,
minimizeOnClose: true
},
local: {
enableWebtorrent: !iris.util.isMobile,
enablePublicPeerDiscovery: true,
autoplayWebtorrent: true,
maxConnectedPeers: iris.util.isElectron ? 2 : 1
}
}
const settings = DEFAULT_SETTINGS;
function getFollowsFn(callback, k, maxDepth = 2, currentDepth = 1) {
k = k || key.pub;
@ -133,6 +148,12 @@ function login(k) {
if (shouldRefresh) {
location.reload();
}
State.electron && State.electron.get('settings').on(electron => {
settings.electron = electron;
});
State.local.get('settings').on(local => {
settings.local = local;
});
}
async function createChatLink() {
@ -206,4 +227,4 @@ function getFollows() {
return follows;
}
export default {init, getKey, getPubKey, getMyName, getMyProfilePhoto, getMyChatLink, createChatLink, removeChatLink, ourActivity, login, logOut, getFollows, loginAsNewUser };
export default {init, getKey, getPubKey, getMyName, getMyProfilePhoto, getMyChatLink, createChatLink, removeChatLink, ourActivity, login, logOut, getFollows, loginAsNewUser, DEFAULT_SETTINGS, settings };

View File

@ -56,8 +56,8 @@ class PublicMessage extends Message {
this.setState({replies: Object.keys(this.replies).length, sortedReplies });
});
});
if (msg.torrentId) {
!iris.util.isMobile && this.downloadWebtorrent(msg.torrentId);
if (msg.torrentId && Session.settings.local.enableWebtorrent) {
this.downloadWebtorrent(msg.torrentId);
}
});
}
@ -100,7 +100,8 @@ class PublicMessage extends Message {
// Stream the file in the browser
setTimeout(() => {
const id = '#' + this.getWebtorrentElementId();
file.appendTo(id, {autoplay: true, muted: true});
const autoplay = Session.settings.autoplayWebtorrent;
file.appendTo(id, {autoplay, muted: !autoplay});
$(id + ' video').attr('loop', true);
}, 0);
}

View File

@ -15,7 +15,7 @@ class Settings extends Component {
constructor() {
super();
this.eventListeners = [];
this.state = { settings: {}, maxConnectedPeers: iris.util.isElectron ? 2 : 1};
this.state = Session.DEFAULT_SETTINGS;
}
onProfilePhotoSet(src) {
@ -72,16 +72,17 @@ class Settings extends Component {
<small dangerouslySetInnerHTML=${{ __html:t('public_peer_info') }}></small>
</p>
</div>
<p><input type="checkbox" checked=${this.state.local.enablePublicPeerDiscovery} onChange=${e => State.local.get('settings').get('enablePublicPeerDiscovery').put(!this.state.local.enablePublicPeerDiscovery)} id="enablePublicPeerDiscovery"/><label for="enablePublicPeerDiscovery">Enable public peer discovery</label></p>
<h4>${t('maximum_number_of_peer_connections')}</h4>
<p>
<small>There's a bug that may cause high CPU and bandwidth usage when connecting to more than 1 peer. Working on it!</small>
</p>
<p>
<input type="number" value=${this.state.maxConnectedPeers} onChange=${e => State.local.get('settings').get('maxConnectedPeers').put(e.target.value || 0)}/>
<input type="number" value=${this.state.local.maxConnectedPeers} onChange=${e => State.local.get('settings').get('maxConnectedPeers').put(e.target.value || 0)}/>
</p>
${iris.util.isElectron ? html`
<h4>${t('your_public_address')}</h4>
<p>http://${this.state.settings.publicIp || '-'}:8767/gun</p>
<p>http://${this.state.electron.publicIp || '-'}:8767/gun</p>
`: ''}
<h4>Set up your own peer</h4>
<p>
@ -94,10 +95,14 @@ class Settings extends Component {
${iris.util.isElectron ? html`
<hr/>
<h3>Desktop</h3>
<p><input type="checkbox" checked=${this.state.settings.openAtLogin} onChange=${e => State.electron.get('settings').get('openAtLogin').put(!this.state.settings.openAtLogin)} id="openAtLogin"/><label for="openAtLogin">Open at login</label></p>
<p><input type="checkbox" checked=${this.state.settings.minimizeOnClose} onChange=${e => State.electron.get('settings').get('minimizeOnClose').put(!this.state.settings.minimizeOnClose)} id="minimizeOnClose"/><label for="minimizeOnClose">Minimize on close</label></p>
<p><input type="checkbox" checked=${this.state.electron.openAtLogin} onChange=${e => State.electron.get('settings').get('openAtLogin').put(!this.state.electron.openAtLogin)} id="openAtLogin"/><label for="openAtLogin">Open at login</label></p>
<p><input type="checkbox" checked=${this.state.electron.minimizeOnClose} onChange=${e => State.electron.get('settings').get('minimizeOnClose').put(!this.state.electron.minimizeOnClose)} id="minimizeOnClose"/><label for="minimizeOnClose">Minimize on close</label></p>
`: ''}
<hr/>
<h3>${t('webtorrent')}</h3>
<p><input type="checkbox" checked=${this.state.local.enableWebtorrent} onChange=${e => State.local.get('settings').get('enableWebtorrent').put(!this.state.local.enableWebtorrent)} id="enableWebtorrent"/><label for="enableWebtorrent">Enable webtorrent videos</label></p>
<p><input type="checkbox" checked=${this.state.local.autoplayWebtorrent} onChange=${e => State.local.get('settings').get('autoplayWebtorrent').put(!this.state.local.autoplayWebtorrent)} id="autoplayWebtorrent"/><label for="autoplayWebtorrent">Autoplay webtorrent videos</label></p>
<hr/>
<h3>${t('webrtc_connection_options')}</h3>
<p><small>${t('webrtc_info')}</small></p>
<p><textarea rows="4" id="rtc-config" placeholder="${t('webrtc_connection_options')}"></textarea></p>
@ -126,8 +131,12 @@ class Settings extends Component {
$('#rtc-config').val(JSON.stringify(getRTCConfig()));
});
State.electron && State.electron.get('settings').on(settings => this.setState({settings}));
State.local.get('settings').get('maxConnectedPeers').on(maxConnectedPeers => this.setState({maxConnectedPeers}));
State.electron && State.electron.get('settings').on(electron => {
this.setState({electron});
});
State.local.get('settings').on(local => {
this.setState({local})
});
}
componentWillUnmount() {