
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
ws-event-bus
Advanced tools
开发时使用的event bus;利用ws服务器作为中转。
npm i ws -D
npm i ws-event-bus -D
浏览器端:
html:
<body>
<button id="btn1">btn1</button>
<button id="btn2">btn2</button>
</body>
js(需要打包):
import WSS from 'ws-event-bus'
function getClient(id) {
let ws = new WSS({
id,
url: 'ws://localhost:8080/'
})
ws.on('message', (data) => {
console.log(id + ' get message >>>>', data)
})
ws.on('wait', (data,response) => {
console.log(id + ' wait >>>>', response)
})
return ws
}
let w1 = getClient('w1')
let w2 = getClient('w2')
function click1(){
w1.send('this is w1+', {
to: 'w2'
}).then(res => {
console.log('w1 get reply')
})
}
function click2(){
w2.reply(w2.waiting[0],'value')
}
document.getElementById('btn1').onclick = click1
document.getElementById('btn2').onclick = click2
server:
const WSS = require('ws-event-bus/dist/server.js').default
const path = require('path')
let server = new Server({
port:8080
})
server.static(path.resolve(process.cwd()),'./');//静态资源
server.start()
nodejs:
const WSS = require('ws-event-bus').default
function getClient(id) {
let ws = new WSS({
id,
url: 'ws://localhost:8080/'
})
ws.on('message', (data) => {
console.log(id + ' get message>>>>', data)
})
ws.on('wait', (data, response) => {
console.log(id + ' wait >>>>', response)
})
return ws
}
let w1 = getClient('w1')
let w2 = getClient('w2')
function click1() {
w1.send('this is w1+', {
to: 'w2'
}).then(res => {
console.log('w1 sucewss++++', res)
})
}
function click2() {
w2.reply(w2.waiting[0],'value')
}
click1()
setTimeout(() => {
click2()
}, 3000)
setTimeout(() => {}, 100000)
FAQs
event bus between frontend and backend
The npm package ws-event-bus receives a total of 0 weekly downloads. As such, ws-event-bus popularity was classified as not popular.
We found that ws-event-bus demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.