Platform documentation & tutorials

Integrate Panda with your web app

Cloud Notifications

Rather than polling Panda to find when a video has finished encoding, Panda allows you to provide a callback url and subscribe to events occurring during the encoding process. The notification Url is defined per cloud and can be edited through the web interface or the API.

To manage your notifications, log into your Panda account, select your cloud and click on “notifications” (assuming that you already have a cloud). Here you’ll be able to specify an url and select events you would like to receive. One you’ve saved your notification settings, notifications will be sent for any new videos and encodings of this cloud.

How to Integrate notification in your App.

For each event you will receive a POST request, containing the event name (ex: encoding-complete) and some ids the videos or encodings having their status changed, as form data.

Panda is expecting a 200 response from you. Otherwise it will retry the notification within an exponential interval of time and during 24 hours.

Panda provides the following events:

Video events

video-created

This is called once a video has downloaded (if a url was given), validated, and uploaded to your S3 bucket. The status will either be success or fail. An array of encoding ids is provided, although note that the encodings will not have been processed at this state.

The post request body contains the video id and metadata that has been extracted. For example in ruby

{
  "event" => "video-created",
  "video_id" => '123234',
  "encoding_ids" => {0 => 'firstid', 1 => 'secondid'}
}

And in PHP

$_POST["event"] // => "video-created"
$_POST["video_id"] // => '123234'
$_POST["encodings_ids"][0] // => 'firstid'

video-encoded

This is called when all encodings for a video have been completed. Note that this may be returned multiple times if, for example, a new encoding is added for an existing video.

{
  "event" => "video-encoded",
  "video_id" => "bfa6029038de24e4494f20a166700021",
  "encoding_ids" => {0 => 'firstid', 1 => 'secondid'}
}

Encoding events

If you would like to show videos to your users before all encodings are complete these events can be useful.

encoding-progress

This is called approximately every 10s while an encoding is processing, and returns the percentage complete. Use with care since this will generate a lot of traffic!

{
  "event" => "encoding-progress",
  "encoding_id" => 'firstid',
  "progress" => 23
}

encoding-complete

This is called for each encoding when the encoding is done (or failed)

The post body contains encoding information

{
  "event" => "encoding-complete",
  "encoding_id" => "bfa6029038de24e4494f20a166700021"
}

After receiving those IDs you can easily and securely retrieve the state of your videos/encoding by simply using your current library.

example:

  Panda::Video.find(params['video_id']).status
  => 'success'      

Testing notifications in development

Because your development machine is rarely accessible from the Internet, the notifications cannot be sent to you directly. At Panda, we use localtunnel to give access to our local development machine to the Internet.

1)

$ gem install localtunnel
# 8080 is the port of the local webserver
$ localtunnel 8080
  This localtunnel service is brought to you by Twilio.
  Port 8080 is now publicly accessible from http://3wu2.localtunnel.com

2) Now set the notification URL in your development cloud to http://3wu2.localtunnel.com/path/to/api/end-point

3) Your local app starts receiving notification callbacks

Alternatively, if you just want to see what output Panda is producing, create a new target on postbin.org and set it up as the notification end-point. Postbin will record Panda’s callbacks and let you see them trough their web interface.