Try Live Demo

Ant Media Server provides webhooks for making your system/app know when certain events occurs. Therefore, you can register your URL to Ant Media Server which makes POST request when a live stream is started, finished or recorded. Firstly,  let’s look at how to register your backend URL to Ant Media Server as a webhook. After that, we’ll provide reference for webhooks.

webhook ant media server

Register Your Webhook URL

You can add default webhook URL to your streaming app on Ant Media Server. In addition, it lets you add custom specific webhook URL’s in creating broadcast.

Add default Webhook URL

In order to add default URL,  just follow the steps below

  • Open your apps red5-web.properties  and add settings.listenerHookURL property to that file. red5-web.properties file is under webapps/<app_name>/WEB-INF  folder
    ...
    
    settings.listenerHookURL=http://www.example.com/webhook/
    
    ...
  • For 1.6.0 and earlier versions, open your apps red5-web.xml file and add settings.listenerHookURL to the app.settings bean.
    ...
    <bean id="app.settings" class="io.antmedia.AppSettings" >
    ...
       <property name="listenerHookURL" value="${settings.listenerHookURL}" />
    ...
    </bean>
    ...
  • Restart the server on command line
    sudo service antmedia restart

Right now, there is a default webhook URL for your app.

Add Custom Webhook for Streams

Ant Media Server provides creating streams through rest service. Therefore, If you want to specify the webhook URL for each stream, you can use createBroadcast method in rest service.  createBroadcast method has Broadcast object parameter which has listenerHookURL field . As a result,  you can set listenerHookURL for creating stream at Ant Media Server.

Here is a sample JSON for using createBroadcast method with Postman

Webhooks List

It’s time to know when Ant Media Server calls webhooks with which parameters. Here is a simple list for that

  • liveStreamStarted: Ant Media server calls this hook when a new live stream is started. It sends POST (application/x-www-form-urlencoded) request to URL with following variables
    • id:  stream id of the broadcast
    • action: “liveStreamStarted”
    • streamName: stream name of the broadcast. It can be null.
    • category:  stream category of the broadcast. It can be null.
  • liveStreamEnded: Ant Media Server calls this hook when a live stream is ended. It sends POST(application/x-www-form-urlencoded) request to URL with following variables.
    • id: stream id of the broadcast
    • action: “liveStreamEnded”
    • streamName: stream name of the broadcast. It can be null.
    • category: stream category of the broadcast. It can be null.
  • vodReady: Ant Media Server calls this hook when the recording of the live stream is ended. It sends POST(application/x-www-form-urlencoded) request to URL with following variables.
    • id: stream id of the broadcast
    • action: “vodReady”
    • vodNamevod file name

That’s all. As a result, you can take some custom actions according to your project by checking action variable in your backend URL.

We hope this post will help you to make automation in your project.  Please keep in touch if you have any question. We will be happy if we can help you.


Ahmet Oguz Mermerkaya

Oguz is the co-founder of Ant Media. His tech stack includes VxWorks, UML, Rhapsody in C++. Java, OSGi, Swing, JSF, Web, PHP, FFmpeg API, Native WebRTC, Java EE, Hibernate, Spring, MongoDB, MySQL, Angular, JavaScript, HTML5, Android (Native) and iOS (Native). Oguz is one of the writers of "Merhaba Android", one of the first books published in Turkey about Android app programming. His second book is about HTML5 & CSS3. He has attended several conferences and universities talking about Android, business life and technical issues. He is a member of the GDG Community and also the founder of GDG Ankara.

chatsimple
Warning: Undefined array key "promocode" in /home/mirror.antmedia.io/public_html/wp-content/themes/hestia-child/footer.php on line 70