Skip to content
This repository has been archived by the owner on May 6, 2020. It is now read-only.

Creating your own storage service for recordings

mpermar edited this page Sep 1, 2011 · 2 revisions

Rayo's record command lets you record media and returns URIs to the media files that have been recorded as is specified in the Rayo Specification. By default, the Rayo Server will record the different files in the filesystem and will return an URI to these files. So for example after having recorded a file you would get presence message with the following content:

  <complete xmlns='urn:xmpp:rayo:ext:1'>
    <success xmlns='urn:xmpp:rayo:record:complete:1' uri="file:/tmp/rayo7451601434771683422.mp3"/>
  </complete>

Filesystem is nice but chances are you are interested in more advanced storage mechanisms like posting the files to some Web Service, uploading the files to a remote storage like Amazon S3, etc. Fortunately, the Rayo Server lets you plug your own storage implementations very easily and without requiring to modify any code or configuration file. To do this, Rayo takes adanvage of Java's SPI infrastructure.

Creating your own Storage Service.

If you want to provide you own storage service implementation you will have to implement the StorageService interface, which provides just a single method:

   public URI store(File file, com.voxeo.moho.Participant participant) throws IOException;

The store method, receives a file which contains the media that has been recorded plus a Participant object which can be used to get context information about the recording and returns an URI to the newly created resource. Whatever you do to store the file is up to you. Rayo will grab the returned URI and will add it to the complete XMPP message. So for example if you have a service that uploads the recordings to Dropbox and returns an URI to the dropbox resource then your complete XMPP message would be similar to this one:

<presence to='16577@app.rayo.net/1' from='9f00061@call.rayo.net/fgh4590'>
  <complete xmlns='urn:xmpp:rayo:ext:1'>
    <stop xmlns='urn:xmpp:rayo:ext:complete:1' uri="http://dl.getdropbox.com/u/123456/recording-001.mp3" />
  </complete>
</presence>

Using participant to grab context information

The participant object in the StorageService's store method is an instance of com.voxeo.moho.Participant which commonly will be either a Call or a Conference depending on which was the target of the Recording component.

In either way you can use that participant object to grab context information about the call or about the conference and its participants. Below is an hypothetical example:

    @Override
    public URI store(File file, Participant participant) throws IOException {
		
        if (participant instance of com.voxeo.moho.Call) {
            Call call = (Call)participant;
            Iterator<String> it = call.getHeaderNames();
            while(headers.hasNext()) {
                String key = it.next();
                String value = call.getHeader(key);
                // Do stuff
            }
        }
        return file.toURI();
    }

Packaging and deploying your own storage service implementation

Once you have your Storage Service implementation ready you need to package it in a JAR file. But before doing that, you need to add an SPI resource descriptor file. As you will see, this is not a very hard task. However you may find the official docs at Oracle's website.

Basically you need to create the following text file and add it to your JAR file:

   META-INF/services/com.rayo.core.recording.StorageService

And inside that text file you add one line for each of your implementations of the StorageService interface, like for example

com.acme.company.DropboxStorageService    # Dropbox Storage Service

And that is it. Rayo Server's default storage service is also defined as an SPI implementation, so that should serve you as an example. Check it out here.