本文整理汇总了Java中io.socket.emitter.Emitter.Listener方法的典型用法代码示例。如果您正苦于以下问题:Java Emitter.Listener方法的具体用法?Java Emitter.Listener怎么用?Java Emitter.Listener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.socket.emitter.Emitter
的用法示例。
在下文中一共展示了Emitter.Listener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void connect(HashMap<String, Emitter.Listener> events) {
mEvents = events;
String url = mServerUrl + "/channel";
IO.Options opts = new IO.Options();
opts.forceNew = true;
opts.query = "A=" + mAppId + "&C=" + mChannelId + "&S=" + mServerName + "&D=" + mDeviceId + "&U=" + xpushSession.getId();
mChannelSocket = null;
try {
mChannelSocket = IO.socket(url, opts);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
if (events != null) {
for (String eventName : events.keySet()) {
this.on(eventName, events.get(eventName));
}
}
mChannelSocket.connect();
}
示例2: doClose
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
protected void doClose() {
final Polling self = this;
Emitter.Listener close = new Emitter.Listener() {
@Override
public void call(Object... args) {
logger.fine("writing close packet");
try {
self.write(new Packet[]{new Packet(Packet.CLOSE)});
} catch (UTF8Exception err) {
throw new RuntimeException(err);
}
}
};
if (this.readyState == ReadyState.OPEN) {
logger.fine("transport open - closing");
close.call();
} else {
// in case we're trying to close while
// handshaking is in progress (engine.io-client GH-164)
logger.fine("transport not open - deferring close");
this.once(EVENT_OPEN, close);
}
}
示例3: on
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void on(String event, Emitter.Listener fn) {
mChannelSocket.on(event, fn);
}
示例4: SailsSocket
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public SailsSocket(String url, IO.Options options) {
// Set logger level to FINE
logger.setLevel(Level.FINE);
if (options == null) {
options = new IO.Options();
}
/**
* Solves problem: "Sails v0.11.x is not compatible with the socket.io/sails.io.js
* client SDK version you are using (0.9.0). Please see the v0.11 migration guide
* on http://sailsjs.org for more information".
*
* https://github.com/balderdashy/sails/issues/2640
*/
String sdkVersionQuery = SDK_VERSION_KEY + "=" + SDK_VERSION_VALUE;
if (options.query == null) {
options.query = sdkVersionQuery;
} else {
options.query = options.query + "&" + sdkVersionQuery;
}
try {
socket = IO.socket(url, options);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
requestQueue = new HashSet<SailsSocketRequest>();
Emitter.Listener clearRequestQueue = new Emitter.Listener() {
@Override
public void call(Object... args) {
drainRequestQueue();
}
};
socket.on(Socket.EVENT_CONNECT, clearRequestQueue);
socket.on(Socket.EVENT_RECONNECT, clearRequestQueue);
}
示例5: connectChannel
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
private void connectChannel() {
HashMap<String, Emitter.Listener> events = new HashMap<>();
events.put(Socket.EVENT_CONNECT_ERROR, onConnectError);
events.put(Socket.EVENT_CONNECT_TIMEOUT, onConnectError);
events.put(Socket.EVENT_CONNECT, onConnectSuccess);
events.put("message", onMessage);
mChannelCore.connect(events);
}
示例6: stop
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
* Stop broadcast topology to server-side.
*/
public Emitter.Listener stop() {
return new Emitter.Listener() {
@Override public void call(Object... args) {
refreshTask.cancel(true);
AgentClusterDemo.stop();
}
};
}
示例7: start
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
* Start broadcast topology to server-side.
*/
public Emitter.Listener start() {
return new Emitter.Listener() {
@Override public void call(Object... args) {
safeStopRefresh();
final long timeout = args.length > 1 && args[1] instanceof Long ? (long)args[1] : DFLT_TIMEOUT;
refreshTask = pool.scheduleWithFixedDelay(broadcastTask, 0L, timeout, TimeUnit.MILLISECONDS);
}
};
}
示例8: stop
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
/**
* Stop broadcast topology to server-side.
*/
public Emitter.Listener stop() {
return new Emitter.Listener() {
@Override public void call(Object... args) {
refreshTask.cancel(true);
watch();
}
};
}
示例9: on
import io.socket.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);
}
};
}
示例10: fireReconnectEventsOnSocket
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
@Test(timeout = TIMEOUT)
public void fireReconnectEventsOnSocket() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
Manager.Options opts = new Manager.Options();
opts.reconnection = true;
opts.timeout = 0;
opts.reconnectionAttempts = 2;
opts.reconnectionDelay = 10;
final Manager manager = new Manager(new URI(uri()), opts);
socket = manager.socket("/timeout_socket");
final int[] reconnects = new int[] {0};
Emitter.Listener reconnectCb = new Emitter.Listener() {
@Override
public void call(Object... args) {
reconnects[0]++;
values.offer(args[0]);
}
};
socket.on(Socket.EVENT_RECONNECT_ATTEMPT, reconnectCb);
socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() {
@Override
public void call(Object... objects) {
socket.close();
manager.close();
values.offer(reconnects[0]);
}
});
socket.open();
assertThat((Integer)values.take(), is(reconnects[0]));
assertThat((Integer)values.take(), is(2));
}
示例11: fireReconnectingWithAttemptsNumberWhenReconnectingTwice
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
@Test(timeout = TIMEOUT)
public void fireReconnectingWithAttemptsNumberWhenReconnectingTwice() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
Manager.Options opts = new Manager.Options();
opts.reconnection = true;
opts.timeout = 0;
opts.reconnectionAttempts = 2;
opts.reconnectionDelay = 10;
final Manager manager = new Manager(new URI(uri()), opts);
socket = manager.socket("/timeout_socket");
final int[] reconnects = new int[] {0};
Emitter.Listener reconnectCb = new Emitter.Listener() {
@Override
public void call(Object... args) {
reconnects[0]++;
values.offer(args[0]);
}
};
socket.on(Socket.EVENT_RECONNECTING, reconnectCb);
socket.on(Socket.EVENT_RECONNECT_FAILED, new Emitter.Listener() {
@Override
public void call(Object... objects) {
socket.close();
manager.close();
values.offer(reconnects[0]);
}
});
socket.open();
assertThat((Integer)values.take(), is(reconnects[0]));
assertThat((Integer)values.take(), is(2));
}
示例12: on
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void on(String event, Emitter.Listener eventListener) {
if( !mEvents.containsKey( event) ){
mGlobalSocket.on(event, eventListener);
}
}
示例13: off
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void off(String event, Emitter.Listener fn) {
mChannelSocket.off(event, fn);
}
示例14: addListener
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void addListener(String event, Emitter.Listener listener) {
this.socket.off(event, listener);
this.socket.on(event, listener);
}
示例15: addOnHandler
import io.socket.emitter.Emitter; //导入方法依赖的package包/类
public void addOnHandler(String event,Emitter.Listener listener){
mSocket.on(event, listener);
}