Просмотр исходного кода

Merge pull request #16001 from overleaf/jpa-web-real-time-auto-join-only

[web] drop support for legacy real-time connection

GitOrigin-RevId: d03aae6392a8d920239647ab198d66d6c75f61a0
Jakob Ackermann 2 лет назад
Родитель
Сommit
6b19cae812

+ 0 - 1
services/web/app/src/Features/Project/ProjectController.js

@@ -864,7 +864,6 @@ const ProjectController = {
               },
               privilegeLevel,
               anonymous,
-              anonymousAccessToken: anonymous ? anonRequestToken : null,
               isTokenMember,
               isRestrictedTokenMember: AuthorizationManager.isRestrictedUser(
                 userId,

+ 0 - 1
services/web/app/views/project/editor/meta.pug

@@ -5,7 +5,6 @@ meta(name="ol-user" data-type="json" content=user)
 meta(name="ol-learnedWords" data-type="json" content=learnedWords)
 meta(name="ol-anonymous" data-type="boolean" content=anonymous)
 meta(name="ol-brandVariation" data-type="json" content=brandVariation)
-meta(name="ol-anonymousAccessToken" content=anonymousAccessToken)
 meta(name="ol-isTokenMember" data-type="boolean" content=isTokenMember)
 meta(name="ol-isRestrictedTokenMember" data-type="boolean" content=isRestrictedTokenMember)
 meta(name="ol-maxDocLength" data-type="json" content=maxDocLength)

+ 2 - 104
services/web/frontend/js/ide/connection/ConnectionManager.js

@@ -27,8 +27,6 @@ export default ConnectionManager = (function () {
       this.prototype.MIN_RETRY_INTERVAL = 1000 // ms, rate limit on reconnects for user clicking "try now"
       this.prototype.BACKGROUND_RETRY_INTERVAL = 5 * 1000
 
-      this.prototype.JOIN_PROJECT_RETRY_INTERVAL = 5000
-      this.prototype.JOIN_PROJECT_MAX_RETRY_INTERVAL = 60000
       this.prototype.RECONNECT_GRACEFULLY_RETRY_INTERVAL = 5000 // ms
       this.prototype.MAX_RECONNECT_GRACEFULLY_INTERVAL = 45 * 1000
     }
@@ -76,8 +74,6 @@ export default ConnectionManager = (function () {
       this.gracefullyReconnecting = false
       this.shuttingDown = false
 
-      this.joinProjectRetryInterval = this.JOIN_PROJECT_RETRY_INTERVAL
-
       this.$scope.connection = {
         debug: debugging,
         reconnecting: false,
@@ -186,31 +182,7 @@ export default ConnectionManager = (function () {
       })
 
       // The next event we should get is an authentication response
-      // from the server, either "connectionAccepted" or "bootstrap" or
-      // "connectionRejected".
-
-      // Handle real-time without bootstrap capability.
-      this.ide.socket.on('connectionAccepted', (_, publicId) => {
-        this.ide.socket.publicId = publicId || this.ide.socket.socket.sessionid
-        // state should be 'authenticating'...
-        debugConsole.log('[socket.io connectionAccepted] allowed to connect')
-        this.connected = true
-        this.gracefullyReconnecting = false
-        this.ide.pushEvent('connected')
-        this.updateConnectionManagerState('joining')
-
-        this.$scope.$apply(() => {
-          if (this.$scope.state.loading) {
-            this.$scope.state.load_progress = 70
-          }
-        })
-
-        // we have passed authentication so we can now join the project
-        const connectionJobId = this.$scope.connection.jobId
-        setTimeout(() => {
-          this.joinProject(connectionJobId)
-        }, 100)
-      })
+      // from the server, either "joinProjectResponse" or "connectionRejected".
 
       this.ide.socket.on(
         'joinProjectResponse',
@@ -229,9 +201,7 @@ export default ConnectionManager = (function () {
             }
           })
 
-          const connectionJobId = this.$scope.connection.jobId
           this.handleJoinProjectResponse({
-            connectionJobId,
             project,
             permissionsLevel,
             protocolVersion,
@@ -425,79 +395,7 @@ Something went wrong connecting to your project. Please refresh if this continue
       }
     }
 
-    joinProject(connectionId) {
-      debugConsole.log(`[joinProject ${connectionId}] joining...`)
-      // Note: if the "joinProject" message doesn't reach the server
-      // (e.g. if we are in a disconnected state at this point) the
-      // callback will never be executed
-      if (!this.expectConnectionManagerState('joining', connectionId)) {
-        debugConsole.log(
-          `[joinProject ${connectionId}] aborting with stale connection`
-        )
-        return
-      }
-      const data = {
-        project_id: this.ide.project_id,
-      }
-      if (window.anonymousAccessToken) {
-        data.anonymousAccessToken = window.anonymousAccessToken
-      }
-      this.ide.socket.emit(
-        'joinProject',
-        data,
-        (err, project, permissionsLevel, protocolVersion) => {
-          this.handleJoinProjectResponse({
-            connectionId,
-            err,
-            project,
-            permissionsLevel,
-            protocolVersion,
-          })
-        }
-      )
-    }
-
-    handleJoinProjectResponse({
-      connectionId,
-      err,
-      project,
-      permissionsLevel,
-      protocolVersion,
-    }) {
-      if (err != null || project == null) {
-        err = err || {}
-        if (err.code === 'ProjectNotFound') {
-          // A stale browser tab tried to join a deleted project.
-          // Reloading the page will render a 404.
-          this.ide
-            .showGenericMessageModal(
-              'Project has been deleted',
-              'This project has been deleted by the owner.'
-            )
-            .result.then(() => location.reload(true))
-          return
-        }
-        if (err.code === 'TooManyRequests') {
-          debugConsole.log(
-            `[joinProject ${connectionId}] retrying: ${err.message}`
-          )
-          setTimeout(
-            () => this.joinProject(connectionId),
-            this.joinProjectRetryInterval
-          )
-          if (
-            this.joinProjectRetryInterval < this.JOIN_PROJECT_MAX_RETRY_INTERVAL
-          ) {
-            this.joinProjectRetryInterval += this.JOIN_PROJECT_RETRY_INTERVAL
-          }
-          return
-        } else {
-          return this.reportConnectionError(err)
-        }
-      }
-
-      this.joinProjectRetryInterval = this.JOIN_PROJECT_RETRY_INTERVAL
-
+    handleJoinProjectResponse({ project, permissionsLevel, protocolVersion }) {
       if (
         this.$scope.protocolVersion != null &&
         this.$scope.protocolVersion !== protocolVersion

+ 9 - 4
services/web/modules/launchpad/frontend/js/pages/launchpad.js

@@ -53,14 +53,19 @@ function setUpStatusIndicators() {
         reconnect: false,
         'connect timeout': timeout,
         'force new connection': true,
+        query: new URLSearchParams({
+          projectId: '404404404404404404404404',
+        }).toString(),
       })
       return new Promise((resolve, reject) => {
         setTimeout(() => reject(new Error('timed out')), timeout)
-        socket.on('connectionAccepted', function () {
-          resolve()
-        })
         socket.on('connectionRejected', function (err) {
-          reject(new Error(err && err.message))
+          if (err.code === 'ProjectNotFound') {
+            // We received the response from joinProject, so the websocket is up.
+            resolve()
+          } else {
+            reject(new Error(err && err.message))
+          }
         })
         socket.on('connect_failed', function (err) {
           reject(new Error(err && err.message))