mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #1508 from sharelatex/bg-add-websocket-fallback-option
add fallback to siteUrl if websocket fails GitOrigin-RevId: fd866d17475cb974e4158ac7a89e972c66f0dd97
This commit is contained in:
parent
c4dd8b5da8
commit
00cdc008d5
3 changed files with 28 additions and 1 deletions
|
@ -275,6 +275,10 @@ module.exports = ProjectController =
|
||||||
project_id = req.params.Project_id
|
project_id = req.params.Project_id
|
||||||
logger.log project_id:project_id, anonymous:anonymous, user_id:user_id, "loading editor"
|
logger.log project_id:project_id, anonymous:anonymous, user_id:user_id, "loading editor"
|
||||||
|
|
||||||
|
# record failures to load the custom websocket
|
||||||
|
if req.query?.ws is 'fallback'
|
||||||
|
metrics.inc "load-editor-ws-fallback"
|
||||||
|
|
||||||
async.auto {
|
async.auto {
|
||||||
project: (cb)->
|
project: (cb)->
|
||||||
ProjectGetter.getProject(
|
ProjectGetter.getProject(
|
||||||
|
|
|
@ -185,7 +185,13 @@ define([
|
||||||
|
|
||||||
ide.validFileRegex = '^[^*/]*$' // Don't allow * and /
|
ide.validFileRegex = '^[^*/]*$' // Don't allow * and /
|
||||||
|
|
||||||
ide.wsUrl = window.sharelatex.wsUrl || null // websocket url (if defined)
|
let useFallbackWebsocket =
|
||||||
|
window.location &&
|
||||||
|
window.location.search &&
|
||||||
|
window.location.search.match(/ws=fallback/)
|
||||||
|
// if we previously failed to load the websocket fall back to null (the siteUrl)
|
||||||
|
ide.wsUrl = useFallbackWebsocket ? null : window.sharelatex.wsUrl || null // websocket url (if defined)
|
||||||
|
|
||||||
ide.project_id = $scope.project_id = window.project_id
|
ide.project_id = $scope.project_id = window.project_id
|
||||||
ide.$scope = $scope
|
ide.$scope = $scope
|
||||||
|
|
||||||
|
|
|
@ -103,6 +103,23 @@ define([], function() {
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// handle network-level websocket errors (e.g. failed dns lookups)
|
||||||
|
|
||||||
|
this.ide.socket.on('error', err => {
|
||||||
|
sl_console.log('socket.io error', err)
|
||||||
|
if (this.wsUrl && !window.location.href.match(/ws=fallback/)) {
|
||||||
|
// if we tried to load a custom websocket location and failed
|
||||||
|
// try reloading and falling back to the siteUrl
|
||||||
|
window.location = window.location.href + '?ws=fallback'
|
||||||
|
} else {
|
||||||
|
this.connected = false
|
||||||
|
return this.$scope.$apply(() => {
|
||||||
|
return (this.$scope.state.error =
|
||||||
|
"Unable to connect, please view the <u><a href='/learn/Kb/Connection_problems'>connection problems guide</a></u> to fix the issue.")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// The "connect" event is the first event we get back. It only
|
// The "connect" event is the first event we get back. It only
|
||||||
// indicates that the websocket is connected, we still need to
|
// indicates that the websocket is connected, we still need to
|
||||||
// pass authentication to join a project.
|
// pass authentication to join a project.
|
||||||
|
|
Loading…
Reference in a new issue