0.1.0 • Published 7 years ago
wx-ws v0.1.0
Wechat/Weixin Apps and Games WebSocket Wrapper
NOTTICE This package is still in testing progress and internally used in our own game project based on Cocos.
Although not mentioned by Wechat/Weixin official, the internal object WebSocket
could be used in Wechat/Weixin Games as well, but it can only open two
connections, and later connections will kick out former ones. But via the
official recommended way wx.connectSocket, users can build at most 5
connections. This package is a wrapper of wx.connectSocket to replace the
internal WebSocket object, and keep the way of usage.
More about WebSocket, please check
WebSocket - Web APIs | MDN.
Example
import { WebSocket as wxWebSocket } from "wx-ws";
declare global {
const wx: any;
}
if (typeof wx == "object" && typeof wx.connectSocket == "function") {
// replace the internal WebSocket object
WebSocket = wxWebSocket;
}
// ...
var ws = new WebSocket(/* ... */);0.1.0
7 years ago