diff options
Diffstat (limited to 'src/features')
-rw-r--r-- | src/features/publishDebugInfo/index.js | 2 | ||||
-rwxr-xr-x | src/features/settingsWS/actions.ts | 13 | ||||
-rwxr-xr-x | src/features/settingsWS/index.ts | 28 | ||||
-rwxr-xr-x | src/features/settingsWS/state.ts | 13 | ||||
-rwxr-xr-x | src/features/settingsWS/store.js | 132 | ||||
-rw-r--r-- | src/features/todos/index.ts | 25 | ||||
-rw-r--r-- | src/features/todos/store.js | 9 | ||||
-rw-r--r-- | src/features/workspaces/index.ts | 22 | ||||
-rw-r--r-- | src/features/workspaces/store.js | 8 |
9 files changed, 4 insertions, 248 deletions
diff --git a/src/features/publishDebugInfo/index.js b/src/features/publishDebugInfo/index.js index 51780a34e..43841b530 100644 --- a/src/features/publishDebugInfo/index.js +++ b/src/features/publishDebugInfo/index.js | |||
@@ -12,7 +12,7 @@ export default function initialize() { | |||
12 | state.isModalVisible = true; | 12 | state.isModalVisible = true; |
13 | } | 13 | } |
14 | 14 | ||
15 | window.ferdi.features.publishDebugInfo = { | 15 | window['ferdi'].features.publishDebugInfo = { |
16 | state, | 16 | state, |
17 | showModal, | 17 | showModal, |
18 | }; | 18 | }; |
diff --git a/src/features/settingsWS/actions.ts b/src/features/settingsWS/actions.ts deleted file mode 100755 index 03a398eb5..000000000 --- a/src/features/settingsWS/actions.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import PropTypes from 'prop-types'; | ||
2 | import { createActionsFromDefinitions } from '../../actions/lib/actions'; | ||
3 | |||
4 | export const settingsWSActions = createActionsFromDefinitions( | ||
5 | { | ||
6 | greet: { | ||
7 | name: PropTypes.string.isRequired, | ||
8 | }, | ||
9 | }, | ||
10 | PropTypes.checkPropTypes, | ||
11 | ); | ||
12 | |||
13 | export default settingsWSActions; | ||
diff --git a/src/features/settingsWS/index.ts b/src/features/settingsWS/index.ts deleted file mode 100755 index 9bb206d82..000000000 --- a/src/features/settingsWS/index.ts +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | import { reaction } from 'mobx'; | ||
2 | import { SettingsWSStore } from './store'; | ||
3 | |||
4 | const debug = require('debug')('Ferdi:feature:settingsWS'); | ||
5 | |||
6 | export const settingsStore = new SettingsWSStore(); | ||
7 | |||
8 | export default function initSettingsWebSocket( | ||
9 | stores: { features: any }, | ||
10 | actions: any, | ||
11 | ) { | ||
12 | const { features } = stores; | ||
13 | |||
14 | // Toggle SettingsWebSocket feature | ||
15 | reaction( | ||
16 | () => features.features.isSettingsWSEnabled, | ||
17 | isEnabled => { | ||
18 | if (isEnabled) { | ||
19 | debug('Initializing `settingsWS` feature'); | ||
20 | settingsStore.start(stores, actions); | ||
21 | } else if (settingsStore) { | ||
22 | debug('Disabling `settingsWS` feature'); | ||
23 | settingsStore.stop(); | ||
24 | } | ||
25 | }, | ||
26 | { fireImmediately: true }, | ||
27 | ); | ||
28 | } | ||
diff --git a/src/features/settingsWS/state.ts b/src/features/settingsWS/state.ts deleted file mode 100755 index 7b16b2b6e..000000000 --- a/src/features/settingsWS/state.ts +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | |||
3 | const defaultState = { | ||
4 | isFeatureActive: false, | ||
5 | }; | ||
6 | |||
7 | export const settingsWSState = observable(defaultState); | ||
8 | |||
9 | export function resetState() { | ||
10 | Object.assign(settingsWSState, defaultState); | ||
11 | } | ||
12 | |||
13 | export default settingsWSState; | ||
diff --git a/src/features/settingsWS/store.js b/src/features/settingsWS/store.js deleted file mode 100755 index 3b9e10825..000000000 --- a/src/features/settingsWS/store.js +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | import { observable } from 'mobx'; | ||
2 | import WebSocket from 'ws'; | ||
3 | import ms from 'ms'; | ||
4 | |||
5 | import { FeatureStore } from '../utils/FeatureStore'; | ||
6 | import { createReactions } from '../../stores/lib/Reaction'; | ||
7 | import { WS_API } from '../../environment-remote'; | ||
8 | |||
9 | const debug = require('debug')('Ferdi:feature:settingsWS:store'); | ||
10 | |||
11 | export class SettingsWSStore extends FeatureStore { | ||
12 | stores = null; | ||
13 | |||
14 | actions = null; | ||
15 | |||
16 | ws = null; | ||
17 | |||
18 | pingTimeout = null; | ||
19 | |||
20 | reconnectTimeout = null; | ||
21 | |||
22 | @observable connected = false; | ||
23 | |||
24 | start(stores, actions) { | ||
25 | this.stores = stores; | ||
26 | this.actions = actions; | ||
27 | |||
28 | this._registerReactions( | ||
29 | createReactions([ | ||
30 | this._initialize.bind(this), | ||
31 | this._reconnect.bind(this), | ||
32 | this._close.bind(this), | ||
33 | ]), | ||
34 | ); | ||
35 | } | ||
36 | |||
37 | connect() { | ||
38 | try { | ||
39 | const wsURL = `${WS_API}/ws/${this.stores.user.data.id}`; | ||
40 | debug('Setting up WebSocket to', wsURL); | ||
41 | |||
42 | this.ws = new WebSocket(wsURL); | ||
43 | |||
44 | this.ws.on('open', () => { | ||
45 | debug('Opened WebSocket'); | ||
46 | this.send({ | ||
47 | action: 'authorize', | ||
48 | token: this.stores.user.authToken, | ||
49 | }); | ||
50 | |||
51 | this.connected = true; | ||
52 | |||
53 | this.heartbeat(); | ||
54 | }); | ||
55 | |||
56 | this.ws.on('message', data => { | ||
57 | const resp = JSON.parse(data); | ||
58 | debug('Received message', resp); | ||
59 | |||
60 | if (resp.id) { | ||
61 | this.stores.user.getUserInfoRequest.patch(result => { | ||
62 | if (!result) return; | ||
63 | |||
64 | debug('Patching user object with new values'); | ||
65 | Object.assign(result, resp); | ||
66 | }); | ||
67 | } | ||
68 | }); | ||
69 | |||
70 | this.ws.on('ping', this.heartbeat.bind(this)); | ||
71 | } catch (error) { | ||
72 | console.error(error); | ||
73 | } | ||
74 | } | ||
75 | |||
76 | heartbeat() { | ||
77 | debug('Heartbeat'); | ||
78 | clearTimeout(this.pingTimeout); | ||
79 | |||
80 | this.pingTimeout = setTimeout(() => { | ||
81 | debug('Terminating connection, reconnecting in 35'); | ||
82 | this.ws.terminate(); | ||
83 | |||
84 | this.connected = false; | ||
85 | }, ms('35s')); | ||
86 | } | ||
87 | |||
88 | send(data) { | ||
89 | if (this.ws && this.ws.readyState === 1) { | ||
90 | this.ws.send(JSON.stringify(data)); | ||
91 | debug('Sending data', data); | ||
92 | } else { | ||
93 | debug('WebSocket is not initialized'); | ||
94 | } | ||
95 | } | ||
96 | |||
97 | // Reactions | ||
98 | |||
99 | _initialize() { | ||
100 | if (this.stores.user.data.id && !this.ws) { | ||
101 | this.connect(); | ||
102 | } | ||
103 | } | ||
104 | |||
105 | _reconnect() { | ||
106 | if (!this.connected) { | ||
107 | debug('Trying to reconnect in 30s'); | ||
108 | this.reconnectTimeout = setInterval(() => { | ||
109 | debug('Trying to reconnect'); | ||
110 | this.connect(); | ||
111 | }, ms('30s')); | ||
112 | } else { | ||
113 | debug('Clearing reconnect interval'); | ||
114 | clearInterval(this.reconnectTimeout); | ||
115 | } | ||
116 | } | ||
117 | |||
118 | _close() { | ||
119 | if (!this.stores.user.isLoggedIn) { | ||
120 | debug('Stopping reactions'); | ||
121 | this._stopReactions(); | ||
122 | |||
123 | if (this.ws) { | ||
124 | debug('Terminating connection'); | ||
125 | this.ws.terminate(); | ||
126 | this.ws = null; | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | } | ||
131 | |||
132 | export default SettingsWSStore; | ||
diff --git a/src/features/todos/index.ts b/src/features/todos/index.ts index 3665812e6..2fa8c3130 100644 --- a/src/features/todos/index.ts +++ b/src/features/todos/index.ts | |||
@@ -1,29 +1,8 @@ | |||
1 | import { reaction } from 'mobx'; | ||
2 | import TodoStore from './store'; | 1 | import TodoStore from './store'; |
3 | 2 | ||
4 | const debug = require('debug')('Ferdi:feature:todos'); | ||
5 | |||
6 | export const todosStore = new TodoStore(); | 3 | export const todosStore = new TodoStore(); |
7 | 4 | ||
8 | export default function initTodos( | 5 | export default function initTodos(stores: { todos?: any }, actions: any) { |
9 | stores: { todos?: any; features?: any }, | ||
10 | actions: any, | ||
11 | ) { | ||
12 | stores.todos = todosStore; | 6 | stores.todos = todosStore; |
13 | const { features } = stores; | 7 | todosStore.start(stores, actions); |
14 | |||
15 | // Toggle todos feature | ||
16 | reaction( | ||
17 | () => features.features.isTodosEnabled, | ||
18 | isEnabled => { | ||
19 | if (isEnabled) { | ||
20 | debug('Initializing `todos` feature'); | ||
21 | todosStore.start(stores, actions); | ||
22 | } else if (todosStore.isFeatureActive) { | ||
23 | debug('Disabling `todos` feature'); | ||
24 | todosStore.stop(); | ||
25 | } | ||
26 | }, | ||
27 | { fireImmediately: true }, | ||
28 | ); | ||
29 | } | 8 | } |
diff --git a/src/features/todos/store.js b/src/features/todos/store.js index 010a029ff..d158ed480 100644 --- a/src/features/todos/store.js +++ b/src/features/todos/store.js | |||
@@ -23,8 +23,6 @@ const debug = require('debug')('Ferdi:feature:todos:store'); | |||
23 | export default class TodoStore extends FeatureStore { | 23 | export default class TodoStore extends FeatureStore { |
24 | @observable stores = null; | 24 | @observable stores = null; |
25 | 25 | ||
26 | @observable isFeatureEnabled = false; | ||
27 | |||
28 | @observable isFeatureActive = false; | 26 | @observable isFeatureActive = false; |
29 | 27 | ||
30 | @observable webview = null; | 28 | @observable webview = null; |
@@ -123,7 +121,6 @@ export default class TodoStore extends FeatureStore { | |||
123 | // REACTIONS | 121 | // REACTIONS |
124 | 122 | ||
125 | this._allReactions = createReactions([ | 123 | this._allReactions = createReactions([ |
126 | this._setFeatureEnabledReaction, | ||
127 | this._updateTodosConfig, | 124 | this._updateTodosConfig, |
128 | this._firstLaunchReaction, | 125 | this._firstLaunchReaction, |
129 | this._routeCheckReaction, | 126 | this._routeCheckReaction, |
@@ -262,12 +259,6 @@ export default class TodoStore extends FeatureStore { | |||
262 | 259 | ||
263 | // Reactions | 260 | // Reactions |
264 | 261 | ||
265 | _setFeatureEnabledReaction = () => { | ||
266 | const { isTodosEnabled } = this.stores.features.features; | ||
267 | |||
268 | this.isFeatureEnabled = isTodosEnabled; | ||
269 | }; | ||
270 | |||
271 | _updateTodosConfig = () => { | 262 | _updateTodosConfig = () => { |
272 | // Resend the config if any part changes in Franz: | 263 | // Resend the config if any part changes in Franz: |
273 | this._onTodosClientInitialized(); | 264 | this._onTodosClientInitialized(); |
diff --git a/src/features/workspaces/index.ts b/src/features/workspaces/index.ts index ecca64b41..25975936a 100644 --- a/src/features/workspaces/index.ts +++ b/src/features/workspaces/index.ts | |||
@@ -1,28 +1,8 @@ | |||
1 | import { reaction } from 'mobx'; | ||
2 | import WorkspacesStore from './store'; | 1 | import WorkspacesStore from './store'; |
3 | import { resetApiRequests } from './api'; | ||
4 | |||
5 | const debug = require('debug')('Ferdi:feature:workspaces'); | ||
6 | 2 | ||
7 | export const workspaceStore = new WorkspacesStore(); | 3 | export const workspaceStore = new WorkspacesStore(); |
8 | 4 | ||
9 | export default function initWorkspaces(stores, actions) { | 5 | export default function initWorkspaces(stores, actions) { |
10 | stores.workspaces = workspaceStore; | 6 | stores.workspaces = workspaceStore; |
11 | const { features } = stores; | 7 | workspaceStore.start(stores, actions); |
12 | |||
13 | // Toggle workspace feature | ||
14 | reaction( | ||
15 | () => features.features.isWorkspaceEnabled, | ||
16 | isEnabled => { | ||
17 | if (isEnabled && !workspaceStore.isFeatureActive) { | ||
18 | debug('Initializing `workspaces` feature'); | ||
19 | workspaceStore.start(stores, actions); | ||
20 | } else if (workspaceStore.isFeatureActive) { | ||
21 | debug('Disabling `workspaces` feature'); | ||
22 | workspaceStore.stop(); | ||
23 | resetApiRequests(); | ||
24 | } | ||
25 | }, | ||
26 | { fireImmediately: true }, | ||
27 | ); | ||
28 | } | 8 | } |
diff --git a/src/features/workspaces/store.js b/src/features/workspaces/store.js index 0fa43b723..17ec17b3a 100644 --- a/src/features/workspaces/store.js +++ b/src/features/workspaces/store.js | |||
@@ -18,8 +18,6 @@ import { KEEP_WS_LOADED_USID } from '../../config'; | |||
18 | const debug = require('debug')('Ferdi:feature:workspaces:store'); | 18 | const debug = require('debug')('Ferdi:feature:workspaces:store'); |
19 | 19 | ||
20 | export default class WorkspacesStore extends FeatureStore { | 20 | export default class WorkspacesStore extends FeatureStore { |
21 | @observable isFeatureEnabled = true; | ||
22 | |||
23 | @observable isFeatureActive = false; | 21 | @observable isFeatureActive = false; |
24 | 22 | ||
25 | @observable activeWorkspace = null; | 23 | @observable activeWorkspace = null; |
@@ -97,7 +95,6 @@ export default class WorkspacesStore extends FeatureStore { | |||
97 | 95 | ||
98 | this._allReactions = createReactions([ | 96 | this._allReactions = createReactions([ |
99 | this._openDrawerWithSettingsReaction, | 97 | this._openDrawerWithSettingsReaction, |
100 | this._setFeatureEnabledReaction, | ||
101 | this._cleanupInvalidServiceReferences, | 98 | this._cleanupInvalidServiceReferences, |
102 | this._setActiveServiceOnWorkspaceSwitchReaction, | 99 | this._setActiveServiceOnWorkspaceSwitchReaction, |
103 | this._activateLastUsedWorkspaceReaction, | 100 | this._activateLastUsedWorkspaceReaction, |
@@ -251,11 +248,6 @@ export default class WorkspacesStore extends FeatureStore { | |||
251 | 248 | ||
252 | // Reactions | 249 | // Reactions |
253 | 250 | ||
254 | _setFeatureEnabledReaction = () => { | ||
255 | const { isWorkspaceEnabled } = this.stores.features.features; | ||
256 | this.isFeatureEnabled = isWorkspaceEnabled; | ||
257 | }; | ||
258 | |||
259 | _setWorkspaceBeingEditedReaction = () => { | 251 | _setWorkspaceBeingEditedReaction = () => { |
260 | const { pathname } = this.stores.router.location; | 252 | const { pathname } = this.stores.router.location; |
261 | const match = matchRoute('/settings/workspaces/edit/:id', pathname); | 253 | const match = matchRoute('/settings/workspaces/edit/:id', pathname); |