如何在takeWhile中使用rxjs缓冲区
我在webrtc上工作。应用程序将ICE候选对象发送到后端firestore服务器。 问题是对信令服务器的调用被多次触发,因为onicecandidate被多次触发。我想收集所有的ICE候选者,然后给信令服务器打一个电话。 其思想是缓冲所有事件,直到ICE收集完成。下面的尝试无效如何在takeWhile中使用rxjs缓冲区,rxjs,buffer,Rxjs,Buffer,我在webrtc上工作。应用程序将ICE候选对象发送到后端firestore服务器。 问题是对信令服务器的调用被多次触发,因为onicecandidate被多次触发。我想收集所有的ICE候选者,然后给信令服务器打一个电话。 其思想是缓冲所有事件,直到ICE收集完成。下面的尝试无效 this.pc = new RTCPeerConnection(iceServers); const source: Observable<any> = fromEvent(this.pc, 'iceca
this.pc = new RTCPeerConnection(iceServers);
const source: Observable<any> = fromEvent(this.pc, 'icecandidate');
const takeWhile$ = source
.pipe(
takeWhile(val=> val.currentTarget.iceGatheringState === 'gathering'
))
const buff = source.pipe(buffer(takeWhile$));
buff.subscribe(() => {
// this.pc.onicecandidate = onicecandidateCallback;
})
this.pc=新的RTPeerConnection(ICeServer);
const source:Observable=fromEvent(this.pc,'icecandidate');
const takeWhile$=源
.烟斗(
takeWhile(val=>val.currentTarget.iceGatheringState==='gathering'
))
const buff=source.pipe(缓冲区(takeWhile$);
buff.subscribe(()=>{
//this.pc.onicecandidate=onicecandidateCallback;
})
方法1:
你就快到了
takeWhile$
获取值并在满足条件时发出它们。因此,在buff
中,每当takeWhile$
发出一个值时,buff
就会发出一个icecandidate
事件缓冲区
this.pc = new RTCPeerConnection(iceServers);
const source: Observable<any> = fromEvent(this.pc, "icecandidate");
const takeWhile$ = source.pipe(
takeWhile(val => val.currentTarget.iceGatheringState === "gathering"),
takeLast(1)
);
const buff = source.pipe(buffer(takeWhile$));
buff.subscribe((bufferValues) => {
// bufferValues has a buffer of icecandidate events
// this.pc.onicecandidate = onicecandidateCallback;
});
因此,您只需要在takeWhile$
中发出一个值
因此,您需要的是takeLast()
运算符只发出最后一个值
当您将takeLast(1)
放在takeWhile$
中时,它只会发出最后一个值,而在buff
中,最后发出的值会导致创建icecandidate
事件的缓冲区
this.pc = new RTCPeerConnection(iceServers);
const source: Observable<any> = fromEvent(this.pc, "icecandidate");
const takeWhile$ = source.pipe(
takeWhile(val => val.currentTarget.iceGatheringState === "gathering"),
takeLast(1)
);
const buff = source.pipe(buffer(takeWhile$));
buff.subscribe((bufferValues) => {
// bufferValues has a buffer of icecandidate events
// this.pc.onicecandidate = onicecandidateCallback;
});
方法1: 你就快到了
takeWhile$
获取值并在满足条件时发出它们。因此,在buff
中,每当takeWhile$
发出一个值时,buff
就会发出一个icecandidate
事件缓冲区
this.pc = new RTCPeerConnection(iceServers);
const source: Observable<any> = fromEvent(this.pc, "icecandidate");
const takeWhile$ = source.pipe(
takeWhile(val => val.currentTarget.iceGatheringState === "gathering"),
takeLast(1)
);
const buff = source.pipe(buffer(takeWhile$));
buff.subscribe((bufferValues) => {
// bufferValues has a buffer of icecandidate events
// this.pc.onicecandidate = onicecandidateCallback;
});
因此,您只需要在takeWhile$
中发出一个值
因此,您需要的是takeLast()
运算符只发出最后一个值
当您将takeLast(1)
放在takeWhile$
中时,它只会发出最后一个值,而在buff
中,最后发出的值会导致创建icecandidate
事件的缓冲区
this.pc = new RTCPeerConnection(iceServers);
const source: Observable<any> = fromEvent(this.pc, "icecandidate");
const takeWhile$ = source.pipe(
takeWhile(val => val.currentTarget.iceGatheringState === "gathering"),
takeLast(1)
);
const buff = source.pipe(buffer(takeWhile$));
buff.subscribe((bufferValues) => {
// bufferValues has a buffer of icecandidate events
// this.pc.onicecandidate = onicecandidateCallback;
});
因此,是否要等到
收集完成后再发送最后一个值?还有,onicecandidateCallback
这是从哪里来的?问题基本上是“等待状态为未收集”然后分配此回调吗?因此,是否要等待收集完成,然后发送最后一个值?还有,onicecandidateCallback
这是从哪里来的?问题基本上是“等待状态未聚集”然后分配此回调吗?