Files
Hippy/framework/js/packages/hippy-debug-server/webpack-dev-server/client-src/clients/SockJSClient.js
T
chestershen 26e6434b75 feat(vue, react, debug-server, vue-loader, vue-css-loader): support HMR
- hippy-vue: ElementNode add repaintWithChildren API

- hippy-vue: support remove outdated style of HMR chunk

- hippy-vue-loader: support style hmr

- hippy-vue-css-loader: support remove outdated style of HMR chunk

- debug-server, vue-demo, react-demo, hippy-react: support hmr

- debug-server: add hippy-dev command
2021-12-28 22:31:37 +08:00

28 lines
591 B
JavaScript

import SockJS from '../modules/sockjs-client/index';
import { log } from '../utils/log';
export default class SockJSClient {
constructor(url) {
// SockJS requires `http` and `https` protocols
this.sock = new SockJS(url.replace(/^ws:/i, 'http:').replace(/^wss:/i, 'https:'));
this.sock.onerror = (error) => {
log.error(error);
};
}
onOpen(f) {
this.sock.onopen = f;
}
onClose(f) {
this.sock.onclose = f;
}
// call f with the message string as the first argument
onMessage(f) {
this.sock.onmessage = (e) => {
f(e.data);
};
}
}