(socket)
| 330 | } |
| 331 | |
| 332 | function extractNoteIdFromSocket (socket) { |
| 333 | function extractNoteIdFromReferer (referer) { |
| 334 | if (referer) { |
| 335 | const hostUrl = parseUrl(referer) |
| 336 | if (!hostUrl) { |
| 337 | return false |
| 338 | } |
| 339 | if (config.urlPath) { |
| 340 | return hostUrl.pathname.slice(config.urlPath.length + 1, hostUrl.pathname.length).split('/')[1] |
| 341 | } |
| 342 | return hostUrl.pathname.split('/')[1] |
| 343 | } |
| 344 | return false |
| 345 | } |
| 346 | |
| 347 | if (!socket || !socket.handshake) { |
| 348 | return false |
| 349 | } |
| 350 | |
| 351 | if (get(socket, 'handshake.query.noteId')) { |
| 352 | return decodeURIComponent(socket.handshake.query.noteId) |
| 353 | } |
| 354 | |
| 355 | const referer = get(socket, 'handshake.headers.referer') |
| 356 | if (referer) { |
| 357 | // this part is only for backward compatibility only; current code |
| 358 | // should be using noteId query parameter instead. |
| 359 | return extractNoteIdFromReferer(referer) |
| 360 | } |
| 361 | |
| 362 | return false |
| 363 | } |
| 364 | |
| 365 | async function parseNoteIdFromSocketAsync (socket) { |
| 366 | const noteId = extractNoteIdFromSocket(socket) |
no test coverage detected