Comments (4)
请展示您的代码,方便我们排查
from weapp.socket.io.
const io = require('../utils/weapp.socket.io.js')
let socket = null
let url = null;
function createConnect(conn = { url: "", room:"socketRoom",response:()=>{},onLine:()=>{},onClose:()=>{},onError:()=>{},onSystem:()=>{}}) {
url = conn.url
socket = (this.socket = io(
url,
{
query: {
room: conn.room,
userId: `client_${Math.random()}`,
},
transports: ['websocket']
}
))
console.log("socket",socket)
const id = socket.id
socket.on('connect', () => {
})
socket.on(id, msg => {
conn.response(msg)
});
socket.on('online', (msg) => {
conn.onLine(msg)
})
socket.on('system', (msg) => {
conn.onSystem(msg)
})
socket.on('disconnect', msg => {
conn.onClose(msg)
});
socket.on('error', (e) => {
conn.onError(e)
});
}
function closeSocket(){
if (this.socket) {
this.socket.close()
this.socket = null
wx.closeSocket({
url: url,
success: () => {
console.log("socket close success")
}
})
}
}
module.exports={
createConnect: createConnect,
closeSocket: closeSocket
}
from weapp.socket.io.
调用
webSocket.createConnect({
url: 'socket的url',
room: room,
response: (res) => {
console.log("res:", res);
},
onLine: (msg) => {
console.log("online:", msg)
},
onError: (err) => {
},
onClose: (e) => {
},
onSystem: (msg) => {
console.log("system", msg)
if (msg.type == 'update' && msg.success) {
}
}
})
from weapp.socket.io.
@niefang2017 本项目在内部管理力 websocket 的连接状态(open,close等),请不要再使用 wx API 管理连接,你不应该自己定义 closeSocket
方法来主动关闭连接。如需主动关闭请参考如下代码:
const socket = io(wx://example.com)
socket.disconnect()
from weapp.socket.io.
Related Issues (20)
- 用了一下,请教! HOT 1
- 服务端我用的2.x版本,这个是否支持呢? HOT 1
- 微信小程序出现bug
- 服务端socket.io @4 能用这个包吗? HOT 9
- 能支持socket.io-client 4.6.1最新版本吗? HOT 2
- WebSocket was closed before the connection was established HOT 4
- Converting circular structure to JSON --> starting at object with constructor 'c' | property 'io' -> object with constructor 'f' | property 'nsps' -> object with constructor 'Object' --- property '//undefined//undefined' closes the circle at JSON.stringify (<anonymous>) at cloneWithData (vendor.js? [sm]:9037) at VueComponent.patch [as __patch__] (vendor.js? [sm]:9050) at VueComponent.Vue._update (vendor.js? [sm]:7359) at VueComponent.updateComponent (vendor.js? [sm]:9118) at Watcher.get (vendor.js? [sm]:7819) at Watcher.run (vendor.js? [sm]:7894) at flushSchedulerQueue (vendor.js? [sm]:7650) at Array.<anonymous> (vendor.js? [sm]:5389) at flushCallbacks (vendor.js? [sm]:5317)(env: Windows,mp,1.06.2307260; lib: 3.1.0)
- 客服端发的消息,服务端会同时收到两条一样的 HOT 1
- 提一个非常实用的小建议:剔除socket.io-client依赖。 HOT 2
- npm 安装使用无效, 用源码编译出来的js直接使用可以.
- IOS 11.2 不支持...扩展ES6语法 HOT 2
- 小程序重复退出、再次进入操作socket连接报错:websocket was closed before the connection was established
- 3.0.0版本在微信小程序分包里面调用connect时,真机上预览、体验版均会报错
- 目前是不是不支持polling模式? HOT 2
- TypeError: io is not a function HOT 2
- 能不能出一个client版本是2.X的版本 HOT 1
- 想请教这个包的目的到底什么? HOT 3
- 为什么yarn install 和npm install生成的weapp.socket.io.js不一样呢?
- 请教python flask-socketio不兼容这个微信小程序js文件,报错"GET /socket.io/?EIO=4&transport=websocket HTTP/1.1" 400 ,是本项目依赖的socket.io-client版本太低了吗?
- 请问支持支付宝小程序吗? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from weapp.socket.io.