1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 09:49:20 +02:00

Use sessionId instead of IP to identify viewer

Breaking: YAML config `ip_view_expiration` is renamed `view_expiration`
Breaking: Views are taken into account after 10 seconds instead of 30
seconds (can be changed in YAML config)

Purpose of this commit is to get closer to other video platforms where
some platforms count views on play (mux, vimeo) or others use a very low
delay (instagram, tiktok)

We also want to improve the viewer identification, where we no longer
use the IP but the `sessionId` generated by the web browser. Multiple
viewers behind a NAT can now be able to be identified as independent
viewers (this method is also used by vimeo or mux)
This commit is contained in:
Chocobozzz 2024-04-04 11:30:30 +02:00
parent 6f6abcabfb
commit 5cb3e6a0b8
No known key found for this signature in database
GPG key ID: 583A612D890159BE
25 changed files with 913 additions and 660 deletions

View file

@ -9,8 +9,9 @@ export class ViewsCommand extends AbstractCommand {
currentTime: number
viewEvent?: VideoViewEvent
xForwardedFor?: string
sessionId?: string
}) {
const { id, xForwardedFor, viewEvent, currentTime } = options
const { id, xForwardedFor, viewEvent, currentTime, sessionId } = options
const path = '/api/v1/videos/' + id + '/views'
return this.postBodyRequest({
@ -20,7 +21,8 @@ export class ViewsCommand extends AbstractCommand {
xForwardedFor,
fields: {
currentTime,
viewEvent
viewEvent,
sessionId
},
implicitToken: false,
defaultExpectedStatus: HttpStatusCode.NO_CONTENT_204
@ -30,6 +32,7 @@ export class ViewsCommand extends AbstractCommand {
async simulateView (options: OverrideCommandOptions & {
id: number | string
xForwardedFor?: string
sessionId?: string
}) {
await this.view({ ...options, currentTime: 0 })
await this.view({ ...options, currentTime: 5 })
@ -39,6 +42,7 @@ export class ViewsCommand extends AbstractCommand {
id: number | string
currentTimes: number[]
xForwardedFor?: string
sessionId?: string
}) {
let viewEvent: VideoViewEvent = 'seek'