@streamfarm/sdk 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/LICENSE +21 -0
- package/README.md +291 -2
- package/dist/cjs/chat.d.ts +51 -0
- package/dist/cjs/chat.js +224 -0
- package/dist/cjs/client.d.ts +44 -0
- package/dist/cjs/client.js +64 -0
- package/dist/cjs/errors.d.ts +86 -0
- package/dist/cjs/errors.js +110 -0
- package/dist/cjs/generated/openapi.d.ts +4127 -0
- package/dist/cjs/generated/openapi.js +7 -0
- package/dist/cjs/http.d.ts +81 -0
- package/dist/cjs/http.js +304 -0
- package/dist/cjs/index.d.ts +10 -0
- package/dist/cjs/index.js +22 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/pagination.d.ts +9 -0
- package/dist/cjs/pagination.js +22 -0
- package/dist/cjs/resources/account.d.ts +32 -0
- package/dist/cjs/resources/account.js +58 -0
- package/dist/cjs/resources/ads.d.ts +25 -0
- package/dist/cjs/resources/ads.js +46 -0
- package/dist/cjs/resources/base.d.ts +12 -0
- package/dist/cjs/resources/base.js +23 -0
- package/dist/cjs/resources/comments.d.ts +27 -0
- package/dist/cjs/resources/comments.js +46 -0
- package/dist/cjs/resources/platforms.d.ts +24 -0
- package/dist/cjs/resources/platforms.js +41 -0
- package/dist/cjs/resources/streams.d.ts +39 -0
- package/dist/cjs/resources/streams.js +76 -0
- package/dist/cjs/resources/studio.d.ts +20 -0
- package/dist/cjs/resources/studio.js +39 -0
- package/dist/cjs/types.d.ts +124 -0
- package/dist/cjs/types.js +2 -0
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.js +5 -0
- package/dist/esm/chat.d.ts +51 -0
- package/dist/esm/chat.js +220 -0
- package/dist/esm/client.d.ts +44 -0
- package/dist/esm/client.js +60 -0
- package/dist/esm/errors.d.ts +86 -0
- package/dist/esm/errors.js +94 -0
- package/dist/esm/generated/openapi.d.ts +4127 -0
- package/dist/esm/generated/openapi.js +6 -0
- package/dist/esm/http.d.ts +81 -0
- package/dist/esm/http.js +297 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/pagination.d.ts +9 -0
- package/dist/esm/pagination.js +19 -0
- package/dist/esm/resources/account.d.ts +32 -0
- package/dist/esm/resources/account.js +50 -0
- package/dist/esm/resources/ads.d.ts +25 -0
- package/dist/esm/resources/ads.js +41 -0
- package/dist/esm/resources/base.d.ts +12 -0
- package/dist/esm/resources/base.js +19 -0
- package/dist/esm/resources/comments.d.ts +27 -0
- package/dist/esm/resources/comments.js +42 -0
- package/dist/esm/resources/platforms.d.ts +24 -0
- package/dist/esm/resources/platforms.js +37 -0
- package/dist/esm/resources/streams.d.ts +39 -0
- package/dist/esm/resources/streams.js +72 -0
- package/dist/esm/resources/studio.d.ts +20 -0
- package/dist/esm/resources/studio.js +35 -0
- package/dist/esm/types.d.ts +124 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.js +2 -0
- package/package.json +75 -4
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Resource = void 0;
|
|
4
|
+
/** A part of the API: its methods share the client's transport. */
|
|
5
|
+
class Resource {
|
|
6
|
+
transport;
|
|
7
|
+
constructor(transport) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
}
|
|
10
|
+
/** The answer's `item`. */
|
|
11
|
+
async item(spec, options) {
|
|
12
|
+
return (await this.transport.request(spec, options)).item;
|
|
13
|
+
}
|
|
14
|
+
/** The answer's `items`. */
|
|
15
|
+
async items(spec, options) {
|
|
16
|
+
return (await this.transport.request(spec, options)).items;
|
|
17
|
+
}
|
|
18
|
+
/** A request answered with 204 and no body; a DELETE gone on a retry is done. */
|
|
19
|
+
async none(spec, options) {
|
|
20
|
+
await this.transport.request({ ...spec, goneIsDone: spec.method === 'DELETE' }, options);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.Resource = Resource;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ChatEvent, type WatchOptions } from '../chat.js';
|
|
2
|
+
import { type RequestOptions } from '../http.js';
|
|
3
|
+
import type { Comment, CommentBanParams, CommentCountParams, CommentCounts, CommentListParams, DeletedComment, DeletedCommentListParams } from '../types.js';
|
|
4
|
+
import { Resource } from './base.js';
|
|
5
|
+
/** A stream's chat: comments from every platform. The unified chat comes with the Pro tariff. */
|
|
6
|
+
export declare class Comments extends Resource {
|
|
7
|
+
/**
|
|
8
|
+
* Comments, oldest first (`comments:read`). Without `after` or `since`,
|
|
9
|
+
* the latest `limit`. To follow the chat, use `watch`, or pass the last
|
|
10
|
+
* comment's `uuid` as `after` and drop the ones you have.
|
|
11
|
+
*/
|
|
12
|
+
list(streamId: string, params?: CommentListParams, options?: RequestOptions): Promise<Comment[]>;
|
|
13
|
+
/** Comments the streamer deleted, to drop them from a copy of the chat (`comments:read`). */
|
|
14
|
+
listDeleted(streamId: string, params?: DeletedCommentListParams, options?: RequestOptions): Promise<DeletedComment[]>;
|
|
15
|
+
/** How many comments the chat has, in all and by kind of platform (`comments:read`). */
|
|
16
|
+
counts(streamId: string, params?: CommentCountParams, options?: RequestOptions): Promise<CommentCounts>;
|
|
17
|
+
/** Deletes a comment on its platform and returns it, deleted (`comments:moderate`). */
|
|
18
|
+
delete(streamId: string, commentId: string, options?: RequestOptions): Promise<Comment>;
|
|
19
|
+
/** Bans the comment's author on its platform: for `durationSec` (a timeout), or for good without it (`comments:moderate`). */
|
|
20
|
+
ban(streamId: string, commentId: string, params?: CommentBanParams, options?: RequestOptions): Promise<void>;
|
|
21
|
+
/**
|
|
22
|
+
* Follows the chat: `for await (const event of sf.comments.watch(id))`
|
|
23
|
+
* gives each new comment once and the streamer's deletions, until you
|
|
24
|
+
* break out or `signal` aborts (`comments:read`).
|
|
25
|
+
*/
|
|
26
|
+
watch(streamId: string, options?: WatchOptions): AsyncGenerator<ChatEvent, void, undefined>;
|
|
27
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Comments = void 0;
|
|
4
|
+
const chat_js_1 = require("../chat.js");
|
|
5
|
+
const http_js_1 = require("../http.js");
|
|
6
|
+
const base_js_1 = require("./base.js");
|
|
7
|
+
const commentsPath = (streamId) => `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}/comments`;
|
|
8
|
+
/** A stream's chat: comments from every platform. The unified chat comes with the Pro tariff. */
|
|
9
|
+
class Comments extends base_js_1.Resource {
|
|
10
|
+
/**
|
|
11
|
+
* Comments, oldest first (`comments:read`). Without `after` or `since`,
|
|
12
|
+
* the latest `limit`. To follow the chat, use `watch`, or pass the last
|
|
13
|
+
* comment's `uuid` as `after` and drop the ones you have.
|
|
14
|
+
*/
|
|
15
|
+
async list(streamId, params = {}, options) {
|
|
16
|
+
const { after, since, limit, platformTypes } = params;
|
|
17
|
+
return this.items({ method: 'GET', path: commentsPath(streamId), query: { after, since, limit, platformType: platformTypes } }, options);
|
|
18
|
+
}
|
|
19
|
+
/** Comments the streamer deleted, to drop them from a copy of the chat (`comments:read`). */
|
|
20
|
+
async listDeleted(streamId, params = {}, options) {
|
|
21
|
+
const { since, limit } = params;
|
|
22
|
+
return this.items({ method: 'GET', path: `${commentsPath(streamId)}/deleted`, query: { since, limit } }, options);
|
|
23
|
+
}
|
|
24
|
+
/** How many comments the chat has, in all and by kind of platform (`comments:read`). */
|
|
25
|
+
async counts(streamId, params = {}, options) {
|
|
26
|
+
const { since, platformTypes } = params;
|
|
27
|
+
return this.transport.request({ method: 'GET', path: `${commentsPath(streamId)}/counts`, query: { since, platformType: platformTypes } }, options);
|
|
28
|
+
}
|
|
29
|
+
/** Deletes a comment on its platform and returns it, deleted (`comments:moderate`). */
|
|
30
|
+
async delete(streamId, commentId, options) {
|
|
31
|
+
return this.item({ method: 'DELETE', path: `${commentsPath(streamId)}/${(0, http_js_1.segment)(commentId, 'commentId')}` }, options);
|
|
32
|
+
}
|
|
33
|
+
/** Bans the comment's author on its platform: for `durationSec` (a timeout), or for good without it (`comments:moderate`). */
|
|
34
|
+
async ban(streamId, commentId, params = {}, options) {
|
|
35
|
+
return this.none({ method: 'POST', path: `${commentsPath(streamId)}/${(0, http_js_1.segment)(commentId, 'commentId')}/ban`, body: params }, options);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Follows the chat: `for await (const event of sf.comments.watch(id))`
|
|
39
|
+
* gives each new comment once and the streamer's deletions, until you
|
|
40
|
+
* break out or `signal` aborts (`comments:read`).
|
|
41
|
+
*/
|
|
42
|
+
watch(streamId, options = {}) {
|
|
43
|
+
return (0, chat_js_1.watchChat)(this, streamId, options);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.Comments = Comments;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type RequestOptions } from '../http.js';
|
|
2
|
+
import type { Platform, PlatformCreateParams, PlatformDestinationParams } from '../types.js';
|
|
3
|
+
import { Resource } from './base.js';
|
|
4
|
+
/** Where a stream is pushed: social platforms and RTMP servers. */
|
|
5
|
+
export declare class Platforms extends Resource {
|
|
6
|
+
/** The stream's platforms and their state, without keys (`platforms:read`). */
|
|
7
|
+
list(streamId: string, options?: RequestOptions): Promise<Platform[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Adds a platform (`platforms:write`); a live stream starts pushing to it
|
|
10
|
+
* at once. VK, VK Видео Live and YouTube take nothing but `type` (they use
|
|
11
|
+
* the account's connection), Telegram takes `chat`, OK, Twitch and
|
|
12
|
+
* GoodGame may take `key` (else the one saved in the account), the others
|
|
13
|
+
* need `server` and `key`.
|
|
14
|
+
*/
|
|
15
|
+
add(streamId: string, params: PlatformCreateParams, options?: RequestOptions): Promise<Platform>;
|
|
16
|
+
/** A new server and key; a live platform restarts on them (`platforms:write`). */
|
|
17
|
+
setDestination(streamId: string, platformId: string, params: PlatformDestinationParams, options?: RequestOptions): Promise<Platform>;
|
|
18
|
+
/** Pushes to the platform whenever the stream is live (`platforms:write`). */
|
|
19
|
+
enable(streamId: string, platformId: string, options?: RequestOptions): Promise<Platform>;
|
|
20
|
+
/** Stops pushing to the platform; it stays in the list (`platforms:write`). */
|
|
21
|
+
disable(streamId: string, platformId: string, options?: RequestOptions): Promise<Platform>;
|
|
22
|
+
/** Removes the platform from the stream (`platforms:write`). */
|
|
23
|
+
delete(streamId: string, platformId: string, options?: RequestOptions): Promise<void>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Platforms = void 0;
|
|
4
|
+
const http_js_1 = require("../http.js");
|
|
5
|
+
const base_js_1 = require("./base.js");
|
|
6
|
+
const path = (streamId, platformId) => `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}/platforms`
|
|
7
|
+
+ (platformId === undefined ? '' : `/${(0, http_js_1.segment)(platformId, 'platformId')}`);
|
|
8
|
+
/** Where a stream is pushed: social platforms and RTMP servers. */
|
|
9
|
+
class Platforms extends base_js_1.Resource {
|
|
10
|
+
/** The stream's platforms and their state, without keys (`platforms:read`). */
|
|
11
|
+
async list(streamId, options) {
|
|
12
|
+
return this.items({ method: 'GET', path: path(streamId) }, options);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Adds a platform (`platforms:write`); a live stream starts pushing to it
|
|
16
|
+
* at once. VK, VK Видео Live and YouTube take nothing but `type` (they use
|
|
17
|
+
* the account's connection), Telegram takes `chat`, OK, Twitch and
|
|
18
|
+
* GoodGame may take `key` (else the one saved in the account), the others
|
|
19
|
+
* need `server` and `key`.
|
|
20
|
+
*/
|
|
21
|
+
async add(streamId, params, options) {
|
|
22
|
+
return this.item({ method: 'POST', path: path(streamId), body: params }, options);
|
|
23
|
+
}
|
|
24
|
+
/** A new server and key; a live platform restarts on them (`platforms:write`). */
|
|
25
|
+
async setDestination(streamId, platformId, params, options) {
|
|
26
|
+
return this.item({ method: 'PUT', path: `${path(streamId, platformId)}/destination`, body: params }, options);
|
|
27
|
+
}
|
|
28
|
+
/** Pushes to the platform whenever the stream is live (`platforms:write`). */
|
|
29
|
+
async enable(streamId, platformId, options) {
|
|
30
|
+
return this.item({ method: 'POST', path: `${path(streamId, platformId)}/enable` }, options);
|
|
31
|
+
}
|
|
32
|
+
/** Stops pushing to the platform; it stays in the list (`platforms:write`). */
|
|
33
|
+
async disable(streamId, platformId, options) {
|
|
34
|
+
return this.item({ method: 'POST', path: `${path(streamId, platformId)}/disable` }, options);
|
|
35
|
+
}
|
|
36
|
+
/** Removes the platform from the stream (`platforms:write`). */
|
|
37
|
+
async delete(streamId, platformId, options) {
|
|
38
|
+
return this.none({ method: 'DELETE', path: path(streamId, platformId) }, options);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Platforms = Platforms;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { type RequestOptions } from '../http.js';
|
|
2
|
+
import type { Credentials, Page, Stream, StreamCreateParams, StreamListParams, StreamUpdateParams } from '../types.js';
|
|
3
|
+
import { Resource } from './base.js';
|
|
4
|
+
export interface WaitUntilLiveOptions {
|
|
5
|
+
/** How long to wait, ms; 5 minutes by default. */
|
|
6
|
+
timeout?: number;
|
|
7
|
+
/** How often to look, ms; 5 seconds by default. */
|
|
8
|
+
interval?: number;
|
|
9
|
+
signal?: AbortSignal;
|
|
10
|
+
}
|
|
11
|
+
/** The account's streams. */
|
|
12
|
+
export declare class Streams extends Resource {
|
|
13
|
+
/** A page of the streams the key reaches, newest first (`streams:read`). */
|
|
14
|
+
list(params?: StreamListParams, options?: RequestOptions): Promise<Page<Stream>>;
|
|
15
|
+
/** Every stream the key reaches, page after page: `for await (const stream of sf.streams.all())`. */
|
|
16
|
+
all(params?: Omit<StreamListParams, 'page'>, options?: RequestOptions): AsyncGenerator<Stream, void, undefined>;
|
|
17
|
+
/** Makes a stream (`streams:write`; not with a key limited to some streams). */
|
|
18
|
+
create(params: StreamCreateParams, options?: RequestOptions): Promise<Stream>;
|
|
19
|
+
/** The stream: settings, whether it is live, its limits and figures (`streams:read`). */
|
|
20
|
+
get(streamId: string, options?: RequestOptions): Promise<Stream>;
|
|
21
|
+
/** Changes the given fields only (`streams:write`). The region doesn't change. */
|
|
22
|
+
update(streamId: string, params: StreamUpdateParams, options?: RequestOptions): Promise<Stream>;
|
|
23
|
+
/** Deletes the stream, stopping its broadcast (`streams:write`). */
|
|
24
|
+
delete(streamId: string, options?: RequestOptions): Promise<void>;
|
|
25
|
+
/** Makes a stream frozen past the tariff's the active one (`streams:write`). */
|
|
26
|
+
activate(streamId: string, options?: RequestOptions): Promise<Stream>;
|
|
27
|
+
/**
|
|
28
|
+
* What an encoder publishes with: the RTMP server and key, and WHIP's
|
|
29
|
+
* address and token (`streams:credentials`). With them one broadcasts as
|
|
30
|
+
* the owner: keep them secret.
|
|
31
|
+
*/
|
|
32
|
+
credentials(streamId: string, options?: RequestOptions): Promise<Credentials>;
|
|
33
|
+
/**
|
|
34
|
+
* Waits until the encoder publishes to the stream (`live`) and returns
|
|
35
|
+
* it; WaitTimeoutError if it doesn't in time (`streams:read`). No answer,
|
|
36
|
+
* a server error or the request limit don't end the wait: it looks again.
|
|
37
|
+
*/
|
|
38
|
+
waitUntilLive(streamId: string, options?: WaitUntilLiveOptions): Promise<Stream>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Streams = void 0;
|
|
4
|
+
const errors_js_1 = require("../errors.js");
|
|
5
|
+
const http_js_1 = require("../http.js");
|
|
6
|
+
const pagination_js_1 = require("../pagination.js");
|
|
7
|
+
const base_js_1 = require("./base.js");
|
|
8
|
+
/** The account's streams. */
|
|
9
|
+
class Streams extends base_js_1.Resource {
|
|
10
|
+
/** A page of the streams the key reaches, newest first (`streams:read`). */
|
|
11
|
+
async list(params = {}, options) {
|
|
12
|
+
const { page, size, search } = params;
|
|
13
|
+
return this.transport.request({ method: 'GET', path: '/streams', query: { page, size, search } }, options);
|
|
14
|
+
}
|
|
15
|
+
/** Every stream the key reaches, page after page: `for await (const stream of sf.streams.all())`. */
|
|
16
|
+
all(params = {}, options) {
|
|
17
|
+
return (0, pagination_js_1.paginate)((page) => this.list({ ...params, page }, options));
|
|
18
|
+
}
|
|
19
|
+
/** Makes a stream (`streams:write`; not with a key limited to some streams). */
|
|
20
|
+
async create(params, options) {
|
|
21
|
+
return this.item({ method: 'POST', path: '/streams', body: params }, options);
|
|
22
|
+
}
|
|
23
|
+
/** The stream: settings, whether it is live, its limits and figures (`streams:read`). */
|
|
24
|
+
async get(streamId, options) {
|
|
25
|
+
return this.item({ method: 'GET', path: `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}` }, options);
|
|
26
|
+
}
|
|
27
|
+
/** Changes the given fields only (`streams:write`). The region doesn't change. */
|
|
28
|
+
async update(streamId, params, options) {
|
|
29
|
+
return this.item({ method: 'PATCH', path: `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}`, body: params }, options);
|
|
30
|
+
}
|
|
31
|
+
/** Deletes the stream, stopping its broadcast (`streams:write`). */
|
|
32
|
+
async delete(streamId, options) {
|
|
33
|
+
return this.none({ method: 'DELETE', path: `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}` }, options);
|
|
34
|
+
}
|
|
35
|
+
/** Makes a stream frozen past the tariff's the active one (`streams:write`). */
|
|
36
|
+
async activate(streamId, options) {
|
|
37
|
+
return this.item({ method: 'POST', path: `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}/activate` }, options);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* What an encoder publishes with: the RTMP server and key, and WHIP's
|
|
41
|
+
* address and token (`streams:credentials`). With them one broadcasts as
|
|
42
|
+
* the owner: keep them secret.
|
|
43
|
+
*/
|
|
44
|
+
async credentials(streamId, options) {
|
|
45
|
+
return this.item({ method: 'GET', path: `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}/credentials` }, options);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Waits until the encoder publishes to the stream (`live`) and returns
|
|
49
|
+
* it; WaitTimeoutError if it doesn't in time (`streams:read`). No answer,
|
|
50
|
+
* a server error or the request limit don't end the wait: it looks again.
|
|
51
|
+
*/
|
|
52
|
+
async waitUntilLive(streamId, options = {}) {
|
|
53
|
+
const { timeout = 300_000, interval = 5_000, signal } = options;
|
|
54
|
+
const deadline = Date.now() + timeout;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const left = deadline - Date.now();
|
|
57
|
+
try {
|
|
58
|
+
// Each look within what is left of the wait, and at most 30 s.
|
|
59
|
+
const stream = await this.get(streamId, { signal, maxRetries: 0, timeout: Math.max(1, Math.min(left, 30_000)) });
|
|
60
|
+
if (stream.live)
|
|
61
|
+
return stream;
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
if (signal?.aborted)
|
|
65
|
+
throw signal.reason;
|
|
66
|
+
if (!(error instanceof errors_js_1.ConnectionError || error instanceof errors_js_1.ServerError || error instanceof errors_js_1.RateLimitError))
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
const now = deadline - Date.now();
|
|
70
|
+
if (now <= 0)
|
|
71
|
+
throw new errors_js_1.WaitTimeoutError(`The stream didn't go live within ${timeout} ms`);
|
|
72
|
+
await (0, http_js_1.sleep)(Math.min(interval, now), signal);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.Streams = Streams;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type RequestOptions } from '../http.js';
|
|
2
|
+
import type { RoomToken, Studio as StudioRoom, StudioInvite, StudioInviteCreateParams, StudioInviteCreated, StudioParticipant } from '../types.js';
|
|
3
|
+
import { Resource } from './base.js';
|
|
4
|
+
/** A stream's studio room: guests and their invitations. */
|
|
5
|
+
export declare class Studio extends Resource {
|
|
6
|
+
/** Whether the room can have guests, who is in it and the invitations (`studio:read`). */
|
|
7
|
+
get(streamId: string, options?: RequestOptions): Promise<StudioRoom>;
|
|
8
|
+
/** Who is in the room, on stage and backstage (`studio:read`). */
|
|
9
|
+
participants(streamId: string, options?: RequestOptions): Promise<StudioParticipant[]>;
|
|
10
|
+
/** Removes a guest from the room; a personal link is revoked with them (`studio:write`). */
|
|
11
|
+
removeParticipant(streamId: string, identity: string, options?: RequestOptions): Promise<void>;
|
|
12
|
+
/** The invitations; their links only for a key with `studio:write` (`studio:read`). */
|
|
13
|
+
invites(streamId: string, options?: RequestOptions): Promise<StudioInvite[]>;
|
|
14
|
+
/** Makes an invitation and returns it with the guest's link (`studio:write`). */
|
|
15
|
+
createInvite(streamId: string, params?: StudioInviteCreateParams, options?: RequestOptions): Promise<StudioInviteCreated>;
|
|
16
|
+
/** Revokes an invitation: its link lets nobody in any more (`studio:write`). */
|
|
17
|
+
revokeInvite(streamId: string, inviteId: string, options?: RequestOptions): Promise<void>;
|
|
18
|
+
/** The host's token for the room, for a program that makes the frame itself (`studio:write`). */
|
|
19
|
+
hostToken(streamId: string, options?: RequestOptions): Promise<RoomToken>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Studio = void 0;
|
|
4
|
+
const http_js_1 = require("../http.js");
|
|
5
|
+
const base_js_1 = require("./base.js");
|
|
6
|
+
const studioPath = (streamId) => `/streams/${(0, http_js_1.segment)(streamId, 'streamId')}/studio`;
|
|
7
|
+
/** A stream's studio room: guests and their invitations. */
|
|
8
|
+
class Studio extends base_js_1.Resource {
|
|
9
|
+
/** Whether the room can have guests, who is in it and the invitations (`studio:read`). */
|
|
10
|
+
async get(streamId, options) {
|
|
11
|
+
return this.transport.request({ method: 'GET', path: studioPath(streamId) }, options);
|
|
12
|
+
}
|
|
13
|
+
/** Who is in the room, on stage and backstage (`studio:read`). */
|
|
14
|
+
async participants(streamId, options) {
|
|
15
|
+
return this.items({ method: 'GET', path: `${studioPath(streamId)}/participants` }, options);
|
|
16
|
+
}
|
|
17
|
+
/** Removes a guest from the room; a personal link is revoked with them (`studio:write`). */
|
|
18
|
+
async removeParticipant(streamId, identity, options) {
|
|
19
|
+
return this.none({ method: 'DELETE', path: `${studioPath(streamId)}/participants/${(0, http_js_1.segment)(identity, 'identity')}` }, options);
|
|
20
|
+
}
|
|
21
|
+
/** The invitations; their links only for a key with `studio:write` (`studio:read`). */
|
|
22
|
+
async invites(streamId, options) {
|
|
23
|
+
return this.items({ method: 'GET', path: `${studioPath(streamId)}/invites` }, options);
|
|
24
|
+
}
|
|
25
|
+
/** Makes an invitation and returns it with the guest's link (`studio:write`). */
|
|
26
|
+
async createInvite(streamId, params = {}, options) {
|
|
27
|
+
const { item, url } = await this.transport.request({ method: 'POST', path: `${studioPath(streamId)}/invites`, body: params }, options);
|
|
28
|
+
return { invite: item, url };
|
|
29
|
+
}
|
|
30
|
+
/** Revokes an invitation: its link lets nobody in any more (`studio:write`). */
|
|
31
|
+
async revokeInvite(streamId, inviteId, options) {
|
|
32
|
+
return this.none({ method: 'DELETE', path: `${studioPath(streamId)}/invites/${(0, http_js_1.segment)(inviteId, 'inviteId')}` }, options);
|
|
33
|
+
}
|
|
34
|
+
/** The host's token for the room, for a program that makes the frame itself (`studio:write`). */
|
|
35
|
+
async hostToken(streamId, options) {
|
|
36
|
+
return this.item({ method: 'POST', path: `${studioPath(streamId)}/token` }, options);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.Studio = Studio;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The API's objects and request bodies, named for programs. They come from
|
|
3
|
+
* the API's OpenAPI document (src/generated/openapi.ts, made from
|
|
4
|
+
* spec/openapi.json), so they are exactly what the API sends and takes; the
|
|
5
|
+
* field descriptions are the documentation's. Times are ISO 8601 strings in
|
|
6
|
+
* UTC, ids are UUIDs.
|
|
7
|
+
*/
|
|
8
|
+
import type { components, operations } from './generated/openapi.js';
|
|
9
|
+
type Schemas = components['schemas'];
|
|
10
|
+
type Body<Op extends keyof operations> = NonNullable<operations[Op]['requestBody']>['content']['application/json'];
|
|
11
|
+
/** The key the client works with: its name, scopes, streams and expiry. */
|
|
12
|
+
export type ApiKeyInfo = Schemas['KeyInfo']['key'];
|
|
13
|
+
export type Region = Schemas['Region'];
|
|
14
|
+
/** A social network connection of the account (no tokens). */
|
|
15
|
+
export type Connection = Schemas['Connection'];
|
|
16
|
+
export type Stream = Schemas['Stream'];
|
|
17
|
+
export type StreamSession = Stream['session'];
|
|
18
|
+
export type StreamStats = Stream['stats'];
|
|
19
|
+
/** What an encoder publishes with: RTMP, and WHIP where the region takes it. */
|
|
20
|
+
export type Credentials = Schemas['Credentials'];
|
|
21
|
+
export type Platform = Schemas['Platform'];
|
|
22
|
+
export type Ad = Schemas['Ad'];
|
|
23
|
+
/** The ad overlay of a live, transcoded stream. */
|
|
24
|
+
export type Overlay = Schemas['Overlay'];
|
|
25
|
+
export type Comment = Schemas['Comment'];
|
|
26
|
+
export type CommentFragment = NonNullable<Comment['fragments']>[number];
|
|
27
|
+
export type DeletedComment = Schemas['DeletedComment'];
|
|
28
|
+
export type CommentCounts = Schemas['CommentCounts'];
|
|
29
|
+
/** The studio's room: whether it can have guests, who is in it, the invitations. */
|
|
30
|
+
export type Studio = Schemas['Studio'];
|
|
31
|
+
export type StudioParticipant = Schemas['StudioParticipant'];
|
|
32
|
+
export type StudioInvite = Schemas['StudioInvite'];
|
|
33
|
+
/** The host's token for the studio's room (LiveKit). */
|
|
34
|
+
export type RoomToken = Schemas['RoomToken'];
|
|
35
|
+
export type Stats = Schemas['Stats'];
|
|
36
|
+
export type Broadcast = Schemas['Broadcast'];
|
|
37
|
+
export type Plan = Schemas['Plan'];
|
|
38
|
+
export type Payment = Schemas['Payment'];
|
|
39
|
+
export type Pagination = Schemas['Pagination'];
|
|
40
|
+
export type PlatformType = NonNullable<Platform['type']>;
|
|
41
|
+
export type StreamCategory = NonNullable<Stream['category']>;
|
|
42
|
+
export type Scope = ApiKeyInfo['scopes'][number];
|
|
43
|
+
/** How an encoder publishes: `rtmp` (or SRT) or `webrtc` (WHIP). */
|
|
44
|
+
export type PublishSource = NonNullable<Stream['source']>;
|
|
45
|
+
export type StreamCreateParams = Body<'postStreams'>;
|
|
46
|
+
/** Only the fields to change. */
|
|
47
|
+
export type StreamUpdateParams = Body<'patchStreamsByStreamId'>;
|
|
48
|
+
export type PlatformCreateParams = Body<'postStreamsByStreamIdPlatforms'>;
|
|
49
|
+
export type PlatformDestinationParams = Body<'putStreamsByStreamIdPlatformsByPlatformIdDestination'>;
|
|
50
|
+
export type AdCreateParams = Body<'postStreamsByStreamIdAds'>;
|
|
51
|
+
/** Only the fields to change; `null` clears the advertiser or the ERID. */
|
|
52
|
+
export type AdUpdateParams = Body<'patchStreamsByStreamIdAdsByAdId'>;
|
|
53
|
+
export type OverlayShowParams = Body<'postStreamsByStreamIdOverlayShow'>;
|
|
54
|
+
export type CommentBanParams = Body<'postStreamsByStreamIdCommentsByCommentIdBan'>;
|
|
55
|
+
export type StudioInviteCreateParams = Body<'postStreamsByStreamIdStudioInvites'>;
|
|
56
|
+
/** A page of a list: its items and where it is among the pages. */
|
|
57
|
+
export interface Page<T> {
|
|
58
|
+
items: T[];
|
|
59
|
+
pagination: Pagination;
|
|
60
|
+
}
|
|
61
|
+
export interface PageParams {
|
|
62
|
+
/** From 1. */
|
|
63
|
+
page?: number;
|
|
64
|
+
/** Up to 100; 20 by default. */
|
|
65
|
+
size?: number;
|
|
66
|
+
}
|
|
67
|
+
export interface StreamListParams extends PageParams {
|
|
68
|
+
/** By name. */
|
|
69
|
+
search?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CommentListParams {
|
|
72
|
+
/**
|
|
73
|
+
* The last comment's `uuid` of the previous answer: the answer is then in
|
|
74
|
+
* the order StreamFarm got the comments (`receivedAt`) — up to 50 stored
|
|
75
|
+
* 5 seconds before it, itself, and up to `limit` after it. Drop the ones
|
|
76
|
+
* you have; the answer's last comment is the next `after`. The cursor for
|
|
77
|
+
* following the chat; `comments.watch` does it for you.
|
|
78
|
+
*/
|
|
79
|
+
after?: string;
|
|
80
|
+
/** Only those published after it (by `publishedAt`, the platform's time). Not with `after`. */
|
|
81
|
+
since?: string | Date;
|
|
82
|
+
/** Up to 500; 100 by default. */
|
|
83
|
+
limit?: number;
|
|
84
|
+
/** Only from these kinds of platform. */
|
|
85
|
+
platformTypes?: readonly PlatformType[];
|
|
86
|
+
}
|
|
87
|
+
export interface CommentCountParams {
|
|
88
|
+
/** Count those published from then on, e.g. the broadcast's `session.startedAt`. */
|
|
89
|
+
since?: string | Date;
|
|
90
|
+
platformTypes?: readonly PlatformType[];
|
|
91
|
+
}
|
|
92
|
+
export interface DeletedCommentListParams {
|
|
93
|
+
/** Only those deleted after it: pass the last `deletedAt` you got. */
|
|
94
|
+
since?: string | Date;
|
|
95
|
+
/** Up to 500; 100 by default. */
|
|
96
|
+
limit?: number;
|
|
97
|
+
}
|
|
98
|
+
export interface StatsParams {
|
|
99
|
+
/** The first day, `YYYY-MM-DD`; by default 30 days (12 months by month) before `to`. */
|
|
100
|
+
from?: string;
|
|
101
|
+
/** The last day, included; today by default. */
|
|
102
|
+
to?: string;
|
|
103
|
+
/** By `day` (up to 400) or `month` (up to 60); `day` by default. */
|
|
104
|
+
interval?: 'day' | 'month';
|
|
105
|
+
/** An IANA time zone for the days, e.g. `Europe/Moscow`; UTC by default. */
|
|
106
|
+
timeZone?: string;
|
|
107
|
+
/** Only this stream. */
|
|
108
|
+
streamUuid?: string;
|
|
109
|
+
}
|
|
110
|
+
export interface BroadcastListParams extends PageParams {
|
|
111
|
+
/** Only this stream's. */
|
|
112
|
+
streamUuid?: string;
|
|
113
|
+
/** Only those started from then on. */
|
|
114
|
+
from?: string | Date;
|
|
115
|
+
/** Only those started before then. */
|
|
116
|
+
to?: string | Date;
|
|
117
|
+
}
|
|
118
|
+
/** An invitation just made: the invitation and the guest's link. */
|
|
119
|
+
export interface StudioInviteCreated {
|
|
120
|
+
invite: StudioInvite;
|
|
121
|
+
/** `https://studio.streamfarm.ru/join/<token>`: give it to the guest. */
|
|
122
|
+
url: string;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type RequestOptions } from './http.js';
|
|
2
|
+
import type { Comment, CommentListParams, DeletedComment, DeletedCommentListParams, PlatformType } from './types.js';
|
|
3
|
+
/** What `comments.watch` gives: a new comment, or one the streamer deleted. */
|
|
4
|
+
export type ChatEvent = {
|
|
5
|
+
type: 'comment';
|
|
6
|
+
comment: Comment;
|
|
7
|
+
} | {
|
|
8
|
+
type: 'deleted';
|
|
9
|
+
uuid: string;
|
|
10
|
+
deletedAt: string;
|
|
11
|
+
};
|
|
12
|
+
export interface WatchOptions {
|
|
13
|
+
/** How often to read the chat, ms; 5000 by default (with deletions, 24 requests a minute of the key's 120). */
|
|
14
|
+
interval?: number;
|
|
15
|
+
/** Only comments from these kinds of platform. */
|
|
16
|
+
platformTypes?: readonly PlatformType[];
|
|
17
|
+
/** Give the chat's latest comments first (`historyLimit` of them); false by default: only new ones. */
|
|
18
|
+
includeHistory?: boolean;
|
|
19
|
+
/** How many latest comments the start reads; 100 by default. */
|
|
20
|
+
historyLimit?: number;
|
|
21
|
+
/** Also give `deleted` events; true by default. */
|
|
22
|
+
deletions?: boolean;
|
|
23
|
+
/** Stops the watch: the loop then rejects with the signal's reason. */
|
|
24
|
+
signal?: AbortSignal;
|
|
25
|
+
/**
|
|
26
|
+
* Called for an error the watch rides out: no answer, a server error, the
|
|
27
|
+
* request limit. It then tries again after a pause that doubles with each
|
|
28
|
+
* error in a row (from the interval, at least a second, up to a minute). Other errors (no scope, no stream, no
|
|
29
|
+
* chat in the tariff) end the watch.
|
|
30
|
+
*/
|
|
31
|
+
onError?: (error: Error) => void;
|
|
32
|
+
}
|
|
33
|
+
/** The comment reads the watch makes: Comments' list and listDeleted. */
|
|
34
|
+
export interface ChatSource {
|
|
35
|
+
list(streamId: string, params?: CommentListParams, options?: RequestOptions): Promise<Comment[]>;
|
|
36
|
+
listDeleted(streamId: string, params?: DeletedCommentListParams, options?: RequestOptions): Promise<DeletedComment[]>;
|
|
37
|
+
}
|
|
38
|
+
/** The most a read takes: a full page means more are waiting. */
|
|
39
|
+
export declare const PAGE_LIMIT = 500;
|
|
40
|
+
/**
|
|
41
|
+
* An API without `after` (backend before the cursor by arrival) is read by
|
|
42
|
+
* `since`, the platforms' own times, which come late from the platforms read
|
|
43
|
+
* every 15–60 s: each read reaches this far back behind the newest.
|
|
44
|
+
*/
|
|
45
|
+
export declare const SINCE_LOOKBACK_MS = 120000;
|
|
46
|
+
/**
|
|
47
|
+
* Follows a stream's chat: every new comment once, in the order StreamFarm
|
|
48
|
+
* got them, and the streamer's deletions. Rides out network and server
|
|
49
|
+
* errors; ends on others or when `signal` aborts.
|
|
50
|
+
*/
|
|
51
|
+
export declare function watchChat(source: ChatSource, streamId: string, options?: WatchOptions): AsyncGenerator<ChatEvent, void, undefined>;
|