RIFT-14134, RIFT-14548: RO CRU and Instantiate Data Centers
[osm/UI.git] / skyquake / framework / widgets / skyquake_container / skyquakeContainerSource.js
1 /*
2 *
3 * Copyright 2016 RIFT.IO Inc
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18 import Alt from './skyquakeAltInstance.js';
19 import $ from 'jquery';
20 import SkyquakeContainerActions from './skyquakeContainerActions'
21
22 let Utils = require('utils/utils.js');
23 let API_SERVER = require('utils/rw.js').getSearchParams(window.location).api_server;
24 let HOST = API_SERVER;
25 let NODE_PORT = require('utils/rw.js').getSearchParams(window.location).api_port || ((window.location.protocol == 'https:') ? 8443 : 8000);
26 let DEV_MODE = require('utils/rw.js').getSearchParams(window.location).dev_mode || false;
27 let RW_REST_API_PORT = require('utils/rw.js').getSearchParams(window.location).rw_rest_api_port || 8008;
28
29 if (DEV_MODE) {
30 HOST = window.location.protocol + '//' + window.location.hostname;
31 }
32
33 export default {
34 getNav() {
35 return {
36 remote: function() {
37 return new Promise(function(resolve, reject) {
38 $.ajax({
39 url: '/nav',
40 type: 'GET',
41 // beforeSend: Utils.addAuthorizationStub,
42 success: function(data) {
43 resolve(data);
44 }
45 })
46 })
47 },
48 success: SkyquakeContainerActions.getSkyquakeNavSuccess
49 }
50 },
51
52 getEventStreams() {
53 return {
54 remote: function(state, recordID) {
55 return new Promise(function(resolve, reject) {
56 $.ajax({
57 url: '//' + window.location.hostname + ':' + NODE_PORT + '/api/operational/restconf-state/streams?api_server=' + API_SERVER,
58 type: 'GET',
59 beforeSend: Utils.addAuthorizationStub,
60 success: function(data) {
61 resolve(data);
62 }
63 }).fail(function(xhr) {
64 //Authentication and the handling of fail states should be wrapped up into a connection class.
65 Utils.checkAuthentication(xhr.status);
66 });;
67 });
68 },
69 loading: SkyquakeContainerActions.getEventStreamsLoading,
70 success: SkyquakeContainerActions.getEventStreamsSuccess,
71 error: SkyquakeContainerActions.getEventStreamsError
72 }
73 },
74
75 openNotificationsSocket() {
76 return {
77 remote: function(state, location, streamSource) {
78 return new Promise((resolve, reject) => {
79 $.ajax({
80 url: '//' + window.location.hostname + ':' + NODE_PORT + '/socket-polling?api_server=' + API_SERVER,
81 type: 'POST',
82 beforeSend: Utils.addAuthorizationStub,
83 data: {
84 url: location
85 },
86 success: (data) => {
87 // var url = Utils.webSocketProtocol() + '//' + window.location.hostname + ':' + data.port + data.socketPath;
88 // var ws = new WebSocket(url);
89 // resolve({
90 // ws: ws,
91 // streamSource: streamSource
92 // });
93 const checker = () => {
94 if (!Utils.isMultiplexerLoaded()) {
95 setTimeout(() => {
96 checker();
97 }, 500);
98 } else {
99 resolve({
100 connection: data.id,
101 streamSource: streamSource
102 });
103 }
104 };
105
106 checker();
107 }
108 });
109 });
110 },
111 loading: SkyquakeContainerActions.openNotificationsSocketLoading,
112 success: SkyquakeContainerActions.openNotificationsSocketSuccess,
113 error: SkyquakeContainerActions.openNotificationsSocketError
114 }
115 }
116 }
117