本文整理汇总了Java中io.socket.client.Ack类的典型用法代码示例。如果您正苦于以下问题:Java Ack类的具体用法?Java Ack怎么用?Java Ack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ack类属于io.socket.client包,在下文中一共展示了Ack类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: emitFrom
import io.socket.client.Ack; //导入依赖的package包/类
/**
* Private method used by {@link SailsSocket#request}
*
* @param request {@link SailsSocketRequest}
*/
private void emitFrom(Socket socket, SailsSocketRequest request) {
// Name of the appropriate socket.io listener on the server
// ( === the request method or "verb", e.g. 'get', 'post', 'put', etc. )
String sailsEndpoint = request.getMethod();
// Since Listener is embedded in request, retrieve it.
final SailsSocketResponse.Listener listener = request.getListener();
socket.emit(sailsEndpoint, request.toJSONObject(), new Ack() {
@Override
public void call(Object... args) {
// Send back jsonWebSocketResponse
if (listener != null) {
listener.onResponse(new JWR((JSONObject) args[0]));
}
}
});
}
示例2: channelGet
import io.socket.client.Ack; //导入依赖的package包/类
public void channelGet(final CallbackEvent callback) {
mChannelSocket.emit("channel.get", new Ack() {
@Override
public void call(Object... args) {
JSONObject response = (JSONObject) args[0];
Log.d(TAG, response.toString() );
if (response.has("status")) {
try {
if ("ok".equalsIgnoreCase(response.getString("status"))) {
callback.call(response);
} else {
callback.call();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
示例3: createAckFunction
import io.socket.client.Ack; //导入依赖的package包/类
private Ack createAckFunction(final SettableFuture<GenericOutcome> future) {
return new Ack() {
@Override
public void call(Object... objects) {
if (objects.length == 0 || objects[0] == null) {
future.set(new GenericOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
boolean value = (boolean) objects[0];
if (value) {
future.set(new GenericOutcome());
} else {
future.set(new GenericOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
}
};
}
示例4: send
import io.socket.client.Ack; //导入依赖的package包/类
public void send(String msg, String guid) throws URISyntaxException, JSONException {
JSONObject json = new JSONObject();
json.put("text", msg);
json.put("guid", guid);
// Immediately insert message into list so that UI feels more responsive
// Unsent messages are given a different distinction
final Message m = new Message(msg, username, 1, chat_id, 1, 0);
messageList.add(m);
holderList.put(m, messageList.size() - 1);
runOnUiThread(new Runnable() {
@Override
public void run() {
mAdapter.notifyItemInserted(messageList.size() - 1);
recyclerView.scrollToPosition(mAdapter.getItemCount() - 1);
mAdapter.notifyDataSetChanged();
}
});
socket.emit("sendMessage", json, new Ack() {
@Override
public void call(Object... args) {
Log.w("sending message", args[0].toString());
}
});
}
示例5: channelLeave
import io.socket.client.Ack; //导入依赖的package包/类
public void channelLeave(final CallbackEvent callback) {
mChannelSocket.emit("channel.leave", new Ack() {
@Override
public void call(Object... args) {
JSONObject response = (JSONObject) args[0];
if (response.has("status")) {
try {
if ("ok".equalsIgnoreCase(response.getString("status"))) {
callback.call();
} else {
if (response.has("message") && "ERR-NOTEXIST".equals(response.getString("message") ) ) {
callback.call();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
});
}
示例6: eventGetPlayerVotes
import io.socket.client.Ack; //导入依赖的package包/类
@Override
public void eventGetPlayerVotes(Object... req) {
log("Got eventGetPlayerVotes");
// Interpret message.
// TODO: Should be an error object.
if (req[0] == null) return;
log("Compiling votes...");
JSONObject res = getPluginConfig().getPlayerVotes((JSONObject)req[0]);
log("Sending votes...");
SocketIOClient.emit("PlayerVotes", res, new Ack() {
@Override
public void call(Object... cb) {
}
});
}
示例7: onPlayerChat
import io.socket.client.Ack; //导入依赖的package包/类
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerChat(AsyncPlayerChatEvent event) {
if (SocketIOClient.disconnected()) return;
final String socketEvent = "eventPlayerChat";
JSONObject obj = new JSONObject();
try {
obj.put("name", event.getPlayer().getName());
obj.put("id", event.getPlayer().getUniqueId());
obj.put("message", event.getMessage());
obj.put("key", plugin.getPluginConfig().getForumAPIKey());
} catch (JSONException e) {
plugin.log("Error constructing JSON Object for " + socketEvent);
e.printStackTrace();
return;
}
SocketIOClient.emit(socketEvent, obj, new Ack() {
@Override
public void call(Object... args) {
}
});
}
示例8: _createAckFunction
import io.socket.client.Ack; //导入依赖的package包/类
private Ack _createAckFunction(final SettableFuture<DescribePlayerSessionsOutcome> future) {
return new Ack() {
@Override
public void call(Object... objects) {
if (objects.length == 0 || objects[0] == null) {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
boolean value = (boolean) objects[0];
if (value) {
try {
Sdk.DescribePlayerSessionsResponse.Builder builder = Sdk.DescribePlayerSessionsResponse.newBuilder();
JsonFormat.parser().merge((String)objects[1], builder);
Sdk.DescribePlayerSessionsResponse response = builder.build();
DescribePlayerSessionsResult result = transformResponse(response);
future.set(new DescribePlayerSessionsOutcome(result));
} catch (InvalidProtocolBufferException e) {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED, e)));
}
} else {
future.set(new DescribePlayerSessionsOutcome(new GameLiftError(GameLiftErrorType.SERVICE_CALL_FAILED)));
}
}
};
}
示例9: describePlayerSessions
import io.socket.client.Ack; //导入依赖的package包/类
public DescribePlayerSessionsOutcome describePlayerSessions(DescribePlayerSessionsRequest request) {
Sdk.DescribePlayerSessionsRequest.Builder builder = Sdk.DescribePlayerSessionsRequest.newBuilder();
if (request.getGameSessionId() != null) {
builder.setGameSessionId(request.getGameSessionId());
}
if (request.getNextToken() != null) {
builder.setNextToken(request.getNextToken());
}
if (request.getPlayerId() != null) {
builder.setPlayerId(request.getPlayerId());
}
if (request.getPlayerSessionId() != null) {
builder.setPlayerSessionId(request.getPlayerSessionId());
}
if (request.getPlayerSessionStatusFilter() != null) {
builder.setPlayerSessionStatusFilter(request.getPlayerSessionStatusFilter());
}
builder.setLimit(request.getLimit());
Sdk.DescribePlayerSessionsRequest message = builder.build();
SettableFuture<DescribePlayerSessionsOutcome> future = SettableFuture.create();
Ack ack = _createAckFunction(future);
return emitEvent(message, ack, future, DESCRIBE_PLAYER_SESSION_ERROR);
}
示例10: emitEvent
import io.socket.client.Ack; //导入依赖的package包/类
public synchronized <T extends GenericOutcome> T emitEvent(Message message,
Ack ack,
SettableFuture<T> future,
T genericError) {
socket.emit(message.getDescriptorForType().getFullName(), ack, message.toByteArray());
try {
return future.get(30, TimeUnit.SECONDS);
} catch (Throwable e) {
genericError.setError(new GameLiftError(genericError.getError().getErrorType(), e));
return genericError;
}
}
示例11: onPlayerQuit
import io.socket.client.Ack; //导入依赖的package包/类
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
String socketEvent = SocketIOClient.Events.onPlayerQuit;
SocketIOClient.emit(socketEvent, getPlayerQuitData(event.getPlayer()), new Ack() {
@Override
public void call(Object... args) {
}
});
}
示例12: sendEvent
import io.socket.client.Ack; //导入依赖的package包/类
private static void sendEvent(final String socketEvent, final JSONObject data, final Doable res) {
// Send socket event to the forum.
SocketIOClient.emit(socketEvent, data, new Ack() {
@Override
public void call(Object... args) {
// We receive a callback form the forum with information about the primary linked user.
// First arg is an error object.
if (args[0] == null) {
// Construct response object.
if (args[1] != null) {
// Call the callback if it exists.
if (res != null) res.doit(args[1]);
} else {
Logger.log(socketEvent + " callback no response object found.");
}
} else {
Logger.log(socketEvent + " callback error.");
try {
Logger.log(((JSONObject) args[0]).getString("message"));
} catch (JSONException e) {
//TODO
e.printStackTrace();
}
}
}
});
}
示例13: gameListQuery
import io.socket.client.Ack; //导入依赖的package包/类
private void gameListQuery(JSONObject args, Consumer<JSONObject> callback) {
connection.emit(GAMELIST, args, (Ack) res -> argsToJSON(callback, res));
}
示例14: onStartGameSession
import io.socket.client.Ack; //导入依赖的package包/类
void onStartGameSession(final String rawGameSession, Ack ack) {
debug("ServerState got the startGameSession signal. rawGameSession : " + rawGameSession);
if (!processReady) {
debug("Got a game session on inactive process. Sending false ack.");
ack.call(false);
return;
}
debug("Sending true ack.");
ack.call(true);
runAsync(new Runnable() {
@Override
public void run() {
try {
//Parse message
Sdk.GameSession.Builder builder = Sdk.GameSession.newBuilder();
JsonFormat.parser().merge(rawGameSession, builder);
Sdk.GameSession parsed = builder.build();
//Convert to model
GameSession session = new GameSession();
session.setName(parsed.getName());
session.setFleetId(parsed.getFleetId());
session.setGameSessionId(parsed.getGameSessionId());
session.setMaximumPlayerSessionCount(parsed.getGamePropertiesCount());
session.setGameProperties(new HashMap<String, String>());
for (int i = 0; i < parsed.getGamePropertiesCount(); i++) {
Sdk.GameProperty property = parsed.getGameProperties(i);
session.addGameProperty(property.getKey(), property.getValue());
}
//Save and invoke onGameSessionStarted
gameSessionId = session.getGameSessionId();
processParameters.gameSessionStarted(session);
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
});
}
示例15: fetchConversations
import io.socket.client.Ack; //导入依赖的package包/类
public void fetchConversations() {
socket.emit("getAllChat", new Ack() {
@Override
public void call(Object... args) {
ObjectMapper mapper = new ObjectMapper();
try {
// Establish root node
JsonNode rootNode = mapper.readTree(args[0].toString());
Iterator<JsonNode> iterator = rootNode.elements();
while (iterator.hasNext()) {
int numPeople = 0;
HashMap<String, String> peopleMap = new HashMap<String, String>();
JsonNode chatThread = iterator.next();
long date = chatThread.get("lastUpdate").asLong();
Iterator<JsonNode> peopleIterator = chatThread.get("people").elements();
while(peopleIterator.hasNext()) {
numPeople++;
JsonNode person = peopleIterator.next();
String number = person.get("value").toString().replace("\"", "");
if(!number.contains("@")) {
number = String.format("(%s) %s-%s", number.substring(2, 5), number.substring(5, 8),
number.substring(8, 12));
}
String name = getContactName(getApplicationContext(), number);
if (name != null) {
peopleMap.put(number, name);
} else {
peopleMap.put(number, number);
}
}
ColorGenerator colorGenerator = ColorGenerator.MATERIAL; // or use DEFAULT
Chat chat = new Chat(chatThread.get("chat_id").asInt(), peopleMap, date, chatThread.get("guid").asText());
chat.setNumPeople(numPeople);
chat.setColor(colorGenerator.getColor(chat.getChatID()));
cList.add(chat);
Log.w("people", peopleMap.toString());
Log.w("getPeople", chat.getNumPeople() + "");
runOnUiThread(new Runnable() {
@Override
public void run() {
chatAdapter.notifyDataSetChanged();
}
});
}
} catch (IOException e) {
e.printStackTrace();
}
}
});
chatAdapter.notifyDataSetChanged();
}