本文整理汇总了Java中io.socket.emitter.Emitter类的典型用法代码示例。如果您正苦于以下问题:Java Emitter类的具体用法?Java Emitter怎么用?Java Emitter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Emitter类属于io.socket.emitter包,在下文中一共展示了Emitter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToServer
import io.socket.emitter.Emitter; //导入依赖的package包/类
private void connectToServer(final String nickname) {
try {
socket = IO.socket("http://localhost:5000");
socket.connect();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
System.out.println("Connected: "+socket.id());
socket.emit("login", nickname);
}
});
socket.connect();
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: isAlive
import io.socket.emitter.Emitter; //导入依赖的package包/类
public boolean isAlive() {
socket.emit("isAlive", "hello");
socket.on("isAlive", new Emitter.Listener() {
@Override
public void call(Object... args) {
isAlive = args[0].toString();
callback = true;
}
});
while (!callback) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Log.i("SocketIO-isAlive", isAlive);
callback = false;
return (isAlive.equals("olleh"));
}
示例3: setupNotifications
import io.socket.emitter.Emitter; //导入依赖的package包/类
private void setupNotifications() {
mSocket.on("join", new Emitter.Listener() {
@Override
public void call(Object... args) {
if (mAdapter.getWaiting().size() == 0 && mAdapter.getHelpedByMe().size() == 0)
return;
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplication())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Stay-A-While")
.setContentText("Someone just joined the queue " + mQueueName)
.setSound(alarmSound);
Intent notificationIntent = getIntent();
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
PendingIntent contentIntent = PendingIntent.getActivity(getApplication(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIntent);
builder.setAutoCancel(true);
builder.setLights(Color.MAGENTA, 500, 500);
builder.setVibrate(new long[]{200, 200, 200});
builder.setStyle(new NotificationCompat.InboxStyle());
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(mQueueName, 1, builder.build());
}
});
}
示例4: prepareSocket
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Override
protected void prepareSocket() {
MainApplication.socket.on("wolfResult", new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
String finalUserId = (String) args[0];
JSONArray array = (JSONArray) args[1];
for (int i = 0; i < array.length(); i++) {
JSONObject obj = (JSONObject) array.get(i);
String fromUserId = (String) obj.get("fromUserId");
String toUserId = (String) obj.get("toUserId");
MainApplication.roomInfo.getVoteResults().add(new VoteResult(MainApplication.roomInfo.findUserInRoom(fromUserId),MainApplication.roomInfo.findUserInRoom(toUserId)));
}
Intent intent =new Intent(WolfActivity.this, VoteResultActivity.class).putExtra("type",RoomInfo.VOTE_KILL);
if(finalUserId!=null)
intent.putExtra("finalUserName",MainApplication.roomInfo.findUserInRoom(finalUserId).getNickname());
startActivity(intent);
finish();
}catch (Exception e){
e.printStackTrace();
}
}
});
}
示例5: connect
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void connect() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
// Get global sails socket
TestSailsSocketSingleton.getInstance().setUrl(url);
SailsSocket sailsSocket = TestSailsSocketSingleton.getInstance().socket();
sailsSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
values.offer("done");
}
});
sailsSocket.connect();
values.take();
sailsSocket.disconnect();
}
示例6: isConnectedShouldReturnTrue
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void isConnectedShouldReturnTrue() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final SailsSocket sailsSocket = new SailsSocket(url);
sailsSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
assertThat(sailsSocket.isConnected(), is(true));
values.offer("done");
}
});
sailsSocket.connect();
values.take();
sailsSocket.disconnect();
}
示例7: shouldGetErrorWhenSettingSocketUrl
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void shouldGetErrorWhenSettingSocketUrl() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
TestSailsSocketSingleton.getInstance().setUrl(url);
SailsSocket sailsSocket = TestSailsSocketSingleton.getInstance().socket();
sailsSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
TestSailsSocketSingleton.getInstance().setUrl("http://127.0.0.1:" + PORT);
} catch (Exception e) {
assertThat(e.getMessage(), is("Can not change url while socket is connected"));
values.offer("done");
}
}
});
sailsSocket.connect();
values.take();
sailsSocket.disconnect();
}
示例8: shouldGetErrorWhenSettingSocketOptions
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void shouldGetErrorWhenSettingSocketOptions() throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
TestSailsSocketSingleton.getInstance().setUrl(url);
SailsSocket sailsSocket = TestSailsSocketSingleton.getInstance().socket();
sailsSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
try {
TestSailsSocketSingleton.getInstance().setOptions(new IO.Options());
} catch (Exception e) {
assertThat(e.getMessage(), is("Can not change options while socket is connected"));
values.offer("done");
}
}
});
sailsSocket.connect();
values.take();
sailsSocket.disconnect();
}
示例9: socketConnection
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test
public void socketConnection () throws Exception {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
testSailsSocketSingleton.socket().on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
assertThat(testSailsSocketSingleton.socket().isConnected(), is(true));
anotherSailsSocketSingleton.setUrl("http://localhost");
assertThat(anotherSailsSocketSingleton.socket().isConnected(), is(false));
values.offer("done");
}
});
testSailsSocketSingleton.socket().connect();
values.take();
testSailsSocketSingleton.socket().disconnect();
}
示例10: 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();
}
示例11: doesNotFireConnectErrorIfWeForceDisconnectInOpeningState
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void doesNotFireConnectErrorIfWeForceDisconnectInOpeningState() throws URISyntaxException, InterruptedException {
final BlockingQueue<Optional> values = new LinkedBlockingQueue<Optional>();
IO.Options opts = new IO.Options();
opts.timeout = 100;
socket = client(opts);
socket.on(Socket.EVENT_CONNECT_ERROR, new Emitter.Listener() {
@Override
public void call(Object... args) {
values.offer(Optional.of(new Error("Unexpected")));
}
});
socket.connect();
socket.disconnect();
new Timer().schedule(new TimerTask() {
@Override
public void run() {
values.offer(Optional.empty());
}
}, 300);
@SuppressWarnings("unchecked")
Optional<Error> err = values.take();
if (err.isPresent()) throw err.get();
}
示例12: connectToLocalhost
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void connectToLocalhost() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... objects) {
socket.emit("echo");
socket.on("echoBack", new Emitter.Listener() {
@Override
public void call(Object... args) {
values.offer("done");
}
});
}
});
socket.connect();
values.take();
socket.close();
}
示例13: receiveDateWithAck
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void receiveDateWithAck() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... objects) {
try {
socket.emit("getAckDate", new JSONObject("{test: true}"), new Ack() {
@Override
public void call(Object... args) {
values.offer(args[0]);
}
});
} catch (JSONException e) {
throw new AssertionError(e);
}
}
});
socket.connect();
assertThat(values.take(), instanceOf(String.class));
socket.close();
}
示例14: receiveBinaryDataWithAck
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void receiveBinaryDataWithAck() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
final byte[] buf = "huehue".getBytes(Charset.forName("UTF-8"));
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... objects) {
socket.emit("getAckBinary", "", new Ack() {
@Override
public void call(Object... args) {
values.offer(args[0]);
}
});
}
});
socket.connect();
Assert.assertArrayEquals(buf, (byte[])values.take());
socket.close();
}
示例15: workWithFalse
import io.socket.emitter.Emitter; //导入依赖的package包/类
@Test(timeout = TIMEOUT)
public void workWithFalse() throws URISyntaxException, InterruptedException {
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
socket = client();
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... objects) {
socket.emit("echo", false);
socket.on("echoBack", new Emitter.Listener() {
@Override
public void call(Object... args) {
values.offer(args[0]);
}
});
}
});
socket.connect();
assertThat((Boolean)values.take(), is(false));
socket.close();
}