Overview
Package @swmansion/smelter-node allows you to control a Smelter server from the Node.js process.
When using this approach your React code runs inside Node.js process, and any updates to the React component tree are transmitted to the Smelter server as layout updates over HTTP requests. By default, the Smelter server is automatically launched on the same machine as Node.js, but you may choose to deploy it independently and simply provide the library with the connection URL.
You can use it in 2 modes:
-
This is the most flexible approach. It allows you to dynamically add and remove inputs/outputs at any point. By default, media is processed in real time, but this can be affected by e.g. required inputs or global settings.
Check out
Smelterdocumentation.Example
import Smelter from "@swmansion/smelter-node"async function run() {const smelter = new Smelter();await smelter.init()// register inputs, outputs, or other resources e.g.await smelter.registerOutput("example", <View />, {type: "rtmp_client",url: "rtmp://example.com/app/stream_key",video: {encoder: { type: "ffmpeg_h264" },resolution: { width: 1920, height: 1080 },},audio: {channels: "stereo",encoder: { type: "aac" },}});await smelter.start()// you can register additional input/outputs at any point}void run(); -
Mainly useful to take one or more static files and produce a single output. API in this mode is very limited: you need to define all inputs before start, there can be only one output.
Check out
OfflineSmelterdocumentation.Example
import { OfflineSmelter } from "@swmansion/smelter-node"async function run() {const smelter = new OfflineSmelter();await smelter.init()// register inputsawait smelter.render(<View />, {type: "mp4",serverPath: "./output.mp4",video: {encoder: { type: "ffmpeg_h264" },resolution: { width: 1920, height: 1080 },},audio: {channels: "stereo",encoder: { type: "aac" },}});}void run();
Smelter managers
@swmansion/smelter-node controls the Smelter server via SmelterManager
interface. You can pass them as an argument when initializing Smelter or OfflineSmelter instance.
The package provides 2 implementations:
LocallySpawnedInstanceManager(default) - downloads spawns Smelter binary and spawns a server locally.ExistingInstanceOptions- connects to existing instance.
Compatibility
@swmansion/smelter-node can be used with specific version of Smelter server and React.
| SDK version | Smelter server version | React version |
|---|---|---|
v0.2.0v0.2.1 | v0.4.0v0.4.1 | Recommended: Should work with any react version that is compatible with
|
v0.3.0 | v0.5.0 | Recommended: Should work with any react version that is compatible with
|
You need to remember about requirements of the actual Smelter server too. See Smelter server deployment options: