Skip to content

Commit

Permalink
Merge pull request #1482 from AllenBW/bug/#1637512-broken-websockets
Browse files Browse the repository at this point in the history
BZ#1637512-Restore action cable subscription, ensure enablement flag is available
  • Loading branch information
himdel authored Oct 12, 2018
2 parents cb7c805 + a30d4b1 commit 3af8f1b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion client/app/core/appliance-info.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ export function ApplianceInfo ($sessionStorage) {
role: data.identity.role,
suiVersion: gitHash.gitCommit,
miqVersion: data.server_info.version + '.' + data.server_info.build,
server: data.server_info.appliance
server: data.server_info.appliance,
asyncNotify: data.settings.asynchronous_notifications || true
}
$sessionStorage.applianceInfo = applianceInfo
}
Expand Down
3 changes: 2 additions & 1 deletion client/app/core/appliance-info.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('Appliance Info Service', () => {
'role': 'EvmRole-super_administrator',
'miqVersion': 'master.20170510164252_9e5df30',
'suiVersion': '',
'server': 'EVM'
'server': 'EVM',
'asyncNotify': 'true'
}
ApplianceInfo.set(applianceInfoData)
const currentApplianceInfo = ApplianceInfo.get()
Expand Down
4 changes: 0 additions & 4 deletions client/app/core/authorization.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,6 @@ export function authInit ($rootScope, $state, $log, Session, $sessionStorage, La
}
syncSession()
.then(rbacReloadOrLogin(toState, toParams))
.then(() => {
const cable = ActionCable.createConsumer('/ws/notifications')
cable.subscriptions.create('NotificationChannel', {})
})
.catch(badUser)
}

Expand Down
24 changes: 23 additions & 1 deletion client/app/core/event-notifications.service.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @ngInject */
export function EventNotificationsFactory ($timeout, lodash, CollectionsApi, RBAC) {
export function EventNotificationsFactory ($log, $timeout, lodash, CollectionsApi, RBAC, ApplianceInfo, ActionCable,
Session) {
const state = {}
const toastDelay = 8 * 1000
const service = {
Expand All @@ -21,6 +22,7 @@ export function EventNotificationsFactory ($timeout, lodash, CollectionsApi, RBA
}

notificationsInit()
actionCableInit()

return service

Expand Down Expand Up @@ -233,6 +235,26 @@ export function EventNotificationsFactory ($timeout, lodash, CollectionsApi, RBA
}
}

function actionCableInit () {
if (ApplianceInfo.get().asyncNotify) {
const cable = ActionCable.createConsumer('/ws/notifications')
cable.subscriptions.create('NotificationChannel', {
disconnected: () => {
const vm = this
Session.requestWsToken().then(null, () => {
$log.warn('Unable to retrieve a valid ws_token!')
// Disconnect permanently if the ws_token cannot be fetched
vm.consumer.connection.close({allowReconnect: false})
})
},
received: (data) => {
const msg = miqFormatNotification(data.text, data.bindings)
add(data.level, data.level === 'error' ? 'danger' : data.level, msg, {message: msg}, data.id)
}
})
}
}

function removeToast (notification) {
const index = state.toastNotifications.indexOf(notification)
if (index > -1) {
Expand Down
4 changes: 0 additions & 4 deletions client/app/states/login/login.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ function StateController ($window, $state, Text, RBAC, API_LOGIN, API_PASSWORD,
Session.destroy()
}
})
.then(() => {
const cable = ActionCable.createConsumer('/ws/notifications')
cable.subscriptions.create('NotificationChannel', {})
})
.catch((response) => {
if (response.status === 401) {
vm.credentials.login = ''
Expand Down

0 comments on commit 3af8f1b

Please sign in to comment.