I've been digging an issue with Angular 4 and RxJS. Here is my code, the issue is, the http.post
request Observable is not emitting anything to the next of the chain, the map()
. The POST just get an endless response, it's a stream of Motion JPEG data. Now I have to deal with the data, say each 500KB transferred. My problem is that I cannot do anything with the data if the Observable not emitting anything.
So how to make such angular HTTP feature emit to the next of the chain each chunk of data transferred?
postActionGivenDataBinaryResponse(url:string, data:string) : Observable<any>{
let headers = new Headers ({
'Content-Type' : 'application/json;charset=utf-8'
}) ;
let options = new RequestOptions({
headers : headers,
responseType: ResponseContentType.ArrayBuffer
}) ;
//return binary data as is no json
return this.http.post(url, data, options) //suspecting here is not emitting anything due to unknown configuration issue.
.map(this.extractBinaryData)
.catch(this.handleError) ;
}
private extractBinaryData(res:Response){
console.log('Dealing with data in the com service.') ; // this never runs
return res ;
}
I call the above function like this, the post response is an endless binary data, I need to process it as string array.
this.mySubscription = this.comService.postActionGivenDataBinaryResponse(myurl,mydata)
.do(()=>{
console.log('Observable Passed data.') ; //this never runs.
})
.bufferCount(128000)
.map((data)=>{//process the data each 128kb chunk})
.subscribe();