-
Notifications
You must be signed in to change notification settings - Fork 443
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c57874e
commit a39e07b
Showing
5 changed files
with
266 additions
and
171 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { callMethod, getter, InstanceIdKey, setter, WinIdKey, WorkerProxy } from './bridge'; | ||
import { CallType } from '../../types'; | ||
import { defineCstr } from './utils'; | ||
import { SourceBuffer } from './source-buffer'; | ||
|
||
export const AudioTrackList = class { | ||
constructor(mediaElm: any) { | ||
const audioTracks = 'audioTracks'; | ||
const winId = mediaElm[WinIdKey]; | ||
const instanceId = mediaElm[InstanceIdKey]; | ||
|
||
const instance = { | ||
addEventListener(...args: any[]) { | ||
callMethod( | ||
mediaElm, | ||
[audioTracks, 'addEventListener'], | ||
args, | ||
CallType.NonBlockingNoSideEffect | ||
); | ||
}, | ||
getTrackById(...args: any[]) { | ||
return callMethod(mediaElm, [audioTracks, 'getTrackById'], args); | ||
}, | ||
get length(): number { | ||
return getter(mediaElm, [audioTracks, 'length']); | ||
}, | ||
removeEventListener(...args: any[]) { | ||
callMethod( | ||
mediaElm, | ||
[audioTracks, 'removeEventListener'], | ||
args, | ||
CallType.NonBlockingNoSideEffect | ||
); | ||
}, | ||
}; | ||
|
||
return new Proxy(instance, { | ||
get(target: any, propName) { | ||
if (typeof propName === 'number') { | ||
return new AudioTrack(winId, instanceId, [audioTracks, propName]); | ||
} | ||
return target[propName]; | ||
}, | ||
}) as any; | ||
} | ||
}; | ||
|
||
const AudioTrack = class extends WorkerProxy { | ||
get enabled() { | ||
return getter(this, ['enabled']); | ||
} | ||
set enabled(value: any) { | ||
setter(this, ['enabled'], value); | ||
} | ||
|
||
get id() { | ||
return getter(this, ['id']); | ||
} | ||
|
||
get kind() { | ||
return getter(this, ['kind']); | ||
} | ||
|
||
get label() { | ||
return getter(this, ['label']); | ||
} | ||
|
||
get language() { | ||
return getter(this, ['language']); | ||
} | ||
|
||
get sourceBuffer() { | ||
return new SourceBuffer(this); | ||
} | ||
}; | ||
|
||
export const hasAudioTracks = 'audioTracks' in (self.HTMLMediaElement.prototype as any); | ||
if (hasAudioTracks) { | ||
// not all browsers have audioTracks, only add if it's found | ||
defineCstr('AudioTrackList', AudioTrackList); | ||
defineCstr('AudioTrack', AudioTrack); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.