From c43ed8e8624383db5a0cf22b210cee202bae323c Mon Sep 17 00:00:00 2001 From: kontrollanten <6680299+kontrollanten@users.noreply.github.com> Date: Mon, 10 Oct 2022 15:18:31 +0200 Subject: Expose PeerTube socket to plugins (#5239) * server(pluginHelpers): add socket * test(plugins): add socket cases * fixes after review * Update plugin-helpers.ts * Update plugin-helpers.ts --- .../fixtures/peertube-plugin-test-four/main.js | 16 +++++++++++++ server/tests/plugins/plugin-helpers.ts | 27 ++++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'server/tests') diff --git a/server/tests/fixtures/peertube-plugin-test-four/main.js b/server/tests/fixtures/peertube-plugin-test-four/main.js index 5194e3e02..3e848c49e 100644 --- a/server/tests/fixtures/peertube-plugin-test-four/main.js +++ b/server/tests/fixtures/peertube-plugin-test-four/main.js @@ -128,6 +128,22 @@ async function register ({ return res.json(result) }) + + router.post('/send-notification', async (req, res) => { + peertubeHelpers.socket.sendNotification(req.body.userId, { + type: 1, + userId: req.body.userId + }) + + return res.sendStatus(201) + }) + + router.post('/send-video-live-new-state/:uuid', async (req, res) => { + const video = await peertubeHelpers.videos.loadByIdOrUUID(req.params.uuid) + peertubeHelpers.socket.sendVideoLiveNewState(video) + + return res.sendStatus(201) + }) } } diff --git a/server/tests/plugins/plugin-helpers.ts b/server/tests/plugins/plugin-helpers.ts index 955d7ddfd..31c18350a 100644 --- a/server/tests/plugins/plugin-helpers.ts +++ b/server/tests/plugins/plugin-helpers.ts @@ -83,6 +83,33 @@ describe('Test plugin helpers', function () { }) }) + describe('Socket', function () { + + it('Should sendNotification without any exceptions', async () => { + const user = await servers[0].users.create({ username: 'notis_redding', password: 'secret1234?' }) + await makePostBodyRequest({ + url: servers[0].url, + path: '/plugins/test-four/router/send-notification', + fields: { + userId: user.id + }, + expectedStatus: HttpStatusCode.CREATED_201 + }) + }) + + it('Should sendVideoLiveNewState without any exceptions', async () => { + const res = await servers[0].videos.quickUpload({ name: 'video server 1' }) + + await makePostBodyRequest({ + url: servers[0].url, + path: '/plugins/test-four/router/send-video-live-new-state/' + res.uuid, + expectedStatus: HttpStatusCode.CREATED_201 + }) + + await servers[0].videos.remove({ id: res.uuid }) + }) + }) + describe('Plugin', function () { it('Should get the base static route', async function () { -- cgit v1.2.3