Wowza Community

List active streams status & insert into MySQL DB

Hello,

I hope I am posting this in the right location. If not, please forgive me as I am new to Wowza. I have a project I am working on where we have a webpage that will display streams. What we are wanting to do is create dynamic players. I.E. the players only display if they are active. Now that part is pretty simple as I can do this via PHP script to display just the active players as they come online.

Now where we are having issues is we need some data to trigger off of. Looking for a way via JSON output an attribute I.E. “Active: true/false” or something similar along those lines. Also the output would need to display the stream key so we know who’s stream it is.

Once we have that, we need to insert that info into a DB. This is where it gets even more trivial is how to sync the streamers status to their DB entry.

At the very least need to know a way to display a streamers stream status with their stream key via JSON.

If there is anyone who can shed some light on this and offer some suggestions this would be greatly appreciative.

-Thanks!

Hello,

It’s been a few days since you posted this thread so not sure if you still need help with this or not.

You have not mentioned with Wowza version are you using. Version 4.5 has a lot of newer API functionality which might have something related to this. I am not sure because 4.5 was released not long ago and I’m also still exploring the newer calls.

Otherwise, this task entails custom module development. You can take cue from examples and dwell on those. If you are not interested in doing it yourself we can write one for your needs. please PM me or alternatively ask Wowza for the consultant list.

Thanks

Inderjeet

Hi Texan78,

You’re actually lucky! Wowza 4.5 has HTTP API call that can list the incoming streams (streamkeys as you call them, I guess). So if you already have the stream names in your database already, you can compare them with the JSON data returned by the HTTP request. Alternatively, you can fetch the list of the incoming streams and set them as active or something in the db (and the rest as inactive, but this is bad logic if your db is big).

Take a look at: https://www.wowza.com/docs/live-sources-query-examples

I am a bit busy these days but can create a sample in 2-3 days when free (or see if I can extract from somewhere). But trust me, it’s not difficult at all now. It will take 30 mins to do this now while it took us 30+ days when we needed this a few years ago.

Best wishes!

Inderjeet

Hi Texan78,

Curl is only one of the many ways. You can straightaway enter the URL in a browser and it should give you some output.

Anyway, I have quickly crated something, which I wanted to send you by PM but i couldn’t find a away to send you a personal message.

Here is the basic shabby code in PHP, will run from Linux web server, even windows if Curl works. Please excuse any errors:

<?php
/*
Created by Inderjeet S Sodhi for Texan78 
Wowza Forums
Edited: 24 September 2016
Objectss on the Wowza server. Hope this helps.
Thanks
Inderjeet

You need to whitelist the IP from where the calls will originate, in Server.xml file (or VHost?, please check the post). This will not work from your home PC if you don’t have a static/fixed IP unless you want to keep adding removing it in the file every few hours.

Thanks

Inderjeet

I am not sure if you posted a screenshot before or after editing the file. In the I am still seeing 127.0.0.1 which is the default. Even shared IPs are static, they remain forever until changed. I raised that point assuming you’d try to access the API from your home/office developer PC, which won’t work unless you do what you said, openening the API to everyone (avoid doing that).

As Jason said, let support people help you with this step by step.

I have removed the code for certain reasons but you must’ve taken it by now. Let me know if you need it again.

All the best!

Inderjeet

Hi Texan78,

Are you able to query the Wowza server via REST API? You should be able to get a list of currently active streams by sending a GET request to the following REST API endpoint:

http://localhost:8087/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/{appName}/instances/_definst_

where {appName} is the name of your Wowza application.

You can do this from PHP as swexpert mentioned. You can receive JSON data similar to:

{
"serverName": "_defaultServer_"
"incomingStreams": [1]
0:  {
"sourceIp": ""
"isPTZEnabled": false
"applicationInstance": "_definst_"
"name": "wowzademo.stream"
"isRecordingSet": false
"isStreamManagerStream": true
"isPublishedToVOD": false
"isConnected": true
"ptzPollingInterval": 2000
}-
-
"outgoingStreams": [0]
"recorders": [0]
"streamGroups": [0]
"name": "_definst_"
}

In your PHP code, ensure that you have your HTTP request correctly sending the headers.

I hope this helps. If you continue to have issues, do please open a support ticket so that we can take a look at your code.

Michelle

Hi,

If you use a Content-Type: application/json header in your REST API command, the response from the server should be in the JSON format.

You can append monitoring/current to the REST API endpoint you are using to get the statistics for a given incoming stream.

Michelle

Hi,

You should be able to infer the IsConnected value by checking the uptime value. If it is 0, then the stream is not connected. It’s also a good idea to use the bytesIn value, as a 0 in this parameter indicates the stream is not sending any data at the time of the query. The TotalConnections is included in the respons, and the Name value is already an explicit value since it was used in the query. But if you do want a simple response that includes only these three values, then you will need to create an HTTPProvider.

Michelle

Hello,

Have you verified that this rejection is not happening because the port is not open?

Can you check that port 8087 is open on this IP address here:

http://www.yougetsignal.com/tools/open-ports/

If you do find the port is not open then it may be best to submit a support ticket so that we can take a deeper look at your logs and configuration and work with you one on one through our ticket system

Regards,

Jason Hatchett

Hello,

Yes I am still looking or a solution.

I am using Wowza v4.5.

I am new to Wowza and I have gone through all the support docs and while they are very detailed. I seem to be overlooking what it is I am looking for.

I am essentially just needing to pull a JSON request that at least shows the users stream key and show if the stream is Active or Not Active. From there I can write a script that pulls that info and updates the database.

So I am stuck at trying to query the Wowza server to show this information.

Any help would be greatly appreciated as I have been stuck for months.

-Thanks

Hello,

Thanks for the response. That is pretty much what I am trying to do. The streamkeys are already in the DB. I have a column for stream status too I.E. StreamStatus with the response true or false. So if the stream is active I need a way to update that to true and if it is offline then false.

The main issue is trying to make the HTTP request. I think if I can get that far I may be able to come up with something. I have never worked with CURL before though.

-Thanks!

Thank you so much for you help and the example.

One of the issues I am having is being able to access the data via the API. I have followed all the articles and read numerous forum threads but, I am unable to access the REST API. I get this error below.

4.5.0

403

Your IP address (XX.XX.XX.XX) has been blocked

I have masked my IP address above for security reasons. I think if I can figure that part out the rest should be fairly easy going forward or at least give me something to work with.

-Thanks

Hello,

Thanks for the quick reply. I have done that and also did * which should allow me to check it from any IP but still get blocked error msg. I have a sticky static IP so it doesn’t change even though it is not a true static IP. The web host where the script will be called from is not on a dedicated server with a dedicated IP ether. It is on a shared host but, the IP won’t change ether. Here is a screen shot of my settings from the server.xml

This is one of the issues I have been struggling with for months and haven’t been able to get it to work. Is there something below I am not doing correctly?

I have been playing around this with this but, I was able to finally call it in the browser. The code though did not work. It just gave me the error “Could not process. Error: ()couldn’t connect to host” and I removed the hostname/IP from the error.

One thing I did notice about the code you posted was it was looking for $api_username and $api_password which was different from the variable that was set for it. I changed it and still no luck.

I don’t have the original code anymore though since I was playing around with it and didn’t have it saved since it was on here.

This http://hostname:8087/v2/servers/defaultServer/vhosts/defaultVHost/applications/live/instances when I bring it up in the browser has info a stream is active. I am just not able to get the script working or create one so I can query information from it to update my DB. Also need viewer counts per instance as well and timestamp but, that one doesn’t include that.

Ok so I found what I needed GET /v2/servers/{serverName}/vhosts/{vhostName}/applications/{appName}/instances/{instanceName}/incomingstreams/{streamName} but how do I get that to request as JSON as REST API Documentations shows?

Also is there one that will return how many viewers a certain stream has?

-Thanks

You can append monitoring/current to the REST API endpoint you are using to get the statistics for a given incoming stream.

Michelle

Yes! Thank you!

Now if I can just figure out the PHP code to make a GET request as I am not having any luck. I can make it in the browser no problem but not able to make a cURL request in PHP.

I am assuming if I just want certain responses I.E. Name, IsConnected, TotalConnections and that is it I will need to make my own HTTP provider?

-Thanks!

Well come to find out the reason I couldn’t get any of the scripts to work is because my web host (Bluehost) blocks ports on shared hosting accounts. In order to get ports open you have to have a dedicated IP. So I got a dedicated IP and was able to put together a script that allows me to parse the information I need.

So if I am wanting Name, IsConnected, TotalConnections in one response I will need to make my own HTTP provider?

Would it be possible to just edit one and add the TotalConnections to and if so how? If I can get one response that has that I will be golden.

-Thanks!