optimizations
This commit is contained in:
20
resources/js/bootstrap.js
vendored
20
resources/js/bootstrap.js
vendored
@@ -14,6 +14,10 @@ window.Pusher = Pusher
|
||||
|
||||
let echoInstance = null
|
||||
|
||||
function isLoopbackHost(host) {
|
||||
return ['127.0.0.1', '0.0.0.0', 'localhost', '::1'].includes(String(host || '').toLowerCase())
|
||||
}
|
||||
|
||||
export function getEcho() {
|
||||
if (echoInstance !== null) {
|
||||
return echoInstance || null
|
||||
@@ -27,13 +31,23 @@ export function getEcho() {
|
||||
|
||||
const scheme = import.meta.env.VITE_REVERB_SCHEME || window.location.protocol.replace(':', '') || 'https'
|
||||
const forceTLS = scheme === 'https'
|
||||
const configuredHost = import.meta.env.VITE_REVERB_HOST || window.location.hostname
|
||||
const publicHostname = window.location.hostname
|
||||
const useWindowHost = !isLoopbackHost(publicHostname) && isLoopbackHost(configuredHost)
|
||||
const resolvedHost = useWindowHost ? publicHostname : configuredHost
|
||||
const resolvedPort = useWindowHost
|
||||
? Number(forceTLS ? 443 : 80)
|
||||
: Number(import.meta.env.VITE_REVERB_PORT || (forceTLS ? 443 : 80))
|
||||
const resolvedSecurePort = useWindowHost
|
||||
? Number(forceTLS ? 443 : 80)
|
||||
: Number(import.meta.env.VITE_REVERB_PORT || 443)
|
||||
|
||||
echoInstance = new Echo({
|
||||
broadcaster: 'reverb',
|
||||
key,
|
||||
wsHost: import.meta.env.VITE_REVERB_HOST || window.location.hostname,
|
||||
wsPort: Number(import.meta.env.VITE_REVERB_PORT || (forceTLS ? 443 : 80)),
|
||||
wssPort: Number(import.meta.env.VITE_REVERB_PORT || 443),
|
||||
wsHost: resolvedHost,
|
||||
wsPort: resolvedPort,
|
||||
wssPort: resolvedSecurePort,
|
||||
forceTLS,
|
||||
enabledTransports: ['ws', 'wss'],
|
||||
authEndpoint: '/broadcasting/auth',
|
||||
|
||||
Reference in New Issue
Block a user