aboutsummaryrefslogtreecommitdiffstats
path: root/src/features/settingsWS/index.js
blob: 7771421d657981383af0ab6d64bc075ea4332d1b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { reaction } from 'mobx';
import { SettingsWSStore } from './store';

const debug = require('debug')('Ferdi:feature:settingsWS');

export const settingsStore = new SettingsWSStore();

export default function initSettingsWebSocket(stores, actions) {
  const { features } = stores;

  // Toggle SettingsWebSocket feature
  reaction(
    () => (
      features.features.isSettingsWSEnabled
    ),
    (isEnabled) => {
      if (isEnabled) {
        debug('Initializing `settingsWS` feature');
        settingsStore.start(stores, actions);
      } else if (settingsStore) {
        debug('Disabling `settingsWS` feature');
        settingsStore.stop();
      }
    },
    { fireImmediately: true },
  );
}