当前位置: 首页>>代码示例>>Java>>正文


Java Emitter类代码示例

本文整理汇总了Java中com.github.nkzawa.emitter.Emitter的典型用法代码示例。如果您正苦于以下问题:Java Emitter类的具体用法?Java Emitter怎么用?Java Emitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Emitter类属于com.github.nkzawa.emitter包,在下文中一共展示了Emitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupSocketIO

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private void setupSocketIO(Server item){
    try {
        io = IO.socket(item.getTargetUrl());

        io.on("log", new Emitter.Listener() {
            @Override
            public void call(Object... args) {
                JSONObject dataReceive = (JSONObject) args[0];

                handleMessage(dataReceive);
            }
        });
    }catch (Exception ex){
        Log.i("Exception", ex.getMessage());
    }
}
 
开发者ID:BlaShadow,项目名称:Remote-Logger-Android,代码行数:17,代码来源:ServerDetails.java

示例2: listenForEvent

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private <J> void listenForEvent(String eventName, String serviceName, final OnEventCallback<J> callback, final Class<J> jClass) {
    mSocket.on(serviceName + " " + eventName,
            new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    if (args.length == 1) {
                        JSONObject obj = (JSONObject) args[0];
                        if (callback instanceof OnCreatedCallback) {
                            ((OnCreatedCallback) callback).onCreated(Serialization.deserializeObject(obj, jClass, gson));
                        }

                        if (callback instanceof OnUpdatedCallback) {
                            ((OnUpdatedCallback) callback).onUpdated(Serialization.deserializeObject(obj, jClass, gson));
                        }

                        if (callback instanceof OnRemovedCallback) {
                            ((OnRemovedCallback) callback).onRemoved(Serialization.deserializeObject(obj, jClass, gson));
                        }

                        if (callback instanceof OnPatchedCallback) {
                            ((OnPatchedCallback) callback).onPatched(Serialization.deserializeObject(obj, jClass, gson));
                        }
                    }
                }
            });
}
 
开发者ID:feathersjs-ecosystem,项目名称:feathers-android,代码行数:27,代码来源:FeathersSocketClient.java

示例3: initCallListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initCallListener(final SocketEventListener listener){
    return new Emitter.Listener() {
        @Override
        public void call(Object... args) {

            SynergykitLog.print(getEvent() + ": " + STATE_CALLED); //print state

            //call listener
            if(listener!=null)
                listener.call(args);
            else
                SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);

        }
    };
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:17,代码来源:Socket.java

示例4: initUnsubscribedListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initUnsubscribedListener(final SocketEventListener listener){
    return new Emitter.Listener() {
        @Override
        public void call(Object... args) {

            SynergykitLog.print(getEvent() + ": " + STATE_UNSUBSCRIBED); //print state

            //unsubscribed listener
            if(listener!=null)
                listener.unsubscribed();
            else
                SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);


        }
    };
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:18,代码来源:Socket.java

示例5: off

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@SuppressWarnings("unused")
private void off(final JSONArray args, final CallbackContext callbackContext) throws JSONException {
  if (args.length() == 0) {
    this.socket.off();
    callbackContext.success();
    return;
  }

  String eventName = args.getString(0);
  if (args.length() == 1) {
    this.socket.off(eventName);
    callbackContext.success();
    return;
  }
  
  int hashCode = args.getInt(1);
  if (LISTENERS.containsKey(hashCode)) {
    Emitter.Listener listener = LISTENERS.remove(hashCode);
    this.socket.off(eventName, listener);
  }
}
 
开发者ID:wf9a5m75,项目名称:plugin-socket.io,代码行数:22,代码来源:SocketIO.java

示例6: emit

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
/**
 * Emits an event with an acknowledge.
 *
 * @param event an event name
 * @param args data to send.
 * @param ack the acknowledgement to be called
 * @return a reference to this object.
 */
public Emitter emit(final String event, final Object[] args, final Ack ack) {
    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            List<Object> _args = new ArrayList<Object>() {{
                add(event);
                if (args != null) {
                    addAll(Arrays.asList(args));
                }
            }};
            Packet<JSONArray> packet = new Packet<JSONArray>(Parser.EVENT, new JSONArray(_args));

            logger.fine(String.format("emitting packet with ack id %d", ids));
            Socket.this.acks.put(ids, ack);
            packet.id = ids++;

            Socket.this.packet(packet);
        }
    });
    return this;
}
 
开发者ID:wf9a5m75,项目名称:plugin-socket.io,代码行数:30,代码来源:Socket.java

示例7: rememberWebsocket

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void rememberWebsocket() throws InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            final Socket socket = new Socket(createOptions());

            socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Transport transport = (Transport) args[0];
                    socket.close();
                    if (WebSocket.NAME.equals(transport.name)) {
                        Socket.Options opts = new Socket.Options();
                        opts.port = PORT;
                        opts.rememberUpgrade = true;

                        Socket socket2 = new Socket(opts);
                        socket2.open();
                        values.offer(socket2.transport.name);
                        socket2.close();
                    }
                }
            });
            socket.open();
            values.offer(socket.transport.name);
        }
    });

    assertThat((String)values.take(), is(Polling.NAME));
    assertThat((String)values.take(), is(WebSocket.NAME));
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:35,代码来源:ServerConnectionTest.java

示例8: notRememberWebsocket

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void notRememberWebsocket() throws InterruptedException {
    final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();

    EventThread.exec(new Runnable() {
        @Override
        public void run() {
            final Socket socket = new Socket(createOptions());

            socket.on(Socket.EVENT_UPGRADE, new Emitter.Listener() {
                @Override
                public void call(Object... args) {
                    Transport transport = (Transport)args[0];
                    socket.close();
                    if (WebSocket.NAME.equals(transport.name)) {
                        Socket.Options opts = new Socket.Options();
                        opts.port = PORT;
                        opts.rememberUpgrade = false;

                        final Socket socket2 = new Socket(opts);
                        socket2.open();
                        values.offer(socket2.transport.name);
                        socket2.close();
                    }
                }
            });
            socket.open();
            values.offer(socket.transport.name);
        }
    });

    assertThat((String)values.take(), is(Polling.NAME));
    assertThat((String)values.take(), is(not(WebSocket.NAME)));
}
 
开发者ID:jianliaoim,项目名称:talk-android,代码行数:35,代码来源:ServerConnectionTest.java

示例9: initSubscribedListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
private Emitter.Listener initSubscribedListener(final SocketEventListener listener){
    return new Emitter.Listener() {
        @Override
        public void call(Object... args) {

            SynergykitLog.print(getEvent() + ": " + STATE_SUBSCRIBED); //print state

            //subscribed listener
            if(listener!=null)
                listener.subscribed();
            else
                SynergykitLog.print(getEvent() + ": " + Errors.MSG_NO_CALLBACK_LISTENER);
        }
    };
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:16,代码来源:Socket.java

示例10: on

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public static Handle on(final Emitter obj, final String ev, final Emitter.Listener fn) {
    obj.on(ev, fn);
    return new Handle() {
        @Override
        public void destroy() {
            obj.off(ev, fn);
        }
    };
}
 
开发者ID:wf9a5m75,项目名称:plugin-socket.io,代码行数:10,代码来源:On.java

示例11: bindListenerForEvent

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public void bindListenerForEvent(String event,Emitter.Listener listener) {
    if(null != listener && null != socket) {
        socket.on(event,listener);
    }
}
 
开发者ID:xiaominfc,项目名称:pushClientDemo,代码行数:6,代码来源:PushClientService.java

示例12: getConnectedListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getConnectedListener() {
    return connectedListener;
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:4,代码来源:Socket.java

示例13: getDisconnectedListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getDisconnectedListener() {
    return disconnectedListener;
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:4,代码来源:Socket.java

示例14: getReconnectedListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getReconnectedListener() {
    return reconnectedListener;
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:4,代码来源:Socket.java

示例15: getCallListener

import com.github.nkzawa.emitter.Emitter; //导入依赖的package包/类
public Emitter.Listener getCallListener() {
    return callListener;
}
 
开发者ID:SynergyKit,项目名称:synergykit-sdk-android,代码行数:4,代码来源:Socket.java


注:本文中的com.github.nkzawa.emitter.Emitter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。