Skip to content

Commit

Permalink
chore: add more logs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CCharlieLi committed Feb 23, 2021
1 parent 59a345b commit 6982dec
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Apsara.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export class Apsara {
* Create ingest URL with signature
*/
getIngestUrl({ domain, appName, streamName, expiredIn, key }: ApsaraIngestUrlParams): Promise<URL> {
this.logger?.info(
`Create ingest url with domain:${domain}, appName: ${appName}, streamName: ${streamName}, expiredIn: ${expiredIn}`
)
const protocol = 'rtmp:'
const extension = this._getFileExtension('rtmp' as ApsaraProtocal)
return this._generateUrl({ protocol, domain, appName, streamName, extension, expiredIn, key })
Expand All @@ -69,6 +72,10 @@ export class Apsara {
format,
isSecure
}: ApsaraStreamingUrlParams): Promise<URL> {
this.logger?.info(
`Create streaming url with domain:${domain}, appName: ${appName}, ` +
`streamName: ${streamName}, expiredIn: ${expiredIn}, format: ${format}, isSecure: ${isSecure}`
)
const protocol = this._getProtocol(format, isSecure)
const extension = this._getFileExtension(format)
return this._generateUrl({ protocol, domain, appName, streamName, extension, expiredIn, key })
Expand Down
34 changes: 33 additions & 1 deletion src/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('Unit test', () => {
expect(url.pathname).toBe('/testApp/testStream')
})

it('should get streaming url successfully', async () => {
it('should get streaming url successfully - m3u8', async () => {
const url: URL = await apsara.getVideoStreamingUrl({
domain: 'eko.com',
appName: 'testApp',
Expand All @@ -115,5 +115,37 @@ describe('Unit test', () => {
expect(url.host).toBe('eko.com')
expect(url.pathname).toBe('/testApp/testStream.m3u8')
})

it('should get streaming url successfully - flv', async () => {
const url: URL = await apsara.getVideoStreamingUrl({
domain: 'eko.com',
appName: 'testApp',
streamName: 'testStream',
expiredIn: 3600,
key: 'testKey',
format: 'flv',
isSecure: true
})

expect(url.protocol).toBe('https:')
expect(url.host).toBe('eko.com')
expect(url.pathname).toBe('/testApp/testStream.flv')
})

it('should get streaming url successfully - rtmp', async () => {
const url: URL = await apsara.getVideoStreamingUrl({
domain: 'eko.com',
appName: 'testApp',
streamName: 'testStream',
expiredIn: 3600,
key: 'testKey',
format: 'rtmp',
isSecure: true
})

expect(url.protocol).toBe('rtmp:')
expect(url.host).toBe('eko.com')
expect(url.pathname).toBe('/testApp/testStream')
})
})
})

0 comments on commit 6982dec

Please sign in to comment.