Primefaces Push - What are the methods in <p:socket/> client widget

别等时光非礼了梦想. 提交于 2020-01-06 03:22:04

问题



Can anybody point me to any api link which contains the <p:socket/> client widget?

Going through the push showcase I can only see connect method in requestContext.execute("subscriber.connect('/" + username + "')"); What are the other methods.? Is there any disconnect method as-well.?

Also, how to create separate channel for each user (in case of chat application). I reckon, this <p:socket onMessage="handleMessage" channel="/chat/#{userSession.userId}" autoConnect="false" widgetVar="subscriber"/> will do the trick but apparantly it is not, atleast for me. Because by looking in the Chrome dev console I can see that everytime the page is refreshed it is appending the channel name (/chat/userid/userid...).

Any pointers is highly appreciated.!!!


回答1:


I think I got the answer for some of the issue I'm facing.

  1. For methods in push widget, push.js is the file to look for.
  2. The appending issue is because of calling

    requestContext.execute("subscriber.connect('/" + username + "')");

    multiple time. The below code gets called which results in appending of the channel names multiple times.

    connect: function (a) {if (a) {
        this.cfg.request.url += a  // <----
    }
    this.connection = $.atmosphere.subscribe(this.cfg.request)
    
  3. Disconnect method is available in PF 4.0. or you can add the following code to push.js.

     disconnect: function () {  
         this.connection.close()
     }
    


来源:https://stackoverflow.com/questions/21253484/primefaces-push-what-are-the-methods-in-psocket-client-widget

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!