Skip to content

Commit d247a21

Browse files
committed
Added Smelter.stats() to the smelter-node package
1 parent 5c290b8 commit d247a21

File tree

5 files changed

+21
-3
lines changed

5 files changed

+21
-3
lines changed

ts/examples/node-examples/src/audio.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import { downloadAllAssets, ffplayStartRtmpServerAsync } from './utils';
44
import path from 'path';
55
import { useState, useEffect } from 'react';
66

7+
function sleep(ms: number): Promise<void> {
8+
return new Promise(resolve => setTimeout(resolve, ms));
9+
}
10+
711
function ExampleApp() {
812
const [streamWithAudio, setStream] = useState('input_1');
913
useEffect(() => {
@@ -85,5 +89,12 @@ async function run() {
8589
});
8690

8791
await smelter.start();
92+
93+
while (true) {
94+
await sleep(1000);
95+
console.clear();
96+
let json_string = await smelter.stats();
97+
console.dir(json_string, { depth: null });
98+
}
8899
}
89100
void run();

ts/smelter-core/src/api.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ export class ApiClient {
160160
return this.serverManager.sendRequest({
161161
method: 'GET',
162162
route: `/stats`,
163-
body: {},
164163
})
165164
}
166165
}

ts/smelter-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as Output from './api/output';
22
import * as Input from './api/input';
33

44
export { Output, Input };
5-
export { ApiClient, ApiRequest, MultipartRequest, RegisterInputResponse } from './api';
5+
export { ApiClient, ApiRequest, MultipartRequest, RegisterInputResponse, StatsResponse } from './api';
66
export { Smelter } from './live/compositor';
77
export { OfflineSmelter } from './offline/compositor';
88
export { SmelterManager, SetupInstanceOptions } from './smelterManager';

ts/smelter-node/src/api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,5 @@ export type RegisterWhipServerInputResponse = {
4444
bearerToken: string;
4545
endpointRoute: string;
4646
};
47+
48+
export type { StatsResponse } from '@swmansion/smelter-core';

ts/smelter-node/src/live/compositor.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import FormData from 'form-data';
33
import fetch from 'node-fetch';
44
import type { Renderers } from '@swmansion/smelter';
55
import type { SmelterManager } from '@swmansion/smelter-core';
6-
import { StateGuard, Smelter as CoreSmelter } from '@swmansion/smelter-core';
6+
import { StateGuard, Smelter as CoreSmelter, type StatsResponse } from '@swmansion/smelter-core';
77

88
import LocallySpawnedInstance from '../manager/locallySpawnedInstance';
99
import { createLogger } from '../logger';
@@ -179,4 +179,10 @@ export default class Smelter {
179179
await this.coreSmelter.terminate();
180180
});
181181
}
182+
183+
public async stats(): Promise<StatsResponse> {
184+
return await this.scheduler.run(async () => {
185+
return this.coreSmelter.stats();
186+
});
187+
}
182188
}

0 commit comments

Comments
 (0)