Feature requests REST API

SLM

Member
I don't know if this is already possible, but if not, I would like to suggest a feature to be included in future versions:

1. Save stream recordings to a predefined folder
Since the application is installed on an SSD and these disks are mostly smaller in size than HDD's, we would like to be able to record streams to another folder / volume. This folder could be defined in the Flashphoner properties config file. Not on a per stream basis but for all recordings.

2. /stream/deleteRecording
To delete a recorded stream

3. Being able to use vod:// and vod-live:// as well as API method /vod/startup for recorded streams
So this command should look in both the media folder and the recordings folder, or if this is not possible, being able to set both folders (in this case to the same folder) in the config file.
 

Max

Administrator
Staff member
Good day.
1. Save stream recordings to a predefined folder
There is a ticket WCS-2662, your voice for the feature is accepted
2. /stream/deleteRecording
To delete a recorded stream
This can be arranged with your own backend server.
3. Being able to use vod:// and vod-live:// as well as API method /vod/startup for recorded streams
So this command should look in both the media folder and the recordings folder, or if this is not possible, being able to set both folders (in this case to the same folder) in the config file.
You can move recordings to media folder using on_record_hook script
When WCS-2662 will be implemented, you would set recordings and media to the same folder
 

SLM

Member
Good day.

There is a ticket WCS-2662, your voice for the feature is accepted
Thank you.

(2) This can be arranged with your own backend server.
How? It's pretty inefficient to install Apache, php or some other scripting language on the streaming server to do this.

You can move recordings to media folder using on_record_hook script
When WCS-2662 will be implemented, you would set recordings and media to the same folder
The rest hooks are received by a webserver, the recorded or other vod streams are located on the streaming (Flashphoner) server. There is no other connection between the webserver and the streaming server apart from using the REST API methods so unless you have a /stream/move method, I don't think this is possible,
 

Max

Administrator
Staff member
How? It's pretty inefficient to install Apache, php or some other scripting language on the streaming server to do this.
You probably have a backend server to work with REST hooks. So, you can:
1. Send to backend server POST query like this
Code:
/deleteRecording
{
"fileName":"recording_name.mp4"
}
2. Backend server can connect to WCS server via SSH and remove the file with given name like this
PHP:
    $connection = ssh2_connect($ip, 22, array('hostkey' => 'ssh-rsa'));
    ssh2_auth_pubkey_file($connection, 'root', '~/.ssh/id_rsa.pub', '~/.ssh/id_rsa');
    ssh2_auth_password($connection, 'root', 'P@ssW0Rd');
    $stream = ssh2_exec($connection, "rm -f /usr/local/FlashphonerWebCallServer/records/".$fileName);
    stream_set_blocking($stream, true);
    $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
    $response=stream_get_contents($stream_out);
    fclose($stream);
The rest hooks are received by a webserver, the recorded or other vod streams are located on the streaming (Flashphoner) server. There is no other connection between the webserver and the streaming server apart from using the REST API methods so unless you have a /stream/move method, I don't think this is possible,
The record hook script is not a REST hook, this is a bash script. The script is called right after recording file is saved to records folder. The default script is on_record_hook.sh file in /usr/local/FlashphonerWebCallServer/bin folder:
Bash:
STREAM_NAME=$1
FILE_NAME=$2

echo $STREAM_NAME
echo $FILE_NAME
So you can modify it to
Bash:
STREAM_NAME=$1
FILE_PATH=$2
# Get file name from full path
FILE_NAME=$(basename $FILE_PATH)
# Set destination folder
DST_PATH=/usr/local/FlashphonerWebCallServer/media
# Make sure destination folder exists
mkdir -p $DST_PATH
# Move file to destination folder
mv -f $FILE_PATH $DST_PATH/$FILE_NAME
Another option to put all the recordings to media folder is to make a link
Code:
ln -sf /usr/local/FlashphonerWebCallServer/media /usr/local/FlashphonerWebCallServer/records
or, if you prefer those folders to be on separate volume, just link them both to destination path
Code:
ln -sf /opt/media /usr/local/FlashphonerWebCallServer/records
ln -sf /opt/media /usr/local/FlashphonerWebCallServer/media
 

SLM

Member
You probably have a backend server to work with REST hooks. So, you can:
1. Send to backend server POST query like this
Code:
/deleteRecording
{
"fileName":"recording_name.mp4"
}
But there is no /deleteRecording mentioned in the documentation and when I tested this it resulted in a 404.

2. Backend server can connect to WCS server via SSH and remove the file with given name like this
PHP:
...
I think you will understand that I'm not eager to put any server root passwords plaintext in a file so this solution is not workable for me.

The record hook script is not a REST hook, this is a bash script. The script is called right after recording file is saved to records folder. The default script is on_record_hook.sh file in /usr/local/FlashphonerWebCallServer/bin folder:
Bash:
...
Thank you, I will look into this.
 

Max

Administrator
Staff member
But there is no /deleteRecording mentioned in the documentation and when I tested this it resulted in a 404.
You should implement such REST API method on your backend server:
PHP:
<?php
 
$api_method = array_pop(explode("/", $_SERVER['REQUEST_URI']));
$incoming_data = json_decode(file_get_contents('php://input'), true);

switch($api_method) {
    case "deleteRecord": 
     
    $fileName = $incoming_data['fileName'];
     
    $connection = ssh2_connect($ip, 22, array('hostkey' => 'ssh-rsa'));
    ssh2_auth_pubkey_file($connection, 'root', '~/.ssh/id_rsa.pub', '~/.ssh/id_rsa');
    $stream = ssh2_exec($connection, "rm -f /usr/local/FlashphonerWebCallServer/records/".$fileName);
    stream_set_blocking($stream, true);
    $stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO);
    $response=stream_get_contents($stream_out);
    fclose($stream);

    break;
}
header('HTTP/1.1 200 OK', true, 200);
?>
I think you will understand that I'm not eager to put any server root passwords plaintext in a file so this solution is not workable for me.
This is just an example. You can certainly implement a private/public key access (see above)
 
Top