yiyi-websocket

1.0.2 • Public • Published

安装依赖

npm install yiyi-websocket

导入依赖

import Socket from 'yiyi-websocket';

const socket = new Socket({ url: 'ws://localhost:8080' });

const handleClick = () => {
    socket.connectWebSocket().then(res => {
        console.log('connect', res);
    });
    socket.onopen = function (e) {
        console.log('onOpen', e);
    };
    socket.onmessage = function (e) {
        console.log('onmessage', e.data, JSON.parse(e.data));
    };
    socket.onclose = function (e) {
        console.log('onclose', e);
    };
    socket.onerror = function (e) {
        console.log('onerror', e);
    };
};
const handleSend = () => {
    socket.sendMessage(new Date().getTime()).then(res => {
        console.log('sendMessage', res);
    });
};
const handleClose = () => {
    socket.closeWebSocket();
};

Dependents (0)

Package Sidebar

Install

npm i yiyi-websocket

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.58 kB

Total Files

4

Last publish

Collaborators

  • jiaoren