本文整理汇总了Java中play.mvc.WebSocket类的典型用法代码示例。如果您正苦于以下问题:Java WebSocket类的具体用法?Java WebSocket怎么用?Java WebSocket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WebSocket类属于play.mvc包,在下文中一共展示了WebSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendHistoryMessage
import play.mvc.WebSocket; //导入依赖的package包/类
private void sendHistoryMessage(WebSocket.Out<JsonNode> channel, History history) {
if (m_members.values().size() > SIZE_THRESHOLD) {
return;
}
ObjectNode event = Json.newObject();
event.put("kind", "history");
event.put("user", history.talk.username);
event.put("message", history.talk.text);
event.put("userId", history.talk.userId);
event.put("toUser", history.talk.toUserName);
event.put("toUserId", history.talk.toUserId);
event.put("isOnline", history.talk.isOnline);
event.put("isOwners", history.talk.isOwners);
event.put("peopleNum", m_members.keySet().size());
event.put("time", sdf.format(history.date));
channel.write(event);
}
示例2: videoSocket
import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> videoSocket(long id) {
String[] tokens = request().queryString().get("authToken");
if (tokens == null || tokens.length != 1 || tokens[0] == null)
return WebSocket.reject(unauthorized());
Drone drone = Drone.FIND.byId(id);
if (drone == null)
return WebSocket.reject(notFound(Json.toJson("no drone found with this id")));
User u = models.User.findByAuthToken(tokens[0]);
if (u != null) {
return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
} else {
return WebSocket.reject(unauthorized());
}
}
示例3: videoSocket
import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> videoSocket(long id) {
/*String[] tokens = request().queryString().get("authToken");
if (tokens == null || tokens.length != 1 || tokens[0] == null)
return WebSocket.reject(unauthorized());
User u = models.User.findByAuthToken(tokens[0]);
if (u != null) {
return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
} else {
return WebSocket.reject(unauthorized());
}*/
Drone drone = Drone.FIND.byId(id);
DroneCommander d = Fleet.getFleet().getCommanderForDrone(drone);
d.initVideo();
return WebSocket.withActor(out -> VideoWebSocket.props(out, id));
}
示例4: Server
import play.mvc.WebSocket; //导入依赖的package包/类
private Server(ActorRef messageRoom) {
// Create a Fake socket out for the robot that log events to the console.
WebSocket.Out<JsonNode> serverChannel = new WebSocket.Out<JsonNode>() {
public void write(JsonNode frame) {
Logger.info(Json.stringify(frame));
}
public void close() {
}
};
// Join the room
messageRoom.tell(new MessageRoom.Join("Server", serverChannel), null);
}
示例5: connect
import play.mvc.WebSocket; //导入依赖的package包/类
/**
* Action non standard dédiée aux WebSockets
*/
public static WebSocket<JsonNode> connect() {
// On peut récupérer des objets de session ici si besoin!
return new WebSocket<JsonNode>() {
// Appelé quand le "Handshake" est réalisé lors de la première requête HTTP.
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
// Joindre la pièce dédiée aux messages.
try {
MessageRoom.join(UUID.randomUUID().toString(), in, out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}
示例6: connect
import play.mvc.WebSocket; //导入依赖的package包/类
/**
* Action non standard dédiée aux WebSockets
*/
public static WebSocket<JsonNode> connect() {
// On peut récupérer des objets de session ici si besoin!
return new WebSocket<JsonNode>() {
// Appelé quand le "Handshake" est réalisé lors de la première requête HTTP.
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
// Joindre la pièce dédiée aux messages.
try {
MessageRoom.join(UUID.randomUUID().toString(), in, out);
} catch (Exception ex) {
Logger.error("Error in WebSocket onReady", ex);
}
}
};
}
示例7: invokeActor
import play.mvc.WebSocket; //导入依赖的package包/类
/**
* Invokes a new ActorRef instance of type WebSocketActor for an account ID.
*
* @param account Account
* @param in WebSocket input stream
* @param out WebSocket output stream
*/
public void invokeActor(final Account account, WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out) {
if (this.getActorForAccount(account) != null) {
return;
}
this.accountActor.put(account.id, Akka.system().actorOf(Props.create(WebSocketActor.class, account, in, out)));
}
示例8: sendCompleteImage
import play.mvc.WebSocket; //导入依赖的package包/类
private void sendCompleteImage(WebSocket.Out<JsonNode> viewer) {
for (int x = 0; x < imageStrings.length; x++) {
for (int y = 0; y < imageStrings[x].length; y++) {
if (imageStrings[x][y] != null) {
ObjectNode event = Json.newObject();
event.put("kind", "sendImage");
event.put("x", x);
event.put("y", y);
event.put("data", imageStrings[x][y]);
viewer.write(event);
}
}
}
}
示例9: presenter
import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<JsonNode> presenter(final String presenterName) {
Logger.info("Application.presenter()");
return new WebSocket<JsonNode>() {
// Called when the Websocket Handshake is done.
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){
// Join the chat room.
try {
Session.createSession(presenterName, in, out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}
示例10: viewer
import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<JsonNode> viewer(final String presenterName, final String username) {
Logger.info("Application.viewer()");
return new WebSocket<JsonNode>() {
// Called when the Websocket Handshake is done.
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){
// Join the chat room.
try {
Session.joinSession(presenterName, username, in, out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}
示例11: register
import play.mvc.WebSocket; //导入依赖的package包/类
protected void register(NationStatesWebSocket socket, WebSocket.In<JsonNode> in) {
Set<NationStatesWebSocket> set = pages.get(socket.getPageType());
synchronized(set) {
set.add(socket);
in.onClose(new UnregisterCallback(socket));
}
count++;
if (count % 25 == 0) {
int total = 0;
for (PageType page : PageType.values()) {
Set<NationStatesWebSocket> sockets = pages.get(page);
synchronized(sockets) {
total += sockets.size();
}
}
Logger.info("Currently " + total + " registered websockets");
}
}
示例12: wsCall
import play.mvc.WebSocket; //导入依赖的package包/类
public static WebSocket<String> wsCall() {
return new WebSocket<String>() {
@SuppressWarnings("unchecked")
public void onReady(final WebSocket.In<String> in,
final WebSocket.Out<String> out) {
if (Cache.get("channels") == null) {
List<Out> outs = new ArrayList<Out>();
outs.add(out);
Cache.set("channels", outs);
} else ((List<Out>) Cache.get("channels")).add(out);
System.out.println("<" + Cache.get("channels"));
in.onClose(new F.Callback0() {
@Override
public void invoke() throws Throwable {
((List<Out>) Cache.get("channels")).remove(out);
out.close();
}
});
}
};
}
示例13: initializeGame
import play.mvc.WebSocket; //导入依赖的package包/类
private static void initializeGame(ActionRequest actionRequest) {
final Game game = findGame((Long) actionRequest.data[0]);
// change game state
game.superState = Game.STATE_READY;
game.subState = 0;
// set active counter to first position in the list of counters
game.activeCounter = 0;
// construct the action response
ActionResponse response = new ActionResponse();
// define socket request initializing action
response.initializer = Action.TYPE_INITIALIZE_GAME;
// assemble socket response data
response = assembleInitializeGameResponseData(game, response);
@SuppressWarnings("unchecked")
WebSocket.Out<JsonNode> out = (WebSocket.Out<JsonNode>) actionRequest.data[1];
// finally write action response on the socket's out channel
writeOut(response, out);
// persist the game state
game.save();
}
示例14: initializeSinglePlayerGame
import play.mvc.WebSocket; //导入依赖的package包/类
/**
* Controller Action for initiating the web socket.
*/
public static WebSocket<JsonNode> initializeSinglePlayerGame(final Long game) {
final Session session = session();
return new WebSocket<JsonNode>() {
public void onReady(WebSocket.In<JsonNode> in,
WebSocket.Out<JsonNode> out) {
try {
SinglePlayerGameHall.join(game,
UserService.getAuthUserName(session), in, out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}
示例15: administratePlayground
import play.mvc.WebSocket; //导入依赖的package包/类
/**
* Websocket für das Administrieren der Spielfelder verwalten.
*/
public static WebSocket<JsonNode> administratePlayground() {
final User user = getUMS().getLoggedUser(session());
return new WebSocket<JsonNode>() {
public void onReady(WebSocket.In<JsonNode> in, WebSocket.Out<JsonNode> out){
try {
GameHall.join(user, in, out);
} catch (Exception ex) {
ex.printStackTrace();
}
}
};
}