diff --git a/package.json b/package.json index 281ee1d..742b576 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "homepage": "https://community.comma.ai/cabana", "dependencies": { "@commaai/comma-api": "1.1.6", + "@commaai/hls.js": "^0.12.5", "@commaai/log_reader": "^0.5.3", "@commaai/my-comma-auth": "^1.1.0", "@commaai/pandajs": "^0.3.4", @@ -34,7 +35,6 @@ "github-api": "^3.0.0", "global": "^4.3.2", "hls": "0.0.1", - "hls.js": "0.12.3-canary.4258", "husky": "^0.14.3", "int64-buffer": "^0.1.9", "js-cookie": "^2.1.4", diff --git a/src/__tests__/components/CanExplorer.test.js b/src/__tests__/components/CanExplorer.test.js index 569b015..8db5a54 100644 --- a/src/__tests__/components/CanExplorer.test.js +++ b/src/__tests__/components/CanExplorer.test.js @@ -9,7 +9,7 @@ import AcuraDbc from '../../acura-dbc'; jest.mock('aphrodite/lib/inject'); jest.mock('../../components/HLS.js'); -jest.mock('hls.js'); +jest.mock('@commaai/hls.js'); global.document.querySelector = jest.fn(); diff --git a/src/__tests__/components/HLS.test.js b/src/__tests__/components/HLS.test.js index 114d920..0c888a6 100644 --- a/src/__tests__/components/HLS.test.js +++ b/src/__tests__/components/HLS.test.js @@ -1,6 +1,33 @@ +/* eslint-env jest */ import React from 'react'; import { shallow, mount, render } from 'enzyme'; import HLS from '../../components/HLS'; +import HLSMock from '@commaai/hls.js'; + +jest.mock('@commaai/hls.js', () => { + const onMock = jest.fn(); + const destroyMock = jest.fn(); + const module = jest.fn().mockImplementation(() => ({ + on: onMock, + destroy: destroyMock, + })); + + module.onMock = onMock; + module.destroyMock = destroyMock; + + return module; +}); + +HLSMock.Events = { + MANIFEST_PARSED: 0, + BUFFER_APPENDED: 1 +}; + +beforeEach(() => { + HLSMock.mockClear(); + HLSMock.onMock.mockClear(); + HLSMock.destroyMock.mockClear(); +}); test('HLS successfully mounts with minimal default props', () => { const component = shallow( @@ -21,4 +48,8 @@ test('HLS successfully mounts with minimal default props', () => { /> ); expect(component.exists()).toBe(true); + expect(HLSMock).toBeCalledWith({ + enableWorker: false, + disablePtsDtsCorrectionInMp4Remux: true + }); }); diff --git a/src/components/HLS.js b/src/components/HLS.js index ab92633..0303170 100644 --- a/src/components/HLS.js +++ b/src/components/HLS.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import Hls from 'hls.js'; +import Hls from '@commaai/hls.js'; export default class HLS extends Component { static propTypes = { @@ -36,6 +36,14 @@ export default class HLS extends Component { } } + componentDidMount() { + this.player = new Hls({ + enableWorker: false, + disablePtsDtsCorrectionInMp4Remux: true + }); + this.loadSource(); + } + onSeeking = () => { if (!this.props.playing) { this.props.onLoadStart(); @@ -57,11 +65,6 @@ export default class HLS extends Component { } }; - componentDidMount() { - this.player = new Hls({ disablePtsDtsCorrectionInMp4Remux: true }); - this.loadSource(); - } - loadSource(source = this.props.source) { if (this.videoElement) { this.player.loadSource(source); diff --git a/yarn.lock b/yarn.lock index 32c27ca..cf30572 100644 --- a/yarn.lock +++ b/yarn.lock @@ -938,6 +938,14 @@ joi-browser "^13.4.0" querystringify "^2.1.1" +"@commaai/hls.js@^0.12.5": + version "0.12.5" + resolved "https://registry.yarnpkg.com/@commaai/hls.js/-/hls.js-0.12.5.tgz#891e47124b4e9e2a1528463613bf415ff252d2ec" + integrity sha512-aZcwFrhHSGVpi76cHMjT1wQ6Pe0AVv3s0TdzNGFA6LpCb6WCFy2EF9H8QCtNlAviccYnAw4XQrJ+hHToUp4QnA== + dependencies: + eventemitter3 "3.1.0" + url-toolkit "^2.1.6" + "@commaai/log_reader@^0.5.3": version "0.5.3" resolved "https://registry.yarnpkg.com/@commaai/log_reader/-/log_reader-0.5.3.tgz#c3dd2c6f3b911198c32bbebd34d0e9cc862e0672" @@ -6031,14 +6039,6 @@ hex-color-regex@^1.1.0: resolved "https://registry.yarnpkg.com/hex-color-regex/-/hex-color-regex-1.1.0.tgz#4c06fccb4602fe2602b3c93df82d7e7dbf1a8a8e" integrity sha512-l9sfDFsuqtOqKDsQdqrMRk0U85RZc0RtOR9yPI7mRVOa4FsR/BVnZ0shmQRM96Ji99kYZP/7hn1cedc1+ApsTQ== -hls.js@0.12.3-canary.4258: - version "0.12.3-canary.4258" - resolved "https://registry.yarnpkg.com/hls.js/-/hls.js-0.12.3-canary.4258.tgz#9ef7e89a85609222497512b9baed806712246901" - integrity sha512-uSNt4fDVNb5rMpgMGjFvVaIqWwwRnIFiCrTY2zHCIQbaKgw8DOhA3QC5ImYdv8nXiZod5LS69dYxjnj/u8+3nw== - dependencies: - eventemitter3 "3.1.0" - url-toolkit "^2.1.6" - hls@0.0.1: version "0.0.1" resolved "https://registry.yarnpkg.com/hls/-/hls-0.0.1.tgz#3433be0d4b1305db312c966527fbb156e7ed79ca"