我正在使用WebRTC和redux sagas。一个要求是我必须定义peerConnection.onicecandidate
:
function* createPeerConnection(action) {
...
peerConnection = new RTCPeerConnection(servers);
peerConnection.onicecandidate = (event) => {
if (event.candidate) {
yield put({ type: videoSessionActions.SEND_LOCAL_CANDIDATE, payload: event.candidate });
}
}
}
但是,yield put
无法使用此方法。我如何改变它以使其适用于传奇?
答案 0 :(得分:1)
希望活动频道可以帮助您:
import { eventChannel, END } from 'redux-saga';
import { put, take } from 'redux-saga/effects';
import { videoSessionActions } from '../???/constants';
const rtcChannel = servers => eventChannel(emitter => {
const peerConnection = new RTCPeerConnection(servers);
peerConnection.onicecandidate = event => {
if (event.candidate) {
emitter({type: videoSessionActions.SEND_LOCAL_CANDIDATE, payload: event.candidate});
}
};
return () => {
peerConnection.close();
};
}
// ,buffers.expanding(1024) ???
);
function* createPeerConnection(servers) {
const ch = rtcChannel(servers);
while(true) { // eslint-disable-line no-constant-condition
const candidate = yield take(ch);
yield put(candidate);
}
}