@SuppressWarnings("unchecked")
    @Override
    public void update(Observable client, Object msg) {
        // handle subscription updates and othre messages that aren't associated
        // w/ a specific command
        if (msg instanceof Map<?, ?>) {
            Map<String, Object> jsonFields = (Map<String, Object>) msg;
            // handle msg types for DDP server->client msgs:
            // https://github.com/meteor/meteor/blob/master/packages/livedata/DDP.md
            String msgtype = (String) jsonFields
                    .get(DDPClient.DdpMessageField.MSG);
            String collName = (String) jsonFields.get(DdpMessageField.COLLECTION);
            String docId = (String) jsonFields.get(DdpMessageField.ID);

            // ignore {"server_id":"GqrKrbcSeDfTYDkzQ"} web socket msgs
            if (msgtype != null) {
                switch (msgtype) {
                    case DdpMessageType.ERROR:
                        broadcastDDPError((String) jsonFields.get(DdpMessageField.ERRORMSG));
                        break;
                    case DdpMessageType.CONNECTED:
                        mDDPState = DDPSTATE.Connected;
                        broadcastConnectionState(mDDPState);
                        break;
                    case DdpMessageType.ADDED:
                        addDoc(jsonFields, collName, docId);
                        // broadcast that subscription has been updated
                        broadcastSubscriptionChanged(collName, DdpMessageType.ADDED, docId);
                        break;
                    case DdpMessageType.REMOVED:
                        if (removeDoc(collName, docId)) {
                            // broadcast that subscription has been updated
                            broadcastSubscriptionChanged(collName,
                                    DdpMessageType.REMOVED, docId);
                        }
                        break;
                    case DdpMessageType.CHANGED:
                        // handle document updates
                        if (updateDoc(jsonFields, collName, docId)) {
                            // broadcast that subscription has been updated
                            broadcastSubscriptionChanged(collName,
                                    DdpMessageType.CHANGED, docId);
                        }
                        break;
                    case DdpMessageType.CLOSED:
                        mDDPState = DDPSTATE.Closed;
                        broadcastConnectionState(DDPSTATE.Closed);
                        break;
                }
            }
        }
    }
@ SuppressWarnings ( "unchecked" ) @ Override public void update ( Observable client , Object msg ) { if ( msg instanceof Map < ? , ? > ) { Map < String , Object > jsonFields = ( Map < String , Object > ) msg ; String msgtype = ( String ) jsonFields . get ( DDPClient . DdpMessageField . MSG ) ; String collName = ( String ) jsonFields . get ( DdpMessageField . COLLECTION ) ; String docId = ( String ) jsonFields . get ( DdpMessageField . ID ) ; if ( msgtype != null ) { switch ( msgtype ) { case DdpMessageType . ERROR : broadcastDDPError ( ( String ) jsonFields . get ( DdpMessageField . ERRORMSG ) ) ; break ; case DdpMessageType . CONNECTED : mDDPState = DDPSTATE . Connected ; broadcastConnectionState ( mDDPState ) ; break ; case DdpMessageType . ADDED : addDoc ( jsonFields , collName , docId ) ; broadcastSubscriptionChanged ( collName , DdpMessageType . ADDED , docId ) ; break ; case DdpMessageType . REMOVED : if ( removeDoc ( collName , docId ) ) { broadcastSubscriptionChanged ( collName , DdpMessageType . REMOVED , docId ) ; } break ; case DdpMessageType . CHANGED : if ( updateDoc ( jsonFields , collName , docId ) ) { broadcastSubscriptionChanged ( collName , DdpMessageType . CHANGED , docId ) ; } break ; case DdpMessageType . CLOSED : mDDPState = DDPSTATE . Closed ; broadcastConnectionState ( DDPSTATE . Closed ) ; break ; } } } }
handles callbacks from DDP client websocket callbacks