I have an object that looks like this: [{ timestamp: object }]
The timestamp is created timestamp = Date.now();
Now, I am looking for a way to create an Observable that emits the objects in the real sequence, i.e. when the time between entries is 200ms then it needs to wait 200ms, if it's 2.5 seconds then it needs to wait 2500ms.
I get the difference by subtracting the two adjacent index values from each other.
My code is here:
startReplay() {
this.recordingRunning = true;
const replayValues = this.recordedListeningValues;
this.formObservable = Observable.create(function(observer) {
let lastTs;
Object.keys(replayValues).forEach(function(key) {
observer.timer(Math.floor((Number(key) - lastTs) / 1000)).next(key, lastTs);
lastTs = Number(key);
});
});
var source = this.formObservable.subscribe(x => console.log(x));
}
It throws the error: observer.timer is not a function
At the moment, I am only trying to log the differences between the timestamps in seconds. Now, I want to emit it in the differences between the two timestamps.
onNextwas used in RxJS 4, in RxJS 5 callnextinstead.Observable.interval- I guess this is used to create an observable emit periodically.Observable.timernotobserver.timer