3 * Copyright 2016 RIFT.IO Inc
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 import Alt
from './skyquakeAltInstance.js';
19 import $ from 'jquery';
20 import SkyquakeContainerActions
from './skyquakeContainerActions'
21 import rw
from 'utils/rw.js';
22 import Utils
from 'utils/utils.js';
24 let API_SERVER
= rw
.getSearchParams(window
.location
).api_server
;
25 let HOST
= API_SERVER
;
26 let NODE_PORT
= rw
.getSearchParams(window
.location
).api_port
|| ((window
.location
.protocol
== 'https:') ? 8443 : 8000);
27 let DEV_MODE
= rw
.getSearchParams(window
.location
).dev_mode
|| false;
28 let RW_REST_API_PORT
= rw
.getSearchParams(window
.location
).rw_rest_api_port
|| 8008;
31 HOST
= window
.location
.protocol
+ '//' + window
.location
.hostname
;
38 return new Promise(function(resolve
, reject
) {
42 // beforeSend: Utils.addAuthorizationStub,
43 success: function(data
) {
44 Utils
.detectInactivity();
50 success
: SkyquakeContainerActions
.getSkyquakeNavSuccess
56 remote: function(state
, recordID
) {
57 return new Promise(function(resolve
, reject
) {
59 url
: '//' + window
.location
.hostname
+ ':' + window
.location
.port
+ '/api/operational/restconf-state/streams?api_server=' + API_SERVER
,
61 beforeSend
: Utils
.addAuthorizationStub
,
62 success: function(data
) {
65 }).fail(function(xhr
) {
66 //Authentication and the handling of fail states should be wrapped up into a connection class.
67 Utils
.checkAuthentication(xhr
.status
);
71 loading
: SkyquakeContainerActions
.getEventStreamsLoading
,
72 success
: SkyquakeContainerActions
.getEventStreamsSuccess
,
73 error
: SkyquakeContainerActions
.getEventStreamsError
77 openNotificationsSocket() {
79 remote: function(state
, location
, streamSource
) {
80 return new Promise((resolve
, reject
) => {
82 url
: '//' + window
.location
.hostname
+ ':' + window
.location
.port
+ '/socket-polling',
84 beforeSend
: Utils
.addAuthorizationStub
,
89 // var url = Utils.webSocketProtocol() + '//' + window.location.hostname + ':' + data.port + data.socketPath;
90 // var ws = new WebSocket(url);
93 // streamSource: streamSource
95 const checker
= () => {
96 if (!Utils
.isMultiplexerLoaded()) {
103 streamSource
: streamSource
113 loading
: SkyquakeContainerActions
.openNotificationsSocketLoading
,
114 success
: SkyquakeContainerActions
.openNotificationsSocketSuccess
,
115 error
: SkyquakeContainerActions
.openNotificationsSocketError
118 openProjectSocket() {
120 remote: function(state
) {
121 return new Promise(function(resolve
, reject
) {
122 //If socket connection already exists, eat the request.
124 return resolve(false);
127 url
: '/socket-polling',
129 beforeSend
: Utils
.addAuthorizationStub
,
131 url
: '/project?api_server=' + API_SERVER
133 success: function(data
, textStatus
, jqXHR
) {
134 Utils
.checkAndResolveSocketRequest(data
, resolve
, reject
);
138 //Authentication and the handling of fail states should be wrapped up into a connection class.
139 Utils
.checkAuthentication(xhr
.status
);
143 success
: SkyquakeContainerActions
.openProjectSocketSuccess
149 remote: function(state
, recordID
) {
150 return new Promise(function(resolve
, reject
) {
152 url
: '/user-profile?api_server=' + API_SERVER
,
154 beforeSend
: Utils
.addAuthorizationStub
,
155 success: function(data
) {
158 }).fail(function(xhr
) {
159 //Authentication and the handling of fail states should be wrapped up into a connection class.
160 Utils
.checkAuthentication(xhr
.status
);
164 loading
: Alt
.actions
.global
.showScreenLoader
,
165 success
: SkyquakeContainerActions
.getUserProfileSuccess
169 selectActiveProject() {
171 remote: function(state
, event
) {
174 projectId
= JSON
.parse(JSON
.parse(event
.currentTarget
.value
));
176 console
.log('Something went wrong in the selectActiveProject source function', e
);
179 return new Promise(function(resolve
, reject
) {
181 url
: `/session/${projectId}?api_server=${API_SERVER}`,
183 beforeSend
: Utils
.addAuthorizationStub
,
184 success: function(data
) {
187 }).fail(function(xhr
) {
188 //Authentication and the handling of fail states should be wrapped up into a connection class.
189 Utils
.checkAuthentication(xhr
.status
);
193 success
: SkyquakeContainerActions
.selectActiveProjectSuccess