【发布时间】:2020-09-03 21:57:33
【问题描述】:
我得到一个空的.onmessage
但是 .onopen 正在工作
import * as types from './types';
import { eventChannel } from 'redux-saga';
import { takeEvery, put, call, select, take } from 'redux-saga/effects';
export function* createEventChannel() {
const mySocket = new WebSocket('wss://url.com');
return eventChannel((emit: any) => {
mySocket.onopen = () => {
mySocket.send("sdsdsdsd!");
};
// =====> onmessage is getting null
mySocket.onmessage((message:any) => {
emit(message.data)
});
return () => {
mySocket.close();
};
});
}
export function* workWebSocket(action:any) {
const channel = yield call(createEventChannel);
while (true) {
const { message } = yield take(channel);
yield put({ type: types.WEB_SOCKET_SUCCESS, message: message });
}
}
export default function* watchHydration() {
yield takeEvery(types.WEB_SOCKET_FETCH, workWebSocket);
}
关于我为什么会为空的任何建议?
【问题讨论】:
标签: reactjs redux websocket redux-saga