Adjustments to Socket Service for session-limit PR

This commit is contained in:
Jared Tabor 2018-06-27 10:45:23 -07:00
parent b2cdf82b78
commit aa76f6ca39
No known key found for this signature in database
GPG Key ID: 1B343EC4C3CF7E5C

View File

@ -5,8 +5,8 @@
*************************************************/
import ReconnectingWebSocket from 'reconnectingwebsocket';
export default
['$rootScope', '$location', '$log','$state', '$q', 'i18n',
function ($rootScope, $location, $log, $state, $q, i18n) {
['$rootScope', '$location', '$log','$state', '$q', 'i18n', 'GetBasePath', 'Rest',
function ($rootScope, $location, $log, $state, $q, i18n, GetBasePath, Rest) {
var needsResubscribing = false,
socketPromise = $q.defer(),
needsRefreshAfterBlur;
@ -130,16 +130,16 @@ export default
else if(data.group_name==="inventory_update_events"){
str = `ws-${data.group_name}-${data.inventory_update}`;
}
else if(data.group_name==="control" && data.reason=="limit_reached"){
else if(data.group_name === "control" && data.reason === "limit_reached"){
// If we got a `limit_reached_<user_pk>` message, determine
// if the current session is still valid (it may have been
// invalidated)
// If so, log the user out and show a meaningful error
$log.debug(data.reason);
self.$.ajax({
url: '/api/v2/me/'
}).error(function(resp, status) {
if (resp.status == 401) {
let url = GetBasePath('me');
Rest.get(url)
.catch(function(resp) {
if (resp.status === 401) {
$rootScope.sessionTimer.expireSession('session_limit');
$state.go('signOut');
}
@ -165,7 +165,7 @@ export default
// listen for specific messages. A subscription object could
// look like {"groups":{"jobs": ["status_changed", "summary"]}.
// This is used by all socket-enabled $states
state.data.socket.groups['control'] = ['limit_reached_' + $rootScope.current_user.id];
state.data.socket.groups.control = ['limit_reached_' + $rootScope.current_user.id];
this.emit(JSON.stringify(state.data.socket));
this.setLast(state);
},