Event Handlers

HTTP event streaming is implemented in the PowerMedia WMS EventHandler resource.  

When the client wishes to receive asynchronous events, it uses the web service to create an EventHandler and subscribes to specific event types. When the client performs an HTTP GET on the newly created EventHandler, the web service responds with a 200 OK; however, the TCP connection remains open until the client destroys the EventHandler. Event data related to resources and event types subscribed to will be pushed to the client until the Eventhandler is deleted by the client.

XML Definition

<eventhandlers size="<size>">
    <eventhandler identifier=" <identifier> "appid=" <appid> "
    href="http://server/dialogicwebservice/mediacontrol/eventhandlers/<identifier>" >
    <eventsubscribe resourceid="<resourceid>"  resourcetype="< resourcetype> " 
      type="<eventtype>">
      </eventsubscribe>
      </eventhandler>
     ...
</eventhandlers>

<event type="<eventtype>" data="<data>" resourceid="<resourceid>"
    resourcetype="< resourcetype>" >
</event>

Properties

EventHandler Properties

Name

Description

Type

Input / Output

Optional / Mandatory

identifier

Unique identifier assigned to the specific instance of the resource.  This identifier is used by the web service client when performing actions on the resource.

String

Output

N/A

appid

Unique application id included in the original HTTP POST creation process that is utilized by the web service such that clients only have access to resources that they created.

String

Output

N/A

href

An HTTP reference to the specific resource.

String

Output

N/A


EventSubscribe Properties

Name

Description

Type

Input / Output

Optional / Mandatory

resourceid

Unique resource identifier to monitor for events.

Default:Any

String

Input / Output

Optional

resourcetype

Type of resource to monitor for events, such as player, collector.

Supported resource types: “player” “recorder” “collector” “playercollector” and “any”. “any” means all the supported resource types.

Default: any

String

 

Input / Output

Optional

type

Event type to monitor, such as such as play complete, dtmf.

Supported event types: “play_complete” “record_complete” “dtmf” , “keepalive” and “any”. The “keepalive” event will be sent every five mins after being subscribed. "any” means all the supported event types.

Default: any

String

 

 

Input / Output

Optional

action

Add or remove the event subscribe: add, remove.

Default: add

String

Input/Output

Optional

 

Event Properties

Name

Description

Type

Input / Output

Optional / Mandatory

type

Event type

String

Output

N/A

data

Event data

String

Output

N/A

resourceid

IP of resource sending event

String

 

Input

N/A

resourcetype

Type of resource

String

 

Output

N/A


Interaction Diagram

Event Handler Sequence Diagram

The following diagram illustrates the event handler sequence.

dg_event_handler.png

 

Java Sample Code

    public void CreateEventHandler() {
        logger.info("EventMonitor:: CreateEventHandler - Entered.");
        //Create a HttpURLConnection with the correct server
        //Send request to create event handler and retrieve response
        String response = "";
        String requestBody = "<eventhandler>\r\n" +
                             "/t<eventsubscribe type=\"any\" resourceid=\"any\"/>\r\n" +
                             "</eventhandler>";
        HttpURLConnection connection = utils.SendHTTPRequest("http://" +
        MainSipServlet.WMSHost + ":81/DialogicWebService/mediacontrol/eventhandlers",
                                                             "POST",
                                                             requestBody);
        if (connection != null) {
            response = utils.GetHTTPStringResponse(connection);
        }
        //Retrieve response codes
        int responseCode = 0;
        try {
            responseCode = connection.getResponseCode();
        } catch (IOException ex) {
            Logger.getLogger(EventMonitor.class.getName()).log(Level.SEVERE, null, ex);
        }
        String responseMessage = "";
        try {
            responseMessage = connection.getResponseMessage();
        } catch (IOException ex) {
            Logger.getLogger(EventMonitor.class.getName()).log(Level.SEVERE, null, ex);
        }
        String responseLocation = connection.getHeaderField("location");
        //close the connection
        connection.disconnect();
        //log results
        logger.info("EventMonitor:: CreateEventHandler - Http response code =" +
         responseCode);
        logger.info("EventMonitor:: CreateEventHandler - Http response message =" +
        responseMessage);
        logger.info("EventMonitor:: CreateEventHandler - Http response location =" +
        responseLocation);
        if (responseCode == 201) {
            eventHandlerRef = responseLocation;
        }
        logger.info("EventMonitor:: CreateEventHandler - Exited.");
    }