Skip to content

Commit f3358b4

Browse files
authored
Merge pull request #716 from stbuehler/fix-referer
don't require referer to find note id in socket.io connections (fixes #623)
2 parents 2024262 + c4f8fb7 commit f3358b4

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

lib/realtime.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,16 +272,24 @@ function isReady () {
272272
}
273273

274274
function extractNoteIdFromSocket (socket) {
275-
if (!socket || !socket.handshake || !socket.handshake.headers) {
275+
if (!socket || !socket.handshake) {
276276
return false
277277
}
278-
var referer = socket.handshake.headers.referer
279-
if (!referer) {
278+
if (socket.handshake.query && socket.handshake.query.noteId) {
279+
return socket.handshake.query.noteId
280+
} else if (socket.handshake.headers) {
281+
// this part is only for backward compatibility only; current code
282+
// should be using noteId query parameter instead.
283+
var referer = socket.handshake.headers.referer
284+
if (!referer) {
285+
return false
286+
}
287+
var hostUrl = url.parse(referer)
288+
var noteId = config.urlpath ? hostUrl.pathname.slice(config.urlpath.length + 1, hostUrl.pathname.length).split('/')[1] : hostUrl.pathname.split('/')[1]
289+
return noteId
290+
} else {
280291
return false
281292
}
282-
var hostUrl = url.parse(referer)
283-
var noteId = config.urlpath ? hostUrl.pathname.slice(config.urlpath.length + 1, hostUrl.pathname.length).split('/')[1] : hostUrl.pathname.split('/')[1]
284-
return noteId
285293
}
286294

287295
function parseNoteIdFromSocket (socket, callback) {

public/js/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,6 +1762,9 @@ window.havePermission = havePermission
17621762
var io = require('socket.io-client')
17631763
var socket = io.connect({
17641764
path: urlpath ? '/' + urlpath + '/socket.io/' : '',
1765+
query: {
1766+
noteId: noteid
1767+
},
17651768
timeout: 5000, // 5 secs to timeout,
17661769
reconnectionAttempts: 20 // retry 20 times on connect failed
17671770
})

0 commit comments

Comments
 (0)