}
if (okayToConnect) {
log.debug("Connected - Client: {}", conn.getClient());
call.setStatus(Call.STATUS_SUCCESS_RESULT);
if (call instanceof IPendingServiceCall) {
IPendingServiceCall pc = (IPendingServiceCall) call;
pc.setResult(getStatus(NC_CONNECT_SUCCESS));
}
// Measure initial roundtrip time after
// connecting
conn.getChannel(2).write(
new Ping(Ping.STREAM_CLEAR, 0,
-1));
conn.startRoundTripMeasurement();
} else {
log.debug("Connect failed");
call
.setStatus(Call.STATUS_ACCESS_DENIED);
if (call instanceof IPendingServiceCall) {
IPendingServiceCall pc = (IPendingServiceCall) call;
pc
.setResult(getStatus(NC_CONNECT_REJECTED));
}
disconnectOnReturn = true;
}
} catch (ClientRejectedException rejected) {
log.debug("Connect rejected");
call.setStatus(Call.STATUS_ACCESS_DENIED);
if (call instanceof IPendingServiceCall) {
IPendingServiceCall pc = (IPendingServiceCall) call;
StatusObject status = getStatus(NC_CONNECT_REJECTED);
if (rejected.getReason() != null)
status.setApplication(rejected
.getReason());
pc.setResult(status);
}
disconnectOnReturn = true;
}
}
}
} catch (RuntimeException e) {
call.setStatus(Call.STATUS_GENERAL_EXCEPTION);
if (call instanceof IPendingServiceCall) {
IPendingServiceCall pc = (IPendingServiceCall) call;
pc.setResult(getStatus(NC_CONNECT_FAILED));
}
log.error("Error connecting {}", e);
disconnectOnReturn = true;
}
// Evaluate request for AMF3 encoding
if (Integer.valueOf(3).equals(params.get("objectEncoding"))
&& call instanceof IPendingServiceCall) {
Object pcResult = ((IPendingServiceCall) call)
.getResult();
Map<String, Object> result;
if (pcResult instanceof Map) {
result = (Map) pcResult;
result.put("objectEncoding", 3);
} else if (pcResult instanceof StatusObject) {
result = new HashMap<String, Object>();
StatusObject status = (StatusObject) pcResult;
result.put("code", status.getCode());
result.put("description", status.getDescription());
result.put("application", status.getApplication());
result.put("level", status.getLevel());
result.put("objectEncoding", 3);
((IPendingServiceCall) call).setResult(result);
}
rtmp.setEncoding(Encoding.AMF3);
}
}
} else if (action.equals(ACTION_DISCONNECT)) {
conn.close();
} else if (action.equals(ACTION_CREATE_STREAM)
|| action.equals(ACTION_DELETE_STREAM)
|| action.equals(ACTION_RELEASE_STREAM)
|| action.equals(ACTION_PUBLISH)
|| action.equals(ACTION_PLAY) || action.equals(ACTION_SEEK)
|| action.equals(ACTION_PAUSE)
|| action.equals(ACTION_CLOSE_STREAM)
|| action.equals(ACTION_RECEIVE_VIDEO)
|| action.equals(ACTION_RECEIVE_AUDIO)) {
IStreamService streamService = (IStreamService) getScopeService(
conn.getScope(), IStreamService.class,
StreamService.class);
Status status = null;
try {
if (!invokeCall(conn, call, streamService)) {
status = getStatus(NS_INVALID_ARGUMENT).asStatus();
status.setDescription("Failed to " + action
+ " (stream ID: " + source.getStreamId() + ")");
}
} catch (Throwable err) {
log.error("Error while invoking " + action
+ " on stream service.", err);
status = getStatus(NS_FAILED).asStatus();
status.setDescription("Error while invoking " + action
+ " (stream ID: " + source.getStreamId() + ")");
status.setDetails(err.getMessage());
}
if (status != null) {
channel.sendStatus(status);
}
} else {
invokeCall(conn, call);
}
} else if (conn.isConnected()) {
// Service calls, must be connected.
invokeCall(conn, call);
} else {
// Warn user attemps to call service without being connected
log.warn("Not connected, closing connection");
conn.close();
}
if (invoke instanceof Invoke) {
if ((source.getStreamId() != 0)
&& (call.getStatus() == Call.STATUS_SUCCESS_VOID || call
.getStatus() == Call.STATUS_SUCCESS_NULL)) {
// This fixes a bug in the FP on Intel Macs.
if (log.isDebugEnabled()) {
log
.debug("Method does not have return value, do not reply");
}
return;
}
boolean sendResult = true;
if (call instanceof IPendingServiceCall) {
IPendingServiceCall psc = (IPendingServiceCall) call;
Object result = psc.getResult();
if (result instanceof DeferredResult) {
// Remember the deferred result to be sent later
DeferredResult dr = (DeferredResult) result;
dr.setServiceCall(psc);
dr.setChannel(channel);