FusionPBX and Shoutcast/Icecast Streams

Status
Not open for further replies.

pksml

New Member
Dec 20, 2022
7
2
3
44
Hello fellow FusionPBX and FreeSwitch users. I'm looking for some advice about how to build my application.

I have an Icecast stream that will be broadcasting only at certain times. I have a phone number that people can dial in to hear this stream.

If the stream is not live, I'd like to play a recording saying the stream isn't live and then hang up.

How can FusionPBX test if the Icecast stream is live?

Is Lua the only way to go? If so, how would Lua interact with the dialplan for my conditional logic?

BTW the Icecast server has a status webpage that I could scan for a text match to determine if the stream is available.)

Thanks for your thoughts!
 

whut

Active Member
Dec 23, 2022
246
27
28
An ICE cast stream needs to be mp3/mpeg format. aac format will not work as a stream in fusion
 

pksml

New Member
Dec 20, 2022
7
2
3
44
An ICE cast stream needs to be mp3/mpeg format. aac format will not work as a stream in fusion
Thanks for that tidbit. I managed to get Fusion to check for the stream using Lua. I first had to enable CURL in Advanced --> Modules.

Note that it seems Fusion can only connect to HTTP streams as opposed to HTTPS and the HTTP stream must begin with shout://

Here's my basic code:
Code:
-- Session API (Lua)
-- https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Client-and-Developer-Interfaces/Lua-API-Reference/#api-sessions

-- Lua API
-- https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Client-and-Developer-Interfaces/Lua-API-Reference/

-- Using cURL w/ Lua
-- https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_curl_3965033/#lua-usage
-- https://www.pbxforums.com/threads/mod_curl-post-request-responds-with-error-from-lua-script.7407/
-- https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Client-and-Developer-Interfaces/JavaScript/JavaScript-API-Reference/Run_13173558/

-- https://telecom.altanai.com/2020/12/01/why-lua-is-a-good-choice-for-scripting-call-configurations-in-sip-servers-like-kamailio-and-freeswitch/

-- Pattern matching: https://www.lua.org/pil/20.1.html

-- Scripting FreeSWITCH Lua
-- https://hub.packtpub.com/scripting-freeswitch-lua/
-- Better source: Chapter 8 in FreeSwitch 1.8 book from PacktPub

-- fs_cli commands
-- https://developer.signalwire.com/freeswitch/FreeSWITCH-Explained/Modules/mod_commands_1966741/

session:setVariable ( "curl_timeout", "3" )
session:execute ( "curl", "http://myserver.com:8000" )

curl_response_code = session:getVariable ( "curl_response_code" )
curl_response      = session:getVariable ( "curl_response_data" )

freeswitch.consoleLog ( "NOTICE", "cURL response code: " .. curl_response_code .. "\n" )
freeswitch.consoleLog ( "NOTICE", "cURL response data: " .. curl_response .. "\n" )


if ( string.find ( curl_response, "STRING_OF_TEXT_TO_SEARCH_FOR" ) )
then
    -- Stream IS live. Play stream followed by a "thanks for listening" outro and hangup

    session:streamFile ( "shout://myserver.com:8000/stream" );
    session:streamFile ( "/var/www/thanks_for_listening.wav" )
    session:hangup()

else
    -- Stream not live, so play recording and hang up.

    freeswitch.consoleLog ( "NOTICE", "Stream is NOT live!" .. "\n" )

    -- Play the recording

    session:streamFile ( "/var/www/stream_not_live.wav" )

    -- Hangup

    session:hangup()

end

Then in the dialplan, I created one entry and linked the inbound route to it (see attached images).
 

Attachments

  • 01-inbound-route.png
    01-inbound-route.png
    44.2 KB · Views: 12
  • 02-extension.png
    02-extension.png
    59 KB · Views: 12

pksml

New Member
Dec 20, 2022
7
2
3
44

Use the streams application. There is no need to get into code.
Yes, I've seen that page. I don't understand how you utilize the streams application though. How do you implement a stream into an extension? I don't see any way to reference the stream in the dialplan. (The docs are sorely lacking!)
Use shout for http urls, shouts for https urls
Ahhh, that's good to know. Once again, something the docs didn't cover...

BTW, your "Glamour Shots by Deb" profile picture is awesome :)
 
Status
Not open for further replies.