Update version to 2025.1.8 and implement fork and kill channel methods in Channels API
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@techniker-me/pcast-api",
|
||||
"version": "2025.1.7",
|
||||
"version": "2025.1.8",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"ci-build": "bun run build",
|
||||
|
||||
@@ -46,16 +46,24 @@ export class ChannelError extends Error {
|
||||
}
|
||||
}
|
||||
|
||||
type KillChannelResponse = {
|
||||
status: string;
|
||||
killedMembers: Member[];
|
||||
};
|
||||
|
||||
type ForkChannelResponse = {
|
||||
status: string;
|
||||
members: Member[];
|
||||
};
|
||||
|
||||
export class Channels {
|
||||
private readonly _httpRequests: PCastHttpRequests;
|
||||
private readonly _channelsByAlias: Map<ChannelAlias, Channel> = new Map();
|
||||
|
||||
constructor(pcastHttpRequests: PCastHttpRequests, skipInitialization = false) {
|
||||
constructor(pcastHttpRequests: PCastHttpRequests) {
|
||||
this._httpRequests = pcastHttpRequests;
|
||||
if (!skipInitialization) {
|
||||
this.initialize();
|
||||
}
|
||||
}
|
||||
|
||||
public async create(name: string, description: string, channelOptions: string[] = []): Promise<Channel> {
|
||||
if (!name || name.trim().length === 0) {
|
||||
@@ -186,7 +194,7 @@ export class Channels {
|
||||
return response;
|
||||
}
|
||||
|
||||
async getPublishSourceStreamId(channelId: string, retryCount: number = 3): Promise<string | null> {
|
||||
public async getPublishSourceStreamId(channelId: string, retryCount: number = 3): Promise<string | null> {
|
||||
const retryCountRemaining = retryCount || 3;
|
||||
const channelMembers = await this.getMembers(channelId);
|
||||
|
||||
@@ -213,14 +221,30 @@ export class Channels {
|
||||
return presenter.streams[0].uri.match(publishSourceStreamIdRegExp)?.[1] ?? null;
|
||||
}
|
||||
|
||||
// TODO(AZ): Implement this
|
||||
// public async fork(channelId: string): Promise<Channel>
|
||||
public async fork(sourceChannelId: string, destinationChannelId: string): Promise<ForkChannelResponse> {
|
||||
const response = await this._httpRequests.request<ForkChannelResponse>(
|
||||
HttpMethod.PUT,
|
||||
`/channel/${encodeURIComponent(destinationChannelId)}/fork/${encodeURIComponent(sourceChannelId)}`
|
||||
);
|
||||
|
||||
// TODO(AZ): Implement this
|
||||
// public async killChannel(channelId: string): Promise<Channel>
|
||||
if (response.status !== 'ok') {
|
||||
console.error('Fork response [%o]', response);
|
||||
throw new ChannelError(`Failed to fork channel [${sourceChannelId}] to [${destinationChannelId}]`, 'FORK_FAILED');
|
||||
}
|
||||
|
||||
// TODO(AZ): Implement this
|
||||
// public async publishViaUrl(mediaUriToPublish: string, token: string): Promise<Channel>
|
||||
return response;
|
||||
}
|
||||
|
||||
public async killChannel(channelId: string): Promise<KillChannelResponse> {
|
||||
const response = await this._httpRequests.request<KillChannelResponse>(HttpMethod.PUT, `/channel/${encodeURIComponent(channelId)}/kill`);
|
||||
|
||||
if (response.status !== 'ok') {
|
||||
console.error('Kill response [%o]', response);
|
||||
throw new ChannelError(`Failed to kill channel [${channelId}]`, 'KILL_FAILED');
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private async initialize(): Promise<void> {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user