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