-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
save original or clients socket io if exists and save socket io from …
…cdn to vc_io
- Loading branch information
Ostap Gadzeman
committed
Jan 7, 2025
1 parent
0841e72
commit f323ee4
Showing
2 changed files
with
31 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,37 @@ | ||
export function loadExternalScript(url) { | ||
return new Promise((resolve) => { | ||
return new Promise(async (resolve, reject) => { | ||
let originalIo | ||
|
||
if (typeof window !== 'undefined') { | ||
if (typeof window.io !== 'undefined') { | ||
originalIo = window.io; | ||
} | ||
} | ||
|
||
const script = document.createElement('script'); | ||
|
||
script.src = url; | ||
|
||
script.onload = () => { | ||
resolve(); | ||
if (typeof window !== 'undefined') { | ||
if (typeof window.io !== 'undefined') { | ||
window.vc_io = window.io; | ||
|
||
if (originalIo) { | ||
window.io = originalIo; | ||
} | ||
|
||
resolve(); | ||
} else { | ||
reject(new Error('socket.io-client was not loaded correctly.')); | ||
} | ||
} | ||
}; | ||
|
||
script.onerror = () => { | ||
reject(); | ||
reject(new Error('Failed to load the script.')); | ||
}; | ||
document.body.append(script); | ||
|
||
document.body.appendChild(script); | ||
}); | ||
} |