Custom variables
Custom variables are a method to create your own variables in MistServer. You can create both static and dynamic variables at the general panel
When do you use custom variables?
Custom variables are something you want to use when you find yourself either filling in a specific long value many times, or whenever you find yourself in need of brining a simple coding language into MistServer. Static variables replace a value with a static string, dynamic variables run a script and adjust their value accordingly.
Now something to keep in mind is that variables may contain variables, which do indeed work. So adding something like $stream
into a variable would then again be parsed as a variable and insert the stream name whenever the variable is used.
Static variables
A static variable always replaces one variable for the same value. This could be an easy method to insert long strings like recording paths or account information.
A static variable can just be a shorter way to write something down. For example instead of writing a whole path location like /path/to/media/folder/ you just shorten it to /$path/. You can also use it to store a password and avoid accidentally leaking it by visiting a configuration that would use it.
Setting up a static variable
There's 2 important settings for static variables:
Variable name
Whenever MistServer encounters$variablename
it will insert your string.Value
Whatever the variable should insert. This can be anystring
.
Example
A good example of using static variables is shortening local paths to easy and short variables.
Value | Description |
---|---|
Variable name | Path |
Value | tmp/recording/myrecording/$basename/$yday |
Now the reason why we've set up the value to not have any /
in front or at the end is to make it better usable. The first /
is required to trigger local storage logic for recording and shouldn't be included in the variable. The last /
is so I can easily see where the variable ended.
This recording will automatically insert both the $basename
and $yday
variables when used as well. This makes my recording database somewhat easier to use as it's filtered on both the stream that it recorded as well as the day of the year.
We can use it simply by starting a push with:
target
: /$path/myrecording.mkv
Once the stream comes live you will see the following:
You will see any recording show both the pre-parsed target as well as the completely parsed target.
This recording was done on 8th of November for the stream live
. As you can see the $path
variable has inserted: tmp/recording/myrecording/live/312
Dynamic variables
Dynamic variables are as simple or complex as you want them to be and will be periodically checked for their value. They change based on the script and values used.
A dynamic variable can change depending on your own scripts, which grants you near unlimited freedom in setting things up. A very simple usage would be something simple as calling upon date +%s
to get the current POSIX time.
Setting up a dynamic variable
There's 4 important settings for a dynamic variables:
Variable name
Whenever MistServer encounters$variablename
it will insert the value the last time it ran thecommand
.Command
This is the script MistServer will run in order to generate a variable.Checking interval
This is the amount of time in seconds between attempts to run thecommand
.Wait time
This is the amount of time in seconds the script is allowed to run before MistServer stops it and considers it timed-out. The value will benull
in that case.
Example of using a dynamic variable
A dynamic variable is extremely flexible in it's use, so please don't consider this example the only type of usage. For this example we'll do something very simple: Inserting the current UNIX time.
Value | Description |
---|---|
Variable name | Path |
Command | date +%s |
Checking interval | 1 |
Wait time | 2 |
This will have MistServer run the command date +%s
every second and insert the value of the command as the value of the variable $now
.
Once set up you can see the interface show the value upon page load. Note that this page does not update the dynamic values in real time.
We could now in turn use this variable to either insert the current UNIX time into recordings, or even use it to schedule a recording with. Another usage would be to check a database and verify if a user has set a value to on and if so have it record when they go live.
Dynamic variables warning
MistServer will blindly run whatever command is given with the permissions of MistServer. So setting up a dynamic variable will have MistServer periodically run a command no matter what this command is. Whether this is a warning to block the usage or as a suggestion to get creative is up to you.