Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ export interface RegisterInputResponse {
audioDurationMs?: number | null;
/**
*
* @type {number}
* @type {string}
* @memberof RegisterInputResponse
*/
port?: number | null;
publishUrl?: string | null;
}

/**
Expand Down Expand Up @@ -87,7 +87,8 @@ export function RegisterInputResponseFromJSONTyped(json: any, ignoreDiscriminato
: json['audio_duration_ms'] === null
? null
: json['audio_duration_ms'],
port: json['port'] === undefined ? undefined : json['port'] === null ? null : json['port'],
publishUrl:
json['publish_url'] === undefined ? undefined : json['publish_url'] === null ? null : json['publish_url'],
};
}

Expand All @@ -108,6 +109,6 @@ export function RegisterInputResponseToJSONTyped(
endpoint_route: value['endpointRoute'],
video_duration_ms: value['videoDurationMs'],
audio_duration_ms: value['audioDurationMs'],
port: value['port'],
publish_url: value['publishUrl'],
};
}
15 changes: 12 additions & 3 deletions packages/js-server-sdk/src/composition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,23 @@ export class CompositionClient {

/**
* Register an input that an RTMP publisher pushes media into. The stream key identifies the
* input; the address to publish to belongs to the composition, not to this call.
* input and is carried in the returned address.
* @returns the address to publish the RTMP stream to
*/
Comment thread
Gawor270 marked this conversation as resolved.
async registerRtmpInput(
compositionId: CompositionId,
inputId: InputId,
options: Omit<RtmpInput, 'type'>
): Promise<void> {
await this.registerInput(compositionId, inputId, { ...options, type: 'rtmp_server' });
): Promise<string> {
const { publishUrl } = await this.registerInput(compositionId, inputId, { ...options, type: 'rtmp_server' });

if (!publishUrl) {
throw new UnknownException({
message: `Could not obtain a publishing address for input "${inputId}", retry or report it`,
});
}

return publishUrl;
}

/**
Expand Down
22 changes: 19 additions & 3 deletions packages/js-server-sdk/tests/composition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ describe('request serialisation', () => {
});

it('reads a response back into camelCase', async () => {
stubFetch({ port: 5004 });
stubFetch({ publish_url: 'rtmps://rtmp.example.com:443/key' });
const response = await client().registerInput(COMPOSITION_ID, INPUT_ID, {
type: 'rtmp_server',
streamKey: 'key',
});

expect(response).toEqual({ port: 5004 });
expect(response).toEqual({ publishUrl: 'rtmps://rtmp.example.com:443/key' });
});
});

Expand Down Expand Up @@ -108,6 +108,22 @@ describe('input variants', () => {
await expect(client().registerWhipInput(COMPOSITION_ID, INPUT_ID)).rejects.toThrow(UnknownException);
});

it('returns the RTMP publishing address the server chose', async () => {
stubFetch({ publish_url: 'rtmps://rtmp.example.com:443/k' });

await expect(client().registerRtmpInput(COMPOSITION_ID, INPUT_ID, { streamKey: 'k' })).resolves.toBe(
'rtmps://rtmp.example.com:443/k'
);
});

it('throws when the server returns no RTMP publishing address', async () => {
stubFetch({});

await expect(client().registerRtmpInput(COMPOSITION_ID, INPUT_ID, { streamKey: 'k' })).rejects.toThrow(
UnknownException
);
});

it('sends the discriminant for each variant', async () => {
const cases = [
[(c: CompositionClient) => c.registerWhipInput(COMPOSITION_ID, INPUT_ID), 'whip_server'],
Expand All @@ -120,7 +136,7 @@ describe('input variants', () => {
] as const;

for (const [register, type] of cases) {
const fetch = stubFetch({ bearer_token: 'tok' });
const fetch = stubFetch({ bearer_token: 'tok', publish_url: 'rtmps://rtmp.example.com:443/k' });
await register(client());
expect(requestBody(fetch).type).toBe(type);
vi.unstubAllGlobals();
Expand Down
Loading