diff options
author | Chocobozzz <me@florianbigard.com> | 2023-07-31 14:34:36 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-11 15:02:33 +0200 |
commit | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (patch) | |
tree | e4510b39bdac9c318fdb4b47018d08f15368b8f0 /server/tests/api/live/live-rtmps.ts | |
parent | 04d1da5621d25d59bd5fa1543b725c497bf5d9a8 (diff) | |
download | PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.gz PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.tar.zst PeerTube-3a4992633ee62d5edfbb484d9c6bcb3cf158489d.zip |
Migrate server to ESM
Sorry for the very big commit that may lead to git log issues and merge
conflicts, but it's a major step forward:
* Server can be faster at startup because imports() are async and we can
easily lazy import big modules
* Angular doesn't seem to support ES import (with .js extension), so we
had to correctly organize peertube into a monorepo:
* Use yarn workspace feature
* Use typescript reference projects for dependencies
* Shared projects have been moved into "packages", each one is now a
node module (with a dedicated package.json/tsconfig.json)
* server/tools have been moved into apps/ and is now a dedicated app
bundled and published on NPM so users don't have to build peertube
cli tools manually
* server/tests have been moved into packages/ so we don't compile
them every time we want to run the server
* Use isolatedModule option:
* Had to move from const enum to const
(https://www.typescriptlang.org/docs/handbook/enums.html#objects-vs-enums)
* Had to explictely specify "type" imports when used in decorators
* Prefer tsx (that uses esbuild under the hood) instead of ts-node to
load typescript files (tests with mocha or scripts):
* To reduce test complexity as esbuild doesn't support decorator
metadata, we only test server files that do not import server
models
* We still build tests files into js files for a faster CI
* Remove unmaintained peertube CLI import script
* Removed some barrels to speed up execution (less imports)
Diffstat (limited to 'server/tests/api/live/live-rtmps.ts')
-rw-r--r-- | server/tests/api/live/live-rtmps.ts | 143 |
1 files changed, 0 insertions, 143 deletions
diff --git a/server/tests/api/live/live-rtmps.ts b/server/tests/api/live/live-rtmps.ts deleted file mode 100644 index dcaee90cf..000000000 --- a/server/tests/api/live/live-rtmps.ts +++ /dev/null | |||
@@ -1,143 +0,0 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { buildAbsoluteFixturePath } from '@shared/core-utils' | ||
5 | import { VideoPrivacy } from '@shared/models' | ||
6 | import { | ||
7 | cleanupTests, | ||
8 | createSingleServer, | ||
9 | PeerTubeServer, | ||
10 | sendRTMPStream, | ||
11 | setAccessTokensToServers, | ||
12 | setDefaultVideoChannel, | ||
13 | stopFfmpeg, | ||
14 | testFfmpegStreamError, | ||
15 | waitUntilLivePublishedOnAllServers | ||
16 | } from '@shared/server-commands' | ||
17 | |||
18 | describe('Test live RTMPS', function () { | ||
19 | let server: PeerTubeServer | ||
20 | let rtmpUrl: string | ||
21 | let rtmpsUrl: string | ||
22 | |||
23 | async function createLiveWrapper () { | ||
24 | const liveAttributes = { | ||
25 | name: 'live', | ||
26 | channelId: server.store.channel.id, | ||
27 | privacy: VideoPrivacy.PUBLIC, | ||
28 | saveReplay: false | ||
29 | } | ||
30 | |||
31 | const { uuid } = await server.live.create({ fields: liveAttributes }) | ||
32 | |||
33 | const live = await server.live.get({ videoId: uuid }) | ||
34 | const video = await server.videos.get({ id: uuid }) | ||
35 | |||
36 | return Object.assign(video, live) | ||
37 | } | ||
38 | |||
39 | before(async function () { | ||
40 | this.timeout(120000) | ||
41 | |||
42 | server = await createSingleServer(1) | ||
43 | |||
44 | // Get the access tokens | ||
45 | await setAccessTokensToServers([ server ]) | ||
46 | await setDefaultVideoChannel([ server ]) | ||
47 | |||
48 | await server.config.updateCustomSubConfig({ | ||
49 | newConfig: { | ||
50 | live: { | ||
51 | enabled: true, | ||
52 | allowReplay: true, | ||
53 | transcoding: { | ||
54 | enabled: false | ||
55 | } | ||
56 | } | ||
57 | } | ||
58 | }) | ||
59 | |||
60 | rtmpUrl = 'rtmp://' + server.hostname + ':' + server.rtmpPort + '/live' | ||
61 | rtmpsUrl = 'rtmps://' + server.hostname + ':' + server.rtmpsPort + '/live' | ||
62 | }) | ||
63 | |||
64 | it('Should enable RTMPS endpoint only', async function () { | ||
65 | this.timeout(240000) | ||
66 | |||
67 | await server.kill() | ||
68 | await server.run({ | ||
69 | live: { | ||
70 | rtmp: { | ||
71 | enabled: false | ||
72 | }, | ||
73 | rtmps: { | ||
74 | enabled: true, | ||
75 | port: server.rtmpsPort, | ||
76 | key_file: buildAbsoluteFixturePath('rtmps.key'), | ||
77 | cert_file: buildAbsoluteFixturePath('rtmps.cert') | ||
78 | } | ||
79 | } | ||
80 | }) | ||
81 | |||
82 | { | ||
83 | const liveVideo = await createLiveWrapper() | ||
84 | |||
85 | expect(liveVideo.rtmpUrl).to.not.exist | ||
86 | expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl) | ||
87 | |||
88 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey }) | ||
89 | await testFfmpegStreamError(command, true) | ||
90 | } | ||
91 | |||
92 | { | ||
93 | const liveVideo = await createLiveWrapper() | ||
94 | |||
95 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey }) | ||
96 | await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) | ||
97 | await stopFfmpeg(command) | ||
98 | } | ||
99 | }) | ||
100 | |||
101 | it('Should enable both RTMP and RTMPS', async function () { | ||
102 | this.timeout(240000) | ||
103 | |||
104 | await server.kill() | ||
105 | await server.run({ | ||
106 | live: { | ||
107 | rtmp: { | ||
108 | enabled: true, | ||
109 | port: server.rtmpPort | ||
110 | }, | ||
111 | rtmps: { | ||
112 | enabled: true, | ||
113 | port: server.rtmpsPort, | ||
114 | key_file: buildAbsoluteFixturePath('rtmps.key'), | ||
115 | cert_file: buildAbsoluteFixturePath('rtmps.cert') | ||
116 | } | ||
117 | } | ||
118 | }) | ||
119 | |||
120 | { | ||
121 | const liveVideo = await createLiveWrapper() | ||
122 | |||
123 | expect(liveVideo.rtmpUrl).to.equal(rtmpUrl) | ||
124 | expect(liveVideo.rtmpsUrl).to.equal(rtmpsUrl) | ||
125 | |||
126 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpUrl, streamKey: liveVideo.streamKey }) | ||
127 | await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) | ||
128 | await stopFfmpeg(command) | ||
129 | } | ||
130 | |||
131 | { | ||
132 | const liveVideo = await createLiveWrapper() | ||
133 | |||
134 | const command = sendRTMPStream({ rtmpBaseUrl: rtmpsUrl, streamKey: liveVideo.streamKey }) | ||
135 | await waitUntilLivePublishedOnAllServers([ server ], liveVideo.uuid) | ||
136 | await stopFfmpeg(command) | ||
137 | } | ||
138 | }) | ||
139 | |||
140 | after(async function () { | ||
141 | await cleanupTests([ server ]) | ||
142 | }) | ||
143 | }) | ||