forked from Chocobozzz/PeerTube
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
23 changed files
with
474 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
packages/models/src/videos/stats/video-stats-user-agent.model.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type VideoStatsUserAgent = { | ||
[key in 'browser' | 'device' | 'operatingSystem']: { | ||
name: string | ||
viewers: number | ||
}[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
packages/tests/src/api/views/video-views-user-agent-stats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import { buildUUID } from '@peertube/peertube-node-utils' | ||
import { PeerTubeServer, cleanupTests, waitJobs } from '@peertube/peertube-server-commands' | ||
import { prepareViewsServers, processViewersStats } from '@tests/shared/views.js' | ||
import { expect } from 'chai' | ||
|
||
// eslint-disable-next-line max-len | ||
const EDGE_WINDOWS_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/132.0.0.0' | ||
// eslint-disable-next-line max-len | ||
const EDGE_ANDROID_USER_AGENT = 'Mozilla/5.0 (Linux; Android 10; HD1913) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.6943.49 Mobile Safari/537.36 EdgA/131.0.2903.87' | ||
const CHROME_LINUX_USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36' | ||
|
||
describe('Test views user agent stats', function () { | ||
let server: PeerTubeServer | ||
|
||
before(async function () { | ||
this.timeout(120000) | ||
|
||
const servers = await prepareViewsServers({ singleServer: true }) | ||
server = servers[0] | ||
}) | ||
|
||
it('Should report browser, device and OS', async function () { | ||
this.timeout(240000) | ||
|
||
const { uuid } = await server.videos.quickUpload({ name: 'video' }) | ||
await waitJobs(server) | ||
|
||
await server.views.simulateView({ | ||
id: uuid, | ||
sessionId: buildUUID(), | ||
userAgent: EDGE_ANDROID_USER_AGENT | ||
}) | ||
await server.views.simulateView({ | ||
id: uuid, | ||
sessionId: buildUUID(), | ||
userAgent: EDGE_WINDOWS_USER_AGENT | ||
}) | ||
await server.views.simulateView({ | ||
id: uuid, | ||
sessionId: buildUUID(), | ||
userAgent: CHROME_LINUX_USER_AGENT | ||
}) | ||
|
||
await processViewersStats([ server ]) | ||
|
||
const stats = await server.videoStats.getUserAgentStats({ videoId: uuid }) | ||
|
||
expect(stats.browser).to.include.deep.members([ { name: 'Chrome', viewers: 1 } ]) | ||
expect(stats.browser).to.include.deep.members([ { name: 'Edge', viewers: 2 } ]) | ||
|
||
expect(stats.device).to.include.deep.members([ { name: 'unknown', viewers: 2 } ]) | ||
expect(stats.device).to.include.deep.members([ { name: 'mobile', viewers: 1 } ]) | ||
|
||
expect(stats.operatingSystem).to.include.deep.members([ { name: 'Android', viewers: 1 } ]) | ||
expect(stats.operatingSystem).to.include.deep.members([ { name: 'Linux', viewers: 1 } ]) | ||
expect(stats.operatingSystem).to.include.deep.members([ { name: 'Windows', viewers: 1 } ]) | ||
}) | ||
|
||
after(async function () { | ||
await cleanupTests([ server ]) | ||
}) | ||
}) |
Oops, something went wrong.