
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
@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
The npm package @wxcloud/miniprogram-websocket-polyfill receives a total of 0 weekly downloads. As such, @wxcloud/miniprogram-websocket-polyfill popularity was classified as not popular.
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.
Security News
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.