Skip to content

Commit

Permalink
fix: socket io connection
Browse files Browse the repository at this point in the history
  • Loading branch information
nextchamp-saqib committed Jan 15, 2024
1 parent c29777f commit 300f363
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 5 additions & 10 deletions frontend/src/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { frappeRequest, initSocket, setConfig } from 'frappe-ui'
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'
import { frappeRequest, setConfig } from 'frappe-ui'
import { GridItem, GridLayout } from 'grid-layout-plus'
import { createPinia } from 'pinia'
import { createApp } from 'vue'
import { GridLayout, GridItem } from 'grid-layout-plus'
import { socketio_port } from '../../../../sites/common_site_config.json'
import App from './App.vue'
import './index.css'
import router from './router'
import { initSocket } from './socket'
import { createToast } from './utils/toasts'
import { autoAnimatePlugin } from '@formkit/auto-animate/vue'

import { registerControllers, registerGlobalComponents } from './globals'

Expand All @@ -33,12 +33,7 @@ app.use(router)
app.use(autoAnimatePlugin)
app.component('grid-layout', GridLayout)
app.component('grid-item', GridItem)
app.provide(
'$socket',
initSocket({
port: socketio_port,
})
)
app.provide('$socket', initSocket())

registerGlobalComponents(app)
registerControllers(app)
Expand Down
16 changes: 16 additions & 0 deletions frontend/src/socket.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { io } from 'socket.io-client'
import { socketio_port } from '../../../../sites/common_site_config.json'

export function initSocket() {
let host = window.location.hostname
let siteName = window.site_name
let port = window.location.port ? `:${socketio_port}` : ''
let protocol = port ? 'http' : 'https'
let url = `${protocol}://${host}${port}/${siteName}`

let socket = io(url, {
withCredentials: true,
reconnectionAttempts: 5,
})
return socket
}

0 comments on commit 300f363

Please sign in to comment.