Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
fix: Fill metadatas values #14
Browse files Browse the repository at this point in the history
  • Loading branch information
GERMA Delphin Ext IMT/OLS authored and GERMA Delphin Ext IMT/OLS committed Jul 20, 2018
1 parent 3f63145 commit 54e719f
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 26 deletions.
68 changes: 46 additions & 22 deletions src/media/video.media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,57 +250,81 @@ export class VideoMedia extends Media {

private updateTracks() {
// Catch AudioTracks
let i = 0;
let tracks;
tracks = [];
// TODO: Refactor this code (redundancy)
let audioTracks = this.mediaElement.audioTracks;
const audioTracks = this.mediaElement.audioTracks;
if (audioTracks) {
for (i = 0; i < audioTracks.length; i++) {
audioTracks.forEach((audioTrack: any, index: number) => {
if (!audioTrack.hasOwnProperty("enabled")) {
Log.info(TAG + " When extract metadatas, audio track " + index + " haven't enabled property defined");
}
if (!audioTrack.hasOwnProperty("language")) {
Log.info(TAG + " When extract metadatas, audio track " + index + " haven't language property defined");
}
if (!audioTrack.hasOwnProperty("label")) {
Log.info(TAG + " When extract metadatas, audio track " + index + " haven't label property defined");
}
tracks.push(
new Track(
EnumTrack.AUDIO,
i.toString(),
audioTracks[i].enabled,
audioTracks[i].language,
audioTracks[i].label,
index.toString(),
audioTrack.enabled,
audioTrack.language,
audioTrack.label,
),
);
}
});
this.metadata.audioTracks = tracks;
}
// Catch VideoTracks
tracks = [];
let videoTracks = this.mediaElement.videoTracks;
const videoTracks = this.mediaElement.videoTracks;
if (videoTracks) {
for (i = 0; i < videoTracks.length; i++) {
videoTracks.forEach((videoTrack: any, index: number) => {
if (!videoTrack.hasOwnProperty("selected")) {
Log.info(TAG + " When extract metadatas, video track " + index + " haven't selected property defined"
+ " (to set 'enabled' property)");
}
if (!videoTrack.hasOwnProperty("language")) {
Log.info(TAG + " When extract metadatas, video track " + index + " haven't language property defined");
}
if (!videoTrack.hasOwnProperty("label")) {
Log.info(TAG + " When extract metadatas, video track " + index + " haven't label property defined");
}
tracks.push(
new Track(
EnumTrack.VIDEO,
i.toString(),
videoTracks[i].selected,
videoTracks[i].language,
videoTracks[i].label,
index.toString(),
videoTrack.selected,
videoTrack.language,
videoTrack.label,
),
);
}
});
this.metadata.videoTracks = tracks;
}
// Catch TextTracks
tracks = [];
let textTracks = this.mediaElement.textTracks;
const textTracks = this.mediaElement.textTracks;
if (textTracks) {
for (i = 0; i < textTracks.length; i++) {
textTracks.forEach((textTrack: any, index: number) => {
if (!textTrack.hasOwnProperty("language")) {
Log.info(TAG + " When extract metadatas, text track " + index + " haven't language property defined");
}
if (!textTrack.hasOwnProperty("label")) {
Log.info(TAG + " When extract metadatas, text track " + index + " haven't label property defined");
}
tracks.push(
new Track(
EnumTrack.TEXT,
i.toString(),
textTracks[i].mode === "showing",
textTracks[i].language,
textTracks[i].label,
index.toString(),
textTrack.mode === "showing",
textTrack.language,
textTrack.label,
),
);
}
});
this.metadata.textTracks = tracks;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/protocol/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Track {
* @param language
* @param label
*/
constructor(public type: EnumTrack, public trackId: string, public enabled: boolean,
public language: string, public label: string) {
constructor(public type: EnumTrack, public trackId: string, public enabled: boolean = false,
public language: string = "", public label: string = "") {
}
}
2 changes: 0 additions & 2 deletions test/channel.mediachannel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {Logger} from "../src/util/logger";
import {VideoPlayer} from "./mock/video.player";

import d2r = require("ocast-dongletv");
import assert = require("assert");
import chai = require("chai");
import os = require("os");
import util = require("util");

const expect = chai.expect;

Expand Down
126 changes: 126 additions & 0 deletions test/video.media.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { VideoMedia } from "../src";
import chai = require("chai");
import { Metadata } from "../src/protocol/metadata";

const expect = chai.expect;

describe("VideoMedia", () => {

let videoMedia: VideoMedia = null;
let mediaElement: any = null;
before(() => {
mediaElement = {};
videoMedia = new VideoMedia(mediaElement, null);
});

it("When VideoMedia take partial metadatas, it give metadatas corrects => Check audio tracks", () => {
videoMedia.setMetadata(null, null, null, null, null);
mediaElement.audioTracks = [
{
enabled: true,
label: "English",
language: "en",
},
{
enabled: false,
language: "fr",
},
{
// No data
},
];
const metadatas: Metadata = videoMedia.getMedatadata();
expect(metadatas.audioTracks.length).to.equals(3, "Check how many audio tracks have been restitued");
if (metadatas.audioTracks.length === 3) {
// Don't execute next tests if length is bad!
expect(metadatas.audioTracks[0].enabled).to.equals(true, "Check enabled field for the first audio track");
expect(metadatas.audioTracks[0].label).to.equals("English", "Check label field for the first audio track");
expect(metadatas.audioTracks[0].language).to.equals("en",
"Check language field for the first audio track");

expect(metadatas.audioTracks[1].enabled).to.equals(false, "Check enabled field for the second audio track");
expect(metadatas.audioTracks[1].label).to.equals("", "Check label field for the second audio track");
expect(metadatas.audioTracks[1].language).to.equals("fr",
"Check language field for the second audio track");

expect(metadatas.audioTracks[2].enabled).to.equals(false, "Check enabled field for the third audio track");
expect(metadatas.audioTracks[2].label).to.equals("", "Check label field for the third audio track");
expect(metadatas.audioTracks[2].language).to.equals("",
"Check language field for the third audio track");
}
});

it("When VideoMedia take partial metadatas, it give metadatas corrects => Check video tracks", () => {
videoMedia.setMetadata(null, null, null, null, null);
mediaElement.videoTracks = [
{
label: "English",
language: "en",
selected: true,
},
{
language: "fr",
selected: false,
},
{
// No data
},
];
const metadatas: Metadata = videoMedia.getMedatadata();
expect(metadatas.videoTracks.length).to.equals(3, "Check how many video tracks have been restitued");
if (metadatas.videoTracks.length === 3) {
// Don't execute next tests if length is bad!
expect(metadatas.videoTracks[0].enabled).to.equals(true, "Check enabled field for the first video track");
expect(metadatas.videoTracks[0].label).to.equals("English", "Check label field for the first video track");
expect(metadatas.videoTracks[0].language).to.equals("en",
"Check language field for the first video track");

expect(metadatas.videoTracks[1].enabled).to.equals(false, "Check enabled field for the second video track");
expect(metadatas.videoTracks[1].label).to.equals("", "Check label field for the second video track");
expect(metadatas.videoTracks[1].language).to.equals("fr",
"Check language field for the second video track");

expect(metadatas.videoTracks[2].enabled).to.equals(false, "Check enabled field for the third video track");
expect(metadatas.videoTracks[2].label).to.equals("", "Check label field for the third video track");
expect(metadatas.videoTracks[2].language).to.equals("",
"Check language field for the third video track");
}
});

it("When VideoMedia take partial metadatas, it give metadatas corrects => Check text tracks", () => {
videoMedia.setMetadata(null, null, null, null, null);
mediaElement.textTracks = [
{
label: "English",
language: "en",
mode: "showing",
},
{
language: "fr",
mode: "toto",
},
{
// No data
},
];
const metadatas: Metadata = videoMedia.getMedatadata();
expect(metadatas.textTracks.length).to.equals(3, "Check how many text tracks have been restitued");
if (metadatas.textTracks.length === 3) {
// Don't execute next tests if length is bad!
expect(metadatas.textTracks[0].enabled).to.equals(true, "Check enabled field for the first text track");
expect(metadatas.textTracks[0].label).to.equals("English", "Check label field for the first text track");
expect(metadatas.textTracks[0].language).to.equals("en",
"Check language field for the first text track");

expect(metadatas.textTracks[1].enabled).to.equals(false, "Check enabled field for the second text track");
expect(metadatas.textTracks[1].label).to.equals("", "Check label field for the second text track");
expect(metadatas.textTracks[1].language).to.equals("fr",
"Check language field for the second text track");

expect(metadatas.textTracks[2].enabled).to.equals(false, "Check enabled field for the third text track");
expect(metadatas.textTracks[2].label).to.equals("", "Check label field for the third text track");
expect(metadatas.textTracks[2].language).to.equals("",
"Check language field for the third text track");
}
});
});

0 comments on commit 54e719f

Please sign in to comment.