Search in sources :

Example 1 with IPendingServiceCallback

use of org.red5.server.api.service.IPendingServiceCallback in project red5-client by Red5.

the class RTMPSClientTest method test31.

// https://github.com/Red5/red5-client/pull/31
@Test
public void test31() throws InterruptedException {
    final RTMPSClient client = new RTMPSClient();
    client.setConnectionClosedHandler(new Runnable() {

        @Override
        public void run() {
            System.out.println("Connection closed");
        }
    });
    client.setExceptionHandler(new ClientExceptionHandler() {

        @Override
        public void handleException(Throwable throwable) {
            throwable.printStackTrace();
        }
    });
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            client.connect(PropertiesReader.getProperty("rtmps.server"), Integer.valueOf(PropertiesReader.getProperty("rtmps.port")), PropertiesReader.getProperty("rtmps.app"), new IPendingServiceCallback() {

                @Override
                public void resultReceived(IPendingServiceCall result) {
                    System.out.println("resultReceived: " + result);
                    ObjectMap<?, ?> map = (ObjectMap<?, ?>) result.getResult();
                    String code = (String) map.get("code");
                    System.out.printf("Response code: %s\n", code);
                    if ("NetConnection.Connect.Rejected".equals(code)) {
                        System.out.printf("Rejected: %s\n", map.get("description"));
                        client.disconnect();
                    } else if ("NetConnection.Connect.Success".equals(code)) {
                        System.out.println("Success: " + result.isSuccess());
                        // if its oflaDemo, get the list of flvs
                        if ("oflaDemo".equals(PropertiesReader.getProperty("rtmps.app"))) {
                            client.invoke("demoService.getListOfAvailableFLVs", new Object[] {}, new IPendingServiceCallback() {

                                @Override
                                public void resultReceived(IPendingServiceCall call) {
                                    System.out.println("methodCallCallback");
                                    Map<?, ?> map = (Map<?, ?>) call.getResult();
                                    System.out.printf("Response %s\n", map);
                                }
                            });
                        }
                        client.createStream(new IPendingServiceCallback() {

                            @Override
                            public void resultReceived(IPendingServiceCall call) {
                                Number streamId = (Number) call.getResult();
                                // live buffer 0.5s / vod buffer 4s
                                if (Boolean.valueOf(PropertiesReader.getProperty("rtmps.live"))) {
                                    client.ping(Ping.CLIENT_BUFFER, streamId, 500);
                                    client.play(streamId, PropertiesReader.getProperty("rtmps.name"), -1, -1);
                                } else {
                                    client.ping(Ping.CLIENT_BUFFER, streamId, 4000);
                                    client.play(streamId, PropertiesReader.getProperty("rtmps.name"), 0, -1);
                                }
                            }
                        });
                    }
                }
            });
        }
    });
    t.start();
    t.join();
    System.out.println("Joined");
    Thread.sleep(60000L);
    // disconnect
    client.disconnect();
}
Also used : IPendingServiceCallback(org.red5.server.api.service.IPendingServiceCallback) IPendingServiceCall(org.red5.server.api.service.IPendingServiceCall) ClientExceptionHandler(org.red5.client.net.rtmp.ClientExceptionHandler) ObjectMap(org.red5.io.utils.ObjectMap) ObjectMap(org.red5.io.utils.ObjectMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with IPendingServiceCallback

use of org.red5.server.api.service.IPendingServiceCallback in project red5-client by Red5.

the class BaseRTMPClientHandler method createStream.

@Override
public void createStream(IPendingServiceCallback callback) {
    log.debug("createStream - callback: {}", callback);
    IPendingServiceCallback wrapper = new CreateStreamCallBack(callback);
    invoke("createStream", null, wrapper);
}
Also used : IPendingServiceCallback(org.red5.server.api.service.IPendingServiceCallback)

Example 3 with IPendingServiceCallback

use of org.red5.server.api.service.IPendingServiceCallback in project red5-client by Red5.

the class BaseRTMPClientHandler method releaseStream.

public void releaseStream(IPendingServiceCallback callback, Object[] params) {
    log.debug("releaseStream - callback: {}", callback);
    IPendingServiceCallback wrapper = new ReleaseStreamCallBack(callback);
    invoke("releaseStream", params, wrapper);
}
Also used : IPendingServiceCallback(org.red5.server.api.service.IPendingServiceCallback)

Example 4 with IPendingServiceCallback

use of org.red5.server.api.service.IPendingServiceCallback in project red5-server-common by Red5.

the class ServiceUtils method invokeOnAllScopeConnections.

/**
 * Invoke a method on all connections of a scope and handle result.
 *
 * @param scope
 *            scope to get connections from
 * @param method
 *            name of the method to invoke
 * @param params
 *            parameters to pass to the method
 * @param callback
 *            object to notify when result is received
 */
public static void invokeOnAllScopeConnections(IScope scope, String method, Object[] params, IPendingServiceCallback callback) {
    ClientInvokeEvent event = ClientInvokeEvent.build(method, params, callback);
    scope.dispatchEvent(event);
}
Also used : ClientInvokeEvent(org.red5.server.net.rtmp.event.ClientInvokeEvent)

Example 5 with IPendingServiceCallback

use of org.red5.server.api.service.IPendingServiceCallback in project red5-server-common by Red5.

the class RTMPConnection method invoke.

/**
 * {@inheritDoc}
 */
public void invoke(String method, Object[] params, IPendingServiceCallback callback) {
    IPendingServiceCall call = new PendingCall(method, params);
    if (callback != null) {
        call.registerCallback(callback);
    }
    invoke(call);
}
Also used : IPendingServiceCall(org.red5.server.api.service.IPendingServiceCall) PendingCall(org.red5.server.service.PendingCall)

Aggregations

IPendingServiceCallback (org.red5.server.api.service.IPendingServiceCallback)10 IPendingServiceCall (org.red5.server.api.service.IPendingServiceCall)7 ObjectMap (org.red5.io.utils.ObjectMap)5 Notify (org.red5.server.net.rtmp.event.Notify)4 Test (org.junit.Test)3 PendingCall (org.red5.server.service.PendingCall)3 ClientExceptionHandler (org.red5.client.net.rtmp.ClientExceptionHandler)2 IEvent (org.red5.server.api.event.IEvent)2 IEventDispatcher (org.red5.server.api.event.IEventDispatcher)2 RTMPConnection (org.red5.server.net.rtmp.RTMPConnection)2 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Timer (java.util.Timer)1 INetStreamEventHandler (org.red5.client.net.rtmp.INetStreamEventHandler)1 RTMPClient (org.red5.client.net.rtmp.RTMPClient)1 StreamingProxy (org.red5.proxy.StreamingProxy)1 IConnection (org.red5.server.api.IConnection)1 IScope (org.red5.server.api.scope.IScope)1 IServiceCall (org.red5.server.api.service.IServiceCall)1 ClientInvokeEvent (org.red5.server.net.rtmp.event.ClientInvokeEvent)1