My church has a video livestream on Sundays and I have it pushed to various platforms, including an rtmp server which then uses ffmpeg to push to an Icecast server encoded as audio only. Then I have an Asterisk server where when the caller calls in during a livestream, they immediately hear the livestream from the Icecast server. This is what I have to make that happen:
[transport-udp] type=transport protocol=udp bind=0.0.0.0 [siptrunk-auth] type=auth auth_type=userpass username=mysipusername password=mysippassword [siptrunk-aor] type=aor contact=sip:voip.provider.com [siptrunk] type=endpoint transport=transport-udp context=from-siptrunk disallow=all allow=ulaw outbound_auth=siptrunk-auth aors=siptrunk-aor [siptrunk-registration] type=registration transport=transport-udp outbound_auth=siptrunk-auth server_uri=sip:voip.provider.com client_uri=sip:email@example.com contact_user=inbound-calls retry_interval=60 [siptrunk-identify] type=identify match=voip.provider.com endpoint=siptrunk
[from-siptrunk] exten => inbound-calls,1,Verbose(1,Playing some music.) same => n,Answer same => n,MusicOnHold(ulawstream) same => n,Hangup()
[ulawstream] mode=custom application=/usr/sbin/moh.sh
#!/bin/bash if -n "`ls /tmp/asterisk-moh-pipe.*`" ; then rm /tmp/asterisk-moh-pipe.* fi PIPE="/tmp/asterisk-moh-pipe.$$" mknod $PIPE p /usr/sbin/mplayer https://my.icecastserver.com/live.mp3 -really-quiet -quiet -ao pcm:file$ rm $PIPE
I had to also install mplayer & edit the modules.conf file and uncomment res_musiconhold.so.
What I am trying to figure out is how to have it hang up if someone calls in and there is no Icecast stream happening, and also hang up when the Icecast stream ends. Is this possible? How would I accomplish this?