Commit 90ba1592 authored by Ben's avatar Ben Committed by Mark Harding
Browse files

Webtorrent service now disables by feature flag. #2237

parent 47aef7e7
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ import WebTorrent from 'webtorrent';
import { Storage } from '../../services/storage';
import isMobile from '../../helpers/is-mobile';
import isSafari from '../../helpers/is-safari';
import { FeaturesService } from '../../services/features.service';

export const MAX_CONNS = 55;

@@ -30,7 +31,10 @@ export class WebtorrentService {
  protected torrentRefs: { [index: string]: number } = {};
  protected torrentPurgeTimers: { [index: string]: any } = {};

  constructor(protected storage: Storage) {
  constructor(
    protected storage: Storage,
    protected featuresService: FeaturesService
  ) {
    if (
      !this.isBrowserSupported() &&
      !this.storage.get('webtorrent:disabled')
@@ -89,14 +93,15 @@ export class WebtorrentService {
    });
  }

  // Enable/Disable; Support

  isEnabled() {
    if (!window.Minds.user) return false;
    const enabled = window.Minds.user.p2p_media_enabled;

    return enabled && this.isBrowserSupported();
  }
  /**
   * Determines whether webtorrent is to be enabled for user
   * @returns { boolean } - true if webtorrent enabled, supported and user is opted in.
   */
  isEnabled = (): boolean =>
    window.Minds.user &&
    this.featuresService.has('webtorrent') &&
    window.Minds.user.p2p_media_enabled &&
    this.isBrowserSupported();

  setEnabled(enabled: boolean) {
    const current = this.isEnabled();
@@ -196,9 +201,9 @@ export class WebtorrentService {

  // DI

  static _(storage: Storage) {
    return new WebtorrentService(storage);
  static _(storage: Storage, featuresService: FeaturesService) {
    return new WebtorrentService(storage, featuresService);
  }

  static _deps: any[] = [Storage];
  static _deps: any[] = [Storage, FeaturesService];
}