微信应用号小程序wx.sendSocketMessage(OBJECT)

时间:2016-10-03 21:26:15   收藏:0   阅读:484

微信应用号小程序wx.sendSocketMessage(OBJECT)

wx.sendSocketMessage(OBJECT)

? 通过WebSocket连接发送数据,需要先wx.connectSocket,并在wx.onSocketOpen回调之后才能发送。

OBJECT参数说明:

参数类型必填说明
data String 需要发送的内容

示例代码:

var socketOpen = false;
var socketMsgQueue = []
wx.connectSocket({
  url:"qkxue.net"
});

wx.onSocketOpen(function(res){
  socketOpen = true;
  for(var i = 0 ; i < socketMsgQueue.length; i++){
     sendSocketMessage(socketMsgQueue[i])
  }
  socketMsgQueue = [];
})

function sendSocketMessage(msg){
  if(socketOpen){
    wx.sendSocketMessage({
       data:msg
    });
  }else{
     socketMsgQueue.push(msg)
  }
}
稿源:勤快学QKXue.NET
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!