Skip to content

Commit

Permalink
Merge pull request #459 from videogular/feat/unregister-media
Browse files Browse the repository at this point in the history
feat(api): Add unregister media method to api
  • Loading branch information
Elecash authored Mar 26, 2017
2 parents d77e506 + 352714f commit 7ab6b56
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/core/services/vg-api.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -328,4 +328,13 @@ describe('Videogular Player', () => {

expect(api.medias['main']).toBe(media);
});

it('Should register a new media object', () => {
let media = {id: 'main'};
api['main'] = {};

api.unregisterMedia(<IPlayable>media);

expect(api.medias['main']).toBe(undefined);
});
});
4 changes: 4 additions & 0 deletions src/core/services/vg-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,8 @@ export class VgAPI {
registerMedia(media:IPlayable) {
this.medias[media.id] = media;
}

unregisterMedia(media:IPlayable) {
delete this.medias[media.id];
}
}
8 changes: 4 additions & 4 deletions src/core/vg-media/vg-media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,8 @@ export class VgMedia implements OnInit, OnDestroy, IPlayable {
this.elem = this.vgMedia.elem;
}

// It's not registered yet
if (!this.api.getMediaById(this.id)) {
this.api.registerMedia(this);
}
// Just in case we're creating this vgMedia dynamically register again into API
this.api.registerMedia(this);

this.subscriptions = {
// Native events
Expand Down Expand Up @@ -418,5 +416,7 @@ export class VgMedia implements OnInit, OnDestroy, IPlayable {
this.timeUpdateObs.unsubscribe();
this.volumeChangeObs.unsubscribe();
this.errorObs.unsubscribe();

this.api.unregisterMedia(this);
}
}

0 comments on commit 7ab6b56

Please sign in to comment.