logic-helper
Version:
This template should help get you started developing with Vue 3 in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
49 lines (43 loc) • 997 B
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button id="btn1">btn1</button>
<button id="btn2">btn2</button>
<script type="module">
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.replay(w2.waiting[0])
}
document.getElementById('btn1').onclick = click1
document.getElementById('btn2').onclick = click2
</script>
</body>
</html>