When I'm testing the primefaces(5.2) push example (counter, notify, photoshared) all work completely, except chat (same code from page primefaces, copy paste the code from example page), here occur a detail:
private channel = /pushmob/primepush/{room}/felipe
username:"felipe" log out
username:"felipe" log in (private message not work)
private channel = /pushmob/primepush/{room}/felipe/felipe
Another user login can't send private message to felipe.
For detect to private channel, i use in console PF('subscriber').cfg.request.url
Any idea???
PrimeFaces 5.2
Atmosphere 2.3.4
Same code from chat example.
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;
}
} }
Solved...I had to create two pages, one for login and another for chat, allowing successfully use the private channel.