Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dummy connection changes #47

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions addon/hifi-connections/dummy-connection.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { next, bind } from '@ember/runloop';
import Mixin from '@ember/object/mixin';
import Ember from 'ember';
import BaseSound from './base';
let ClassMethods = Mixin.create({
setup() {},
Expand All @@ -12,7 +11,6 @@ let ClassMethods = Mixin.create({
}
});


let DummyConnection = BaseSound.extend({
debugName: 'dummyConnection',
_position: 0,
Expand All @@ -27,19 +25,26 @@ let DummyConnection = BaseSound.extend({
}
},

stopAudio: function() {
this.stopTicking();
if (!this.get('_audioEnded')) {
// Don't start audio again after it's finished. I think this is ok for test audio.
this.set('_audioEnded', true);
this.trigger('audio-ended', this);
}
},

stopTicking: function() {
window.clearTimeout(this.tick);
},

startTicking: function() {
if (!Ember.Test.checkWaiters || Ember.Test.checkWaiters()) {
this.tick = window.setTimeout(bind(() => {
this._setPosition((this._currentPosition() || 0) + this.get('_tickInterval'));
this.tick = window.setTimeout(bind(() => {
let shouldContinue = this._setPosition((this._currentPosition() || 0) + this.get('_tickInterval'));
if (shouldContinue) {
this.startTicking();
}), this.get('_tickInterval'));
} else {
this.stopTicking();
}
}
}), this.get('_tickInterval'));
},

getInfoFromUrl: function() {
Expand Down Expand Up @@ -92,13 +97,12 @@ let DummyConnection = BaseSound.extend({
this.set('_position', duration);

if (duration >= this._audioDuration()) {
next(() => {
this.trigger('audio-ended', this);
this.stopTicking();
});
this.stopAudio();
return false
}
else {
return duration;
}

return duration;
},
_currentPosition() {
return this.get('_position');
Expand Down