public void resultReceived(IPendingServiceCall call) {
   log.debug("resultReceived", call);
   if (call.getResult() instanceof ObjectMap<?, ?>) {
     ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
     if (map.containsKey("code")) {
       String code = (String) map.get("code");
       log.debug("Code: {}", code);
       if (StatusCodes.NS_PLAY_START.equals(code)) {
         subscribed = true;
       }
     }
   }
   wrapped.resultReceived(call);
 }
 public void resultReceived(IPendingServiceCall call) {
   Integer streamIdInt = (Integer) call.getResult();
   log.debug("Stream id: {}", streamIdInt);
   log.debug("Connection: {}", conn);
   log.debug("DeleteStreamCallBack resultReceived - stream id: {}", streamIdInt);
   if (conn != null && streamIdInt != null) {
     log.debug("Deleting net stream");
     conn.removeClientStream(streamIdInt);
     // send a delete notify?
     // NetStreamPrivateData streamData = streamDataMap.get(streamIdInt);
     // streamData.handler.onStreamEvent(notify)
     streamDataMap.remove(streamIdInt);
   }
   wrapped.resultReceived(call);
 }
 public void resultReceived(IPendingServiceCall call) {
   Integer streamIdInt = (Integer) call.getResult();
   log.debug("CreateStreamCallBack resultReceived - stream id: {} call: {}", streamIdInt, call);
   log.debug("Connection: {}", conn);
   if (conn != null && streamIdInt != null) {
     log.debug("Setting new net stream");
     NetStream stream = new NetStream(streamEventDispatcher);
     stream.setConnection(conn);
     stream.setStreamId(streamIdInt);
     conn.addClientStream(stream);
     NetStreamPrivateData streamData = new NetStreamPrivateData();
     streamData.outputStream = conn.createOutputStream(streamIdInt);
     streamData.connConsumer =
         new ConnectionConsumer(
             conn,
             streamData.outputStream.getVideo(),
             streamData.outputStream.getAudio(),
             streamData.outputStream.getData());
     streamDataMap.put(streamIdInt, streamData);
     log.debug("streamDataMap: {}", streamDataMap);
   }
   wrapped.resultReceived(call);
 }
 /** {@inheritDoc} */
 @Override
 protected void onCommand(RTMPConnection conn, Channel channel, Header source, ICommand command) {
   log.trace("onCommand: {}, id: {}", command, command.getTransactionId());
   final IServiceCall call = command.getCall();
   final String methodName = call.getServiceMethodName();
   log.debug(
       "Service name: {} args[0]: {}",
       methodName,
       (call.getArguments().length != 0 ? call.getArguments()[0] : ""));
   if ("_result".equals(methodName) || "_error".equals(methodName)) {
     final IPendingServiceCall pendingCall = conn.getPendingCall(command.getTransactionId());
     log.debug("Received result for pending call - {}", pendingCall);
     if (pendingCall != null) {
       if ("connect".equals(methodName)) {
         Integer encoding = (Integer) connectionParams.get("objectEncoding");
         if (encoding != null && encoding.intValue() == 3) {
           log.debug("Setting encoding to AMF3");
           conn.getState().setEncoding(IConnection.Encoding.AMF3);
         }
       }
     }
     handlePendingCallResult(conn, (Invoke) command);
     return;
   }
   // potentially used twice so get the value once
   boolean onStatus = "onStatus".equals(methodName);
   log.debug("onStatus {}", onStatus);
   if (onStatus) {
     Integer streamId = source.getStreamId();
     if (log.isDebugEnabled()) {
       log.debug("Stream id from header: {}", streamId);
       // XXX create better to serialize ObjectMap to Status object
       ObjectMap<?, ?> objMap = (ObjectMap<?, ?>) call.getArguments()[0];
       // should keep this as an Object to stay compatible with FMS3 etc
       log.debug("Client id from status: {}", objMap.get("clientid"));
     }
     if (streamId != null) {
       // try lookup by stream id
       NetStreamPrivateData streamData = streamDataMap.get(streamId);
       // if null return the first one in the map
       if (streamData == null) {
         log.debug("Stream data was not found by id. Map contents: {}", streamDataMap);
         if (!streamDataMap.isEmpty()) {
           streamData = streamDataMap.values().iterator().next();
         }
       }
       if (streamData == null) {
         log.warn("Stream data was null for id: {}", streamId);
       }
       if (streamData != null && streamData.handler != null) {
         log.debug("Got stream data and handler");
         streamData.handler.onStreamEvent((Notify) command);
       }
     }
   }
   // if this client supports service methods, forward the call
   if (serviceProvider == null) {
     // client doesn't support calling methods on him
     call.setStatus(Call.STATUS_METHOD_NOT_FOUND);
     call.setException(new MethodNotFoundException(methodName));
     log.info(
         "No service provider / method not found; to handle calls like onBWCheck, add a service provider");
   } else {
     serviceInvoker.invoke(call, serviceProvider);
   }
   if (call instanceof IPendingServiceCall) {
     IPendingServiceCall psc = (IPendingServiceCall) call;
     Object result = psc.getResult();
     log.debug("Pending call result is: {}", result);
     if (result instanceof DeferredResult) {
       DeferredResult dr = (DeferredResult) result;
       dr.setTransactionId(command.getTransactionId());
       dr.setServiceCall(psc);
       dr.setChannel(channel);
       conn.registerDeferredResult(dr);
     } else if (!onStatus) {
       if ("onBWCheck".equals(methodName)) {
         onBWCheck(call.getArguments().length > 0 ? call.getArguments()[0] : null);
         Invoke reply = new Invoke();
         reply.setCall(call);
         reply.setTransactionId(command.getTransactionId());
         channel.write(reply);
       } else if ("onBWDone".equals(methodName)) {
         onBWDone(call.getArguments().length > 0 ? call.getArguments()[0] : null);
       } else {
         Invoke reply = new Invoke();
         reply.setCall(call);
         reply.setTransactionId(command.getTransactionId());
         log.debug("Sending empty call reply: {}", reply);
         channel.write(reply);
       }
     }
   }
 }