Refactor Channels and Streams APIs: Update Member streams type to an array, enhance error handling in publishUri method, and add extractMediaType utility function.
This commit is contained in:
@@ -19,14 +19,12 @@ export type Member = {
|
||||
sessionId: string;
|
||||
screenName: string;
|
||||
role: string;
|
||||
streams: [
|
||||
{
|
||||
type: string;
|
||||
uri: string;
|
||||
audioState: string;
|
||||
videoState: string;
|
||||
}
|
||||
];
|
||||
streams: {
|
||||
type: string;
|
||||
uri: string;
|
||||
audioState: string;
|
||||
videoState: string;
|
||||
}[];
|
||||
state: string;
|
||||
lastUpdate: number;
|
||||
};
|
||||
@@ -36,6 +34,16 @@ type GetChannelParams = {
|
||||
channelId?: string;
|
||||
};
|
||||
|
||||
type KillChannelResponse = {
|
||||
status: string;
|
||||
killedMembers: Member[];
|
||||
};
|
||||
|
||||
type ForkChannelResponse = {
|
||||
status: string;
|
||||
members: Member[];
|
||||
};
|
||||
|
||||
export class ChannelError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
@@ -46,16 +54,6 @@ 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();
|
||||
@@ -195,22 +193,23 @@ export class Channels {
|
||||
}
|
||||
|
||||
public async getPublishSourceStreamId(channelId: string, retryCount: number = 3): Promise<string | null> {
|
||||
const retryCountRemaining = retryCount || 3;
|
||||
const channelMembers = await this.getMembers(channelId);
|
||||
|
||||
console.log('channelMembers [%o] retryCount [%d]', channelMembers, retryCount);
|
||||
if (channelMembers.length === 0) {
|
||||
if (retryCountRemaining > 0) {
|
||||
return this.getPublishSourceStreamId(channelId, retryCountRemaining - 1);
|
||||
if (retryCount > 0) {
|
||||
|
||||
return this.getPublishSourceStreamId(channelId, retryCount - 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
const presenter = channelMembers.find(member => member.role === 'Presenter');
|
||||
|
||||
if (!presenter) {
|
||||
if (retryCountRemaining > 0) {
|
||||
return this.getPublishSourceStreamId(channelId, retryCountRemaining - 1);
|
||||
if (retryCount > 0) {
|
||||
return this.getPublishSourceStreamId(channelId, retryCount - 1);
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -218,7 +217,7 @@ export class Channels {
|
||||
|
||||
const publishSourceStreamIdRegExp = /pcast:\/\/.*\/([^?]*)/;
|
||||
|
||||
return presenter.streams[0].uri.match(publishSourceStreamIdRegExp)?.[1] ?? null;
|
||||
return presenter.streams[0]?.uri?.match(publishSourceStreamIdRegExp)?.[1] ?? null;
|
||||
}
|
||||
|
||||
public async fork(sourceChannelId: string, destinationChannelId: string): Promise<ForkChannelResponse> {
|
||||
|
||||
Reference in New Issue
Block a user