mediamtx-node-client
is a Node.js client library for interacting with MediaMTX API. It provides various methods to interact with streams, recordings, and configurations, allowing you to manage and automate tasks with ease.
To install the library, run the following npm command:
npm install mediamtx-node-client
To use the client, create a new instance of MediamtxNodeClient
by passing a configuration object containing the base URL, authentication credentials (username/password), and other optional configurations.
import { MediamtxNodeClient } from "mediamtx-node-client";
const mediaMtxClient = new MediamtxNodeClient({
baseURL: "http://localhost:9997/",
auth: {
username: "your-username",
password: "your-password",
},
});
Lists all available streams.
const streamList = await mediaMtxClient.listStreams();
console.log(streamList);
Gets information about a specific stream by name.
const streamItem = await mediaMtxClient.getStreamByName("stream-name");
console.log(streamItem);
Lists all recordings, with optional pagination.
const recordingList = await mediaMtxClient.recordingList();
Lists all recordings for a specific path.
const recordingListForPath = await mediaMtxClient.recordingListForPath("path-to-recording");
Deletes a recording segment.
const deleteRecording = await mediaMtxClient.deleteRecording("path-to-recording", "start-time");
console.log("Recording deleted");
Gets the global configuration for MediaMTX.
const globalConfig = await mediaMtxClient.getGlobalConfig();
console.log(globalConfig);
Updates the global configuration with the provided patch.à
const updatedConfig = await mediaMtxClient.patchGlobalConfig({ /* your config patch */ });
console.log(updatedConfig);
Gets the default path configuration.
const defaultPathConfig = await mediaMtxClient.getDefaultPathConfiguration();
console.log(defaultPathConfig);
Updates the default path configuration with the provided patch.
const updatedPathConfig = await mediaMtxClient.patchDefaultPathConfiguration({ /* your config patch */ });
console.log(updatedPathConfig);
Lists all path configurations, with optional pagination.
const allPathsConfigurations = await mediaMtxClient.getAllPathsConfigurations();
console.log(allPathsConfigurations);
Gets the configuration for a specific path.
const pathConfig = await mediaMtxClient.getPathConfiguration("stream-name");
console.log(pathConfig);
Creates a new streaming path with the provided configuration.
const newStream = await mediaMtxClient.createNewStreamingPath("/my-stream", {
name: "/my-stream",
source: "rtsp://test:544/stream/test",
sourceOnDemand:true
});
console.log(newStream);
Updates an existing streaming path configuration.
const updatedStream = await mediaMtxClient.updateStreamingPathConfig("/my-stream", { sourceOnDemand:false,maxReaders:5 });
console.log(updatedStream);
Deletes a streaming path.
const deletedPath = await mediaMtxClient.deleteStreamingPath("/my-stream");
console.log(deletedPath);
import { MediamtxNodeClient } from "mediamtx-node-client";
(async () => {
const mediaMtxClient = new MediamtxNodeClient({
baseURL: "http://localhost:9997/",
auth: {
username: "your-username",
password: "your-password",
},
});
const recordingList = await mediaMtxClient.recordingList();
const recordingListForPath = await mediaMtxClient.recordingListForPath("path/to-recording");
const deleteRecording = await mediaMtxClient.deleteRecording(
"path/to-recording",
"2025-02-08T19:39:11.768623Z" //recordingListForPath.segments[0].start
);
console.log("Deleted");
const globalConfig = await mediaMtxClient.getGlobalConfig();
const defaultPathConfiguration = await mediaMtxClient.getDefaultPathConfiguration();
const newStream = await mediaMtxClient.createNewStreamingPath("test/stream-name", {
name: "test/stream-name",
source: "rtsp://example.com/stream",
...
});
const updatedStream = await mediaMtxClient.updateStreamingPathConfig(
"test/stream-name",
{ sourceOnDemand: true }
);
const deletePath = await mediaMtxClient.deleteStreamingPath("test/stream-name");
const allPathsConfigurations = await mediaMtxClient.getAllPathsConfigurations();
if (allPathsConfigurations.items.length) {
const pathConfig = await mediaMtxClient.getPathConfiguration(
allPathsConfigurations.items[0].name!
);
console.log(pathConfig);
}
setInterval(async () => {
const streamList = await mediaMtxClient.listStreams();
console.log(streamList);
}, 1000);
setInterval(async () => {
const streamItem = await mediaMtxClient.getStreamByName(
"stream-name"
);
console.log(streamItem);
}, 1000);
})();