当我测试primefaces(5.2)推送示例(计数器,通知,照片共享)时,所有工作都完全正常,除了聊天(same code from page primefaces,从示例页面复制粘贴代码),这里发生一个细节:
私人频道= / pushmob / primepush / {room} / felipe
用户名:"菲利普" 退出
用户名:"菲利普"登录(私信不起作用)
私人频道= / pushmob / primepush / {room} / felipe / felipe
另一个用户登录无法向felipe发送私信。
对于私有频道的检测,我在控制台中使用 PF('订户&#39)。cfg.request.url
任何想法???
PrimeFaces 5.2
大气2.3.4
聊天示例中的相同代码。
的web.xml
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
的index.xhtml
<p:socket onMessage="handleMessageChat" channel="/{room}"
autoConnect="false" widgetVar='subscriber' />
chatview.xhtml
public class ChatView implements Serializable {
private final static String CHANNEL = "/{room}/";
public void sendGlobal() {
eventBus.publish(CHANNEL + "*", username + ": " + globalMessage);
globalMessage = null;
}
public void sendPrivate() {
eventBus.publish(CHANNEL + privateUser, "[PM "+ username + "] " + username + ": "
+ privateMessage);
eventBus.publish(CHANNEL + username, "[PM " + privateUser + "] " + username + ": "
+ privateMessage);
privateMessage = null;
}
public void login() {
RequestContext requestContext = RequestContext.getCurrentInstance();
if(users.contains(username)) {
loggedIn = false;
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username taken", "Try with another username."));
requestContext.update("growl");
}
else {
users.add(username);
requestContext.execute("PF('subscriber').connect('/" + username + "')");
loggedIn = true;
}
}
public void disconnect() {
//remove user and update ui
users.remove(username);
RequestContext.getCurrentInstance().update("form:users");
//push leave information
eventBus.publish(CHANNEL + "*", username + " left the channel.");
//reset state
loggedIn = false;
username = null;
}
} }
答案 0 :(得分:0)
解决了...我必须创建两个页面,一个用于登录,另一个用于聊天,允许成功使用私有频道。