blob: e9ce332e203b922edf66e2791b429c52977bfeff [file] [log] [blame]
Maleke6c3c722018-10-16 16:44:41 +03001/*
2* Copyright © 2018 European Support Limited
3*
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at
7*
8* http: //www.apache.org/licenses/LICENSE-2.0
9*
10* Unless required by applicable law or agreed to in writing, software
11* distributed under the License is distributed on an "AS IS" BASIS,
12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13* See the License for the specific language governing permissions and
14* limitations under the License.
15*/
16
17import Configuration from 'sdc-app/config/Configuration.js';
18import { applySecurity } from 'nfvo-utils/RestAPIUtil.js';
19import store from 'sdc-app/AppStore.js';
20import { actionTypes } from 'sdc-app/onboarding/userNotifications/UserNotificationsConstants.js';
21
22import Worker from 'nfvo-utils/Notifications.worker.js';
23
24class WorkerUtil {
25 open() {
26 this.worker = new Worker();
27
28 const url = `${Configuration.get('restPrefix')}/v1.0/notifications`;
29 const notificationsWorkerUpdateMillisecond = Configuration.get(
30 'notificationsWorkerUpdateMillisecond'
31 );
32 const options = {};
33
34 applySecurity(options);
35
36 const config = {
37 method: 'GET',
38 url: url,
39 headers: options.headers,
40 data: null
41 };
42
43 this.worker.postMessage({
44 config,
45 notificationsWorkerUpdateMillisecond
46 });
47
48 this.worker.onmessage = event => {
49 const result = event.data;
50 store.dispatch({
51 type: actionTypes.LOAD_NOTIFICATIONS,
52 result
53 });
54 };
55 }
56
57 close() {
58 if (this.worker !== undefined) {
59 this.worker.terminate();
60 }
61 }
62}
63
64export default WorkerUtil;