This repository has been archived by the owner on Sep 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add methods for joining and leaving live streams (#28)
- Loading branch information
Showing
7 changed files
with
201 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { BaseResponseData } from './request'; | ||
import { CommonUserDetails } from './user'; | ||
|
||
export interface LiveStreamRequest { | ||
/** The ID of the live stream to join or leave */ | ||
room_id: string; | ||
} | ||
|
||
export interface JoinLiveStreamResponse extends BaseResponseData { | ||
/** Details about the live stream */ | ||
room: LiveStream; | ||
} | ||
|
||
export interface LiveStream { | ||
/** The timestamp in seconds when the stream was created */ | ||
create_time: number; | ||
|
||
/** The timestamp in seconds when this request was processed */ | ||
finish_time: number; | ||
|
||
/** Details about the user hosting the stream */ | ||
owner: CommonUserDetails; | ||
|
||
/** The ID of the stream */ | ||
room_id: string; | ||
|
||
/** ??? */ | ||
status: number; | ||
|
||
/** The ID used in the stream URL */ | ||
stream_id: string; | ||
|
||
/** Contains a link to the stream */ | ||
stream_url: { | ||
/** A link to the stream source */ | ||
rtmp_pull_url: string; | ||
|
||
/** The ID used in the stream URL */ | ||
sid: string; | ||
}; | ||
|
||
/** The title of the stream */ | ||
title: string; | ||
|
||
/** The number of users currently in the stream */ | ||
user_count: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import MockAdapter from 'axios-mock-adapter'; | ||
import { assert } from 'chai'; | ||
import { describe, it } from 'mocha'; | ||
|
||
import TikTokAPI, { BaseResponseData, CommonUserDetails, JoinLiveStreamResponse } from '../src'; | ||
import { | ||
loadTestData, | ||
mockConfig, | ||
mockParams, | ||
} from './util'; | ||
|
||
describe('#joinLiveStream()', () => { | ||
it('a successful response should match the interface', async () => { | ||
const api = new TikTokAPI(mockParams, mockConfig); | ||
const mock = new MockAdapter(api.request); | ||
mock | ||
.onGet(new RegExp('aweme/v1/room/enter/\?.*')) | ||
.reply(200, loadTestData('joinLiveStream.json'), {}); | ||
|
||
const roomId = '9999999999999999999'; | ||
const streamId = '9000000000000000000'; | ||
const res = await api.joinLiveStream(roomId); | ||
const expected: JoinLiveStreamResponse = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
room: { | ||
create_time: 1000000000, | ||
finish_time: 1000000001, | ||
owner: {} as CommonUserDetails, | ||
room_id: roomId, | ||
status: 0, | ||
stream_id: streamId, | ||
stream_url: { | ||
rtmp_pull_url: `http://pull-flv-l1-mus.pstatp.com/hudong/stream-${streamId}.flv`, | ||
sid: streamId, | ||
}, | ||
title: 'Example', | ||
user_count: 1000, | ||
}, | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); | ||
|
||
describe('#leaveLiveStream()', () => { | ||
it('a successful response should match the interface', async () => { | ||
const api = new TikTokAPI(mockParams, mockConfig); | ||
const mock = new MockAdapter(api.request); | ||
mock | ||
.onGet(new RegExp('aweme/v1/room/leave/\?.*')) | ||
.reply(200, loadTestData('leaveLiveStream.json'), {}); | ||
|
||
const roomId = '9999999999999999999'; | ||
const res = await api.leaveLiveStream(roomId); | ||
const expected: BaseResponseData = { | ||
extra: { | ||
now: 1000000000000, | ||
}, | ||
status_code: 0, | ||
}; | ||
assert.deepStrictEqual(res.data, expected); | ||
}); | ||
}); |
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,20 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"room": { | ||
"create_time": 1000000000, | ||
"finish_time": 1000000001, | ||
"owner": {}, | ||
"room_id": 9999999999999999999, | ||
"status": 0, | ||
"stream_id": 9000000000000000000, | ||
"stream_url": { | ||
"rtmp_pull_url": "http://pull-flv-l1-mus.pstatp.com/hudong/stream-9000000000000000000.flv", | ||
"sid": 9000000000000000000 | ||
}, | ||
"title": "Example", | ||
"user_count": 1000 | ||
}, | ||
"status_code": 0 | ||
} |
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 @@ | ||
{ | ||
"extra": { | ||
"now": 1000000000000 | ||
}, | ||
"status_code": 0 | ||
} |