我正在使用具有非常特定的API的WebRTC庫。該peerConnection.setRemoteDescription
方法的第二個參數應該是當它完成設置遠程描述回調:Redux Observable:如何從回調中返回一個動作?
這是我的WebRTC類的我的包裝功能之一:
export function setRemoteSdp(peerConnection, sdp, callback) {
if (!sdp) return;
return peerConnection.setRemoteDescription(
new RTCSessionDescription(sdp),
callback, // <-------------
);
}
這是一個小品是什麼我想要做的:
function receivedSdp(action$, store) {
return action$.ofType(VideoStream.RECEIVED_SDP)
.mergeMap(action => {
const {peerConnection} = store.getState().videoStreams;
const {sdp} = action.payload;
return WebRTC.setRemoteSdp(peerConnection, sdp,() => {
return myReducer.myAction(); // <------ return action as the callback
})
})
};
這不起作用,因爲我沒有返回Observable。有沒有辦法做到這一點?
P.S.這是WebRTC API:https://github.com/oney/react-native-webrtc/blob/master/RTCPeerConnection.js#L176
天才! Observable.create是我一直在尋找的。感謝martin – Edmund
@martin嗯爲什麼它需要'mergeAll'? 'mergeMap'會使返回的自定義Observable變平,它只發出POJO動作? – jayphelps