本文整理汇总了Java中play.mvc.WebSocket.Out方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocket.Out方法的具体用法?Java WebSocket.Out怎么用?Java WebSocket.Out使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类play.mvc.WebSocket
的用法示例。
在下文中一共展示了WebSocket.Out方法的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: 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);
}
示例3: 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();
}
}
};
}
示例4: 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);
}
}
};
}
示例5: 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)));
}
示例6: 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();
}
}
};
}
示例7: 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();
}
}
};
}
示例8: 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();
}
}
};
}
示例9: 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();
}
});
}
};
}
示例10: 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();
}
示例11: 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();
}
}
};
}
示例12: RaceChatModel
import play.mvc.WebSocket; //导入方法依赖的package包/类
public RaceChatModel(String hostId, Map<String, WebSocket.Out<JsonNode>> members) {
m_hostId = hostId;
m_members = members;
recordList = new ArrayList<History>();
drawedDict = new HashMap<String, Integer>();
flowerWinnerList = new ArrayList<String>();
}
示例13: notifyAll
import play.mvc.WebSocket; //导入方法依赖的package包/类
private void notifyAll(String kind, String user,String userId,String toUserName,String toUserId, String text,boolean isOnline,boolean isOwners) {
/*
if (m_members.values().size() > SIZE_THRESHOLD) {
if (kind.compareToIgnoreCase("talk") != 0 &&
kind.compareToIgnoreCase("present") != 0) {
if (userId == null || m_roomId == null) {
return;
}
if (userId.compareToIgnoreCase(m_roomId) != 0) {
return;
}
//ban zhulaile
Logger.info(kind + ":" + userId + " " + user);
}
}
*/
for(WebSocket.Out<JsonNode> channel: m_members.values()) {
ObjectNode event = Json.newObject();
event.put("kind", kind);
event.put("user", user);
event.put("message", text);
event.put("userId", userId);
event.put("toUser", toUserName);
event.put("toUserId", toUserId);
event.put("isOnline", isOnline);
event.put("isOwners", isOwners);
event.put("peopleNum", m_members.keySet().size());
try {
channel.write(event);
}
catch (Throwable e) {
}
}
}
示例14: Join
import play.mvc.WebSocket; //导入方法依赖的package包/类
public Join(String username,String userId, WebSocket.Out<JsonNode> channel,boolean isOnline,boolean isOwners) {
this.username = username;
this.userId = userId;
this.channel = channel;
this.isOnline =isOnline ;
this.isOwners = isOwners;
}
示例15: wsInterface
import play.mvc.WebSocket; //导入方法依赖的package包/类
public static WebSocket<String> wsInterface() {
return new WebSocket<String>() {
@Override
public void onReady(WebSocket.In<String> in, WebSocket.Out<String> out) {
SimpleChat.start(in,out);
}
};
}