Merge pull request #2890 from overleaf/jpa-socket-io-secondary-id

[misc] socket.io: use a secondary publicId for public facing usages

GitOrigin-RevId: f472c90ce0706aaf409e63c4199e71899b1aefa3
This commit is contained in:
Jakob Ackermann 2020-06-08 10:29:36 +02:00 committed by Copybot
parent 6c614a6adc
commit 9eaa1f9677
3 changed files with 8 additions and 5 deletions

View file

@ -177,7 +177,8 @@ export default (ConnectionManager = (function() {
// from the server, either "connectionAccepted" or
// "connectionRejected".
this.ide.socket.on('connectionAccepted', message => {
this.ide.socket.on('connectionAccepted', (_, publicId) => {
this.ide.socket.publicId = publicId || this.ide.socket.socket.sessionid
// state should be 'authenticating'...
sl_console.log('[socket.io connectionAccepted] allowed to connect')
this.connected = true

View file

@ -18,6 +18,7 @@
*/
import EventEmitter from '../../utils/EventEmitter'
import ShareJs from 'libs/sharejs'
let ShareJsDoc
const SINGLE_USER_FLUSH_DELAY = 1000 // ms
@ -77,7 +78,7 @@ export default (ShareJsDoc = (function() {
)
},
state: 'ok',
id: this.socket.socket.sessionid
id: this.socket.publicId
}
this._doc = new ShareJs.Doc(this.connection, this.doc_id, {
@ -257,7 +258,7 @@ export default (ShareJsDoc = (function() {
updateConnectionState(state) {
sl_console.log(`[updateConnectionState] Setting state to ${state}`)
this.connection.state = state
this.connection.id = this.socket.socket.sessionid
this.connection.id = this.socket.publicId
this._doc.autoOpen = false
this._doc._connectionStateChanged(state)
return (this.lastAcked = null) // reset the last ack time when connection changes

View file

@ -17,6 +17,7 @@
import ColorManager from '../colors/ColorManager'
import 'crypto-js/md5'
import './controllers/OnlineUsersController'
let OnlineUsersManager
export default (OnlineUsersManager = (function() {
@ -42,7 +43,7 @@ export default (OnlineUsersManager = (function() {
(error, connectedUsers) => {
this.$scope.onlineUsers = {}
for (let user of Array.from(connectedUsers || [])) {
if (user.client_id === this.ide.socket.socket.sessionid) {
if (user.client_id === this.ide.socket.publicId) {
// Don't store myself
continue
}
@ -66,7 +67,7 @@ export default (OnlineUsersManager = (function() {
})
this.ide.socket.on('clientTracking.clientUpdated', client => {
if (client.id !== this.ide.socket.socket.sessionid) {
if (client.id !== this.ide.socket.publicId) {
// Check it's not me!
return this.$scope.$apply(() => {
this.$scope.onlineUsers[client.id] = client