@@ -4,7 +4,6 @@ import { clearUser, AuthStore } from '@/composables/stores/auth'
4
4
import { provide , inject , reactive } from 'vue'
5
5
6
6
const socketcluster = require ( 'socketcluster-client' )
7
- const debug = true
8
7
9
8
// Public channel idenitfier and general options
10
9
let options = { waitForAuth : true }
@@ -41,13 +40,13 @@ export const socketLogout = socketUser => {
41
40
}
42
41
43
42
export const watchUserChannel = handler => {
44
- if ( debug ) console . log ( 'Watching user channel.' )
43
+ if ( window . websocket_logs ) console . log ( 'Watching user channel.' )
45
44
if ( userChannel ) userChannel . watch ( handler )
46
45
else setTimeout ( ( ) => watchUserChannel ( handler ) , 1000 )
47
46
}
48
47
49
48
export const unwatchUserChannel = handler => {
50
- if ( debug ) console . log ( 'Unwatching user channel.' )
49
+ if ( window . websocket_logs ) console . log ( 'Unwatching user channel.' )
51
50
if ( userChannel ) userChannel . unwatch ( handler )
52
51
}
53
52
@@ -61,19 +60,19 @@ export default {
61
60
const $auth = inject ( AuthStore )
62
61
63
62
// Socket Error logging
64
- socket . on ( 'error' , err => debug ? console . log ( 'Websocket error:' , err ) : null )
63
+ socket . on ( 'error' , err => window . websocket_logs ? console . log ( 'Websocket error:' , err ) : null )
65
64
66
65
// Channel Subscribe
67
66
socket . on ( 'subscribe' , channelName => {
68
67
if ( JSON . parse ( channelName ) . type === 'role' ) {
69
68
socket . watch ( channelName , d => {
70
- if ( debug ) console . log ( 'Received role channel message.' , d )
69
+ if ( window . websocket_logs ) console . log ( 'Received role channel message.' , d )
71
70
$auth . reauthenticate ( )
72
71
} )
73
72
}
74
73
else if ( JSON . parse ( channelName ) . type === 'user' ) {
75
74
socket . watch ( channelName , d => {
76
- if ( debug ) console . log ( 'Received user channel message' , d )
75
+ if ( window . websocket_logs ) console . log ( 'Received user channel message' , d )
77
76
if ( d . action === 'reauthenticate' ) $auth . reauthenticate ( )
78
77
else if ( d . action === 'logout' && d . sessionId === socket . getAuthToken ( ) . sessionId ) {
79
78
$auth . logout ( )
@@ -90,22 +89,22 @@ export default {
90
89
else if ( JSON . parse ( channelName ) . type === 'public' ) {
91
90
socket . watch ( channelName , d => d . action === 'announcement' ? alertStore . warn ( d . message ) : null )
92
91
}
93
- else debug ? console . log ( 'Not watching' , channelName ) : null
92
+ else window . websocket_logs ? console . log ( 'Not watching' , channelName ) : null
94
93
95
- if ( debug ) console . log ( 'Websocket subscribed to' , channelName , 'with watchers' , socket . watchers ( channelName ) )
94
+ if ( window . websocket_logs ) console . log ( 'Websocket subscribed to' , channelName , 'with watchers' , socket . watchers ( channelName ) )
96
95
} )
97
96
98
97
// Channel Unsubscribe
99
98
socket . on ( 'unsubscribe' , channelName => {
100
- if ( debug ) console . log ( 'Websocket unsubscribed from' , channelName , socket . watchers ( channelName ) )
99
+ if ( window . websocket_logs ) console . log ( 'Websocket unsubscribed from' , channelName , socket . watchers ( channelName ) )
101
100
102
101
// disconnect all watchers from the channel
103
102
socket . unwatch ( channelName )
104
103
} )
105
104
106
105
// Socket Authentication
107
106
socket . on ( 'authenticate' , ( ) => {
108
- if ( debug ) console . log ( 'Authenticated WebSocket Connection' )
107
+ if ( window . websocket_logs ) console . log ( 'Authenticated WebSocket Connection' )
109
108
110
109
// Emit LoggedIn event to socket server
111
110
socket . emit ( 'loggedIn' )
0 commit comments