wowza and streaming. lesson 10
id.241224001.903824
Lesson 10: Advanced Features of Wowza Streaming Engine
This lesson explores 10 advanced tasks using Wowza Streaming Engine's REST API, including Node.js and Python examples for each.
1. Retrieve Server Status
Node.js
const axios = require('axios');
const wowzaApiUrl = 'http://<server-ip>:8087/v2';
const username = 'your-username';
const password = 'your-password';
async function getServerStatus() {
try {
const response = await axios.get(`${wowzaApiUrl}/servers`, {
auth: { username, password }
});
console.log('Server status:', response.data);
} catch (error) {
console.error('Error retrieving server status:', error.response.data);
}
}
getServerStatus();
Python
import requests
from requests.auth import HTTPBasicAuth
def get_server_status():
url = f"http://<server-ip>:8087/v2/servers"
response = requests.get(url, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Server status:", response.json())
get_server_status()
2. Configure Bandwidth Throttling
Node.js
async function setBandwidthLimit() {
const bandwidthConfig = { maxBandwidth: 1000000 }; // Limit to 1 Mbps
try {
const response = await axios.put(
`${wowzaApiUrl}/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/configuration`,
bandwidthConfig,
{ auth: { username, password } }
);
console.log('Bandwidth limit set:', response.data);
} catch (error) {
console.error('Error setting bandwidth limit:', error.response.data);
}
}
setBandwidthLimit();
Python
def set_bandwidth_limit():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/configuration"
bandwidth_config = {"maxBandwidth": 1000000} # 1 Mbps
response = requests.put(url, json=bandwidth_config, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Bandwidth limit set:", response.json())
set_bandwidth_limit()
3. Add a New User for API Access
Node.js
async function addApiUser() {
const userConfig = { username: "newuser", password: "newpassword" };
try {
const response = await axios.post(`${wowzaApiUrl}/users`, userConfig, {
auth: { username, password }
});
console.log('User added:', response.data);
} catch (error) {
console.error('Error adding user:', error.response.data);
}
}
addApiUser();
Python
def add_api_user():
url = f"http://<server-ip>:8087/v2/users"
user_config = {"username": "newuser", "password": "newpassword"}
response = requests.post(url, json=user_config, auth=HTTPBasicAuth('your-username', 'your-password'))
print("User added:", response.json())
add_api_user()
4. Manage Logging Levels
Node.js
async function setLogLevel(level) {
const logConfig = { level: level };
try {
const response = await axios.put(`${wowzaApiUrl}/servers/_defaultServer_/log4j/loglevels`, logConfig, {
auth: { username, password }
});
console.log('Log level set:', response.data);
} catch (error) {
console.error('Error setting log level:', error.response.data);
}
}
setLogLevel("INFO");
Python
def set_log_level(level):
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/log4j/loglevels"
log_config = {"level": level}
response = requests.put(url, json=log_config, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Log level set:", response.json())
set_log_level("INFO")
5. Retrieve Incoming Stream Details
Node.js
async function getIncomingStreams() {
try {
const response = await axios.get(
`${wowzaApiUrl}/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/instances/_definst_/incomingstreams`,
{ auth: { username, password } }
);
console.log('Incoming streams:', response.data);
} catch (error) {
console.error('Error retrieving streams:', error.response.data);
}
}
getIncomingStreams();
Python
def get_incoming_streams():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/instances/_definst_/incomingstreams"
response = requests.get(url, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Incoming streams:", response.json())
get_incoming_streams()
6. Enable SecureToken Protection
Node.js
async function enableSecureToken() {
const tokenConfig = { enabled: true };
try {
const response = await axios.put(
`${wowzaApiUrl}/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/security`,
tokenConfig,
{ auth: { username, password } }
);
console.log('SecureToken enabled:', response.data);
} catch (error) {
console.error('Error enabling SecureToken:', error.response.data);
}
}
enableSecureToken();
Python
def enable_secure_token():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/security"
token_config = {"enabled": True}
response = requests.put(url, json=token_config, auth=HTTPBasicAuth('your-username', 'your-password'))
print("SecureToken enabled:", response.json())
enable_secure_token()
7. Restart Wowza Services
Node.js
async function restartServer() {
try {
const response = await axios.put(`${wowzaApiUrl}/servers/_defaultServer_/actions/restart`, {}, {
auth: { username, password }
});
console.log('Server restarted:', response.data);
} catch (error) {
console.error('Error restarting server:', error.response.data);
}
}
restartServer();
Python
def restart_server():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/actions/restart"
response = requests.put(url, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Server restarted:", response.json())
restart_server()
8. List Transcoder Templates
Node.js
async function listTranscoderTemplates() {
try {
const response = await axios.get(`${wowzaApiUrl}/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/transcoder/templates`, {
auth: { username, password }
});
console.log('Transcoder templates:', response.data);
} catch (error) {
console.error('Error listing templates:', error.response.data);
}
}
listTranscoderTemplates();
Python
def list_transcoder_templates():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/transcoder/templates"
response = requests.get(url, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Transcoder templates:", response.json())
list_transcoder_templates()
9. Set Application Timeouts
Node.js
async function setTimeouts() {
const timeoutConfig = { idleTimeout: 300 };
try {
const response = await axios.put(
`${wowzaApiUrl}/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/configuration`,
timeoutConfig,
{ auth: { username, password } }
);
console.log('Timeout set:', response.data);
} catch (error) {
console.error('Error setting timeout:', error.response.data);
}
}
setTimeouts();
Python
def set_timeouts():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/LiveStreamApp/configuration"
timeout_config = {"idleTimeout": 300}
response = requests.put(url, json=timeout_config, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Timeout set:", response.json())
set_timeouts()
10. Monitor Server Logs
Node.js
async function getServerLogs() {
try {
const response = await axios.get(`${wowzaApiUrl}/servers/_defaultServer_/log4j`, {
auth: { username, password }
});
console.log('Server logs:', response.data);
} catch (error) {
console.error('Error retrieving logs:', error.response.data);
}
}
getServerLogs();
Python
def get_server_logs():
url = f"http://<server-ip>:8087/v2/servers/_defaultServer_/log4j"
response = requests.get(url, auth=HTTPBasicAuth('your-username', 'your-password'))
print("Server logs:", response.json())
get_server_logs()
Next Steps
Combine these advanced tasks into a custom monitoring and management dashboard.
Automate tasks based on triggers, such as resource limits or error conditions.