
Product
Introducing Tier 1 Reachability: Precision CVE Triage for Enterprise Teams
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
@wxcloud/miniprogram-websocket-polyfill
Advanced tools
为第三方库(如socket.io-client)使用浏览器WebSocket对象提供适配小程序的版本。支持创建连接WSS/微信云托管的WebSocket。
连接WSS的后台服务:依赖小程序基础库版本 >= 1.7.0 的环境 连接微信云托管的后台服务:依赖小程序基础库版本 >= 2.22.1 的环境
以使用socket.io-client创建WebSocket客户端为例,大致步骤如下:
npm install --save @wxcloud/miniprogram-websocket-polyfill
import { setup } from '@wxcloud/miniprogram-websocket-polyfill'
import * as socketIO from 'socket.io-client'
let socket
Page({
onLoad() {
this.testLocalSocketIO()
},
// 连接HTTP
testLocalSocketIO() {
setup()
socket = socketIO.io('ws://127.0.0.1:3000', { transports: ['websocket'], query: { test: '112' } })
socket.on('connect', () => {
console.log('HTTP socket client connected')
})
socket.on('message', (msg) => {
console.log('HTTP socket client reveived: ', msg)
})
socket.on('connect_error', (e) => {
console.log('HTTP connect_error', e)
})
},
onSengMsg() {
socket.emit('message', '这是HTTP点击触发信息')
}
})
import { setup } from '@wxcloud/miniprogram-websocket-polyfill'
import * as socketIO from 'socket.io-client'
let socket
Page({
onLoad() {
this.testContainerSocketIO()
},
testContainerSocketIO() {
setup({
container: true,
containerConfigs: {
config: {
env: 'env-id' // 环境id
},
service: 'socket-io-sever',// 服务名
}
})
// 这里兼容socketio,可任意传入一个符合URL规范的字符串
socket = socketIO.io('wss://clound-container', { transports: ['websocket'] })
socket.on('connect', () => {
console.log('socket client connected')
})
socket.on('message', (msg) => {
console.log('socket client reveived: ', msg)
})
socket.on('connect_error', (e) => {
console.log('connect_error', e)
})
},
onSengMsg() {
socket.emit('message', '这是HTTP点击触发信息')
}
})
initOptions类型可参考dist/index.d.ts
里的定义
browser
,以指示webpack在构建过程能打包出支持在browser环境下运行的版本。同时,需要根据官方指引去除debug模块。transports: ['websocket']
FAQs
websocket polyfill for miniprogram
We found that @wxcloud/miniprogram-websocket-polyfill demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.
Research
/Security News
Ongoing npm supply chain attack spreads to DuckDB: multiple packages compromised with the same wallet-drainer malware.
Security News
The MCP Steering Committee has launched the official MCP Registry in preview, a central hub for discovering and publishing MCP servers.