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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations