<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                WebSocket支持同時給app端和pc端發送消息 #### (1) WebSocket操作類 > 通過修改該類WebSocket可以進行同一用戶多端的消息推送 ``` @Component @Slf4j @ServerEndpoint("/websocket/{userId}") public class WebSocket { //省略部分代碼 //1.增加app端標識 private String APP_SESSION_SUFFIX = "_app"; // 2.修改單點消息方法 public void sendOneMessage(String userId, String message) { Session session = sessionPool.get(userId); if (session != null&&session.isOpen()) { try { log.info("【websocket消息】 單點消息:"+message); session.getAsyncRemote().sendText(message); } catch (Exception e) { e.printStackTrace(); } } //--------3.增加APP端消息推送-------- Session session_app = sessionPool.get(userId+APP_SESSION_SUFFIX ); if (session_app != null&&session_app .isOpen()) { try { log.info("【websocket移動端消息】 單點消息:"+message); session_app .getAsyncRemote().sendText(message); } catch (Exception e) { e.printStackTrace(); } } } //省略部分代碼 //------其他類似方法修改同上---------- } ``` ### 前端uniapp中使用WebSocket ``` <script> //引用socket.js import socket from '@/common/js-sdk/socket/socket.js' export default { data() { return { } }, mounted() { //初始化websocket this.onSocketOpen() this.onSocketReceive() }, destroyed: function () { // 離開頁面生命周期函數 socket.closeSocket() }, methods: { onSocketOpen: function () { // WebSocket與普通的請求所用協議有所不同,ws等同于http,wss等同于https socket.init('websocket'); //對應要連接的socket }, onSocketReceive: function () { var _this=this socket.acceptMessage = function(res){ // console.log("頁面收到的消息", res); if(res.cmd == "topic"){ //系統通知 }else if(res.cmd == "user"){ //用戶消息 } else if(res.cmd == 'email'){ //郵件消息 } } } } } </script> ``` socket.js連接url部分代碼修改 ``` init(socket_type,callback) { //省略部分代碼 let url=this.socketUrl.replace("https://","wss://").replace("http://","ws://") +"/"+socket_type+"/"+store.state.userid+"_app"; //省略部分代碼 } //相關參數 socketUrl :對應api地址 socket_type :對應你要連接的是哪個websocket "_app" :標識這是移動端 ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看