1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { RootStore } from 'store/store';
6 import { AuthService } from 'services/auth-service/auth-service';
7 import { Config } from 'common/config';
8 import { WebSocketService } from './websocket-service';
9 import { ResourceEventMessage } from './resource-event-message';
10 import { ResourceKind } from 'models/resource';
11 import { loadProcess } from 'store/processes/processes-actions';
12 import { LogEventType } from 'models/log';
13 import { addProcessLogsPanelItem } from 'store/process-logs-panel/process-logs-panel-actions';
14 import { subprocessPanelActions } from "store/subprocess-panel/subprocess-panel-actions";
15 import { projectPanelActions } from "store/project-panel/project-panel-action";
16 import { getProjectPanelCurrentUuid } from 'store/project-panel/project-panel-action';
17 import { allProcessesPanelActions } from 'store/all-processes-panel/all-processes-panel-action';
19 export const initWebSocket = (config: Config, authService: AuthService, store: RootStore) => {
20 if (config.websocketUrl) {
21 const webSocketService = new WebSocketService(config.websocketUrl, authService);
22 webSocketService.setMessageListener(messageListener(store));
23 webSocketService.connect();
25 console.warn("WARNING: Websocket ExternalURL is not set on the cluster config.");
29 const messageListener = (store: RootStore) => (message: ResourceEventMessage) => {
30 if (message.eventType === LogEventType.CREATE || message.eventType === LogEventType.UPDATE) {
31 switch (message.objectKind) {
32 case ResourceKind.CONTAINER_REQUEST:
33 if (store.getState().processPanel.containerRequestUuid === message.objectUuid) {
34 store.dispatch(loadProcess(message.objectUuid));
36 // fall through, this will happen for container requests as well.
37 case ResourceKind.CONTAINER:
38 store.dispatch(subprocessPanelActions.REQUEST_ITEMS());
39 store.dispatch(allProcessesPanelActions.REQUEST_ITEMS());
40 if (message.objectOwnerUuid === getProjectPanelCurrentUuid(store.getState())) {
41 store.dispatch(projectPanelActions.REQUEST_ITEMS());
48 return store.dispatch(addProcessLogsPanelItem(message as ResourceEventMessage<{ text: string }>));