@@ -4,7 +4,6 @@ import { clearUser, AuthStore } from '@/composables/stores/auth'
44import { provide , inject , reactive } from 'vue'
55
66const socketcluster = require ( 'socketcluster-client' )
7- const debug = true
87
98// Public channel idenitfier and general options
109let options = { waitForAuth : true }
@@ -41,13 +40,13 @@ export const socketLogout = socketUser => {
4140}
4241
4342export const watchUserChannel = handler => {
44- if ( debug ) console . log ( 'Watching user channel.' )
43+ if ( window . websocket_logs ) console . log ( 'Watching user channel.' )
4544 if ( userChannel ) userChannel . watch ( handler )
4645 else setTimeout ( ( ) => watchUserChannel ( handler ) , 1000 )
4746}
4847
4948export const unwatchUserChannel = handler => {
50- if ( debug ) console . log ( 'Unwatching user channel.' )
49+ if ( window . websocket_logs ) console . log ( 'Unwatching user channel.' )
5150 if ( userChannel ) userChannel . unwatch ( handler )
5251}
5352
@@ -61,19 +60,19 @@ export default {
6160 const $auth = inject ( AuthStore )
6261
6362 // 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 )
6564
6665 // Channel Subscribe
6766 socket . on ( 'subscribe' , channelName => {
6867 if ( JSON . parse ( channelName ) . type === 'role' ) {
6968 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 )
7170 $auth . reauthenticate ( )
7271 } )
7372 }
7473 else if ( JSON . parse ( channelName ) . type === 'user' ) {
7574 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 )
7776 if ( d . action === 'reauthenticate' ) $auth . reauthenticate ( )
7877 else if ( d . action === 'logout' && d . sessionId === socket . getAuthToken ( ) . sessionId ) {
7978 $auth . logout ( )
@@ -90,22 +89,22 @@ export default {
9089 else if ( JSON . parse ( channelName ) . type === 'public' ) {
9190 socket . watch ( channelName , d => d . action === 'announcement' ? alertStore . warn ( d . message ) : null )
9291 }
93- else debug ? console . log ( 'Not watching' , channelName ) : null
92+ else window . websocket_logs ? console . log ( 'Not watching' , channelName ) : null
9493
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 ) )
9695 } )
9796
9897 // Channel Unsubscribe
9998 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 ) )
101100
102101 // disconnect all watchers from the channel
103102 socket . unwatch ( channelName )
104103 } )
105104
106105 // Socket Authentication
107106 socket . on ( 'authenticate' , ( ) => {
108- if ( debug ) console . log ( 'Authenticated WebSocket Connection' )
107+ if ( window . websocket_logs ) console . log ( 'Authenticated WebSocket Connection' )
109108
110109 // Emit LoggedIn event to socket server
111110 socket . emit ( 'loggedIn' )
0 commit comments