-
Notifications
You must be signed in to change notification settings - Fork 3
[WIP] initial bringup for casting #37
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
Open
afkcodes
wants to merge
12
commits into
dev
Choose a base branch
from
feature/casting-support
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
f479a63
[WIP] initial bringup for casting
afkcodes b6b48cd
Merge branch 'dev' of https://github.com/afkcodes/audio_x into featur…
afkcodes 5779c22
added sessionrequest, remoteplayer,controller and other updates
afkcodes a0df64c
device selection and connection setup
afkcodes 58499f0
[WIP] initial bringup for casting
afkcodes 25c55c7
added sessionrequest, remoteplayer,controller and other updates
afkcodes e0b0075
device selection and connection setup
afkcodes f0d0546
rebase with dev
afkcodes fcd67c4
Merge branch 'dev' of github.com:afkcodes/audio_x into feature/castin…
afkcodes 5381e40
chore: redo cast
afkcodes 4c72b8e
chore: fix next and previous when casting is active
afkcodes 5aae99b
chore: add types, and device name in audiostate
afkcodes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,102 @@ | ||
| declare global { | ||
| interface Window { | ||
| cast: any; | ||
| chrome: any; | ||
| } | ||
| } | ||
|
|
||
| import { CAST_JOIN_POLICY } from 'constants/cast'; | ||
| import { URLS } from 'constants/common'; | ||
| import { loadScript } from 'helpers/common'; | ||
|
|
||
| class CastAdapter { | ||
| private static _instance: CastAdapter; | ||
| private castContext: any; | ||
| private remotePlayer: any; | ||
| private remotePlayerController: any; | ||
| private castSession: any; | ||
|
|
||
| constructor() { | ||
| if (CastAdapter._instance) { | ||
| console.warn( | ||
| 'Instantiation failed: cannot create multiple instances of Cast framework returning existing instance' | ||
| ); | ||
| return CastAdapter._instance; | ||
| } | ||
| CastAdapter._instance = this; | ||
| } | ||
|
|
||
| async load() { | ||
| await loadScript( | ||
| URLS.CAST, | ||
| () => { | ||
| console.log('Cast framework Loaded'); | ||
| }, | ||
| 'cast' | ||
| ) | ||
| .then(() => { | ||
| this.castContext = window.cast.framework.CastContext.getInstance(); | ||
| }) | ||
| .catch((msg: string) => { | ||
| console.log(msg); | ||
| }); | ||
|
|
||
| return this.castContext; | ||
| } | ||
|
|
||
| async init( | ||
| receiverId: string = 'CC1AD845', | ||
| joinPolicy: keyof typeof CAST_JOIN_POLICY = 'ORIGIN_SCOPED' | ||
| ) { | ||
| const castContext = await this.load(); | ||
| if (castContext) { | ||
| castContext.setOptions({ | ||
| receiverApplicationId: receiverId, | ||
| autoJoinPolicy: CAST_JOIN_POLICY[joinPolicy] | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| castAudio() { | ||
| this.castContext.requestSession().then(() => { | ||
| if (!this.castContext.getCurrentSession()) { | ||
| throw new Error( | ||
| 'Failed to request Cast Session - Device Connection Failed' | ||
| ); | ||
| } else { | ||
| this.castSession = this.castContext.getCurrentSession(); | ||
| this.initializeRemotePlayer(); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| initializeRemotePlayer() { | ||
| this.remotePlayer = new window.cast.framework.RemotePlayer(); | ||
| this.remotePlayerController = | ||
| new window.cast.framework.RemotePlayerController(this.remotePlayer); | ||
| } | ||
|
|
||
| getRemotePlayer() { | ||
| if (this.castSession) { | ||
| return this.remotePlayer; | ||
| } else { | ||
| console.error('Failed to get remotePlayer - No Cast Session active'); | ||
| } | ||
| } | ||
|
|
||
| getRemotePlayerController() { | ||
| if (this.castSession) { | ||
| return this.remotePlayerController; | ||
| } else { | ||
| console.error( | ||
| 'Failed to get remotePlayerController - No Cast Session active' | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| getCastSession() { | ||
| return this.castSession ? this.castSession : undefined; | ||
| } | ||
| } | ||
|
|
||
| export default CastAdapter; | ||
This file contains hidden or 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,21 @@ | ||
| import { JoinPolicy } from 'types/cast.types'; | ||
|
|
||
| declare global { | ||
| interface Window { | ||
| cast: any; | ||
| chrome: any; | ||
| } | ||
| } | ||
|
|
||
| // ORIGIN_SCOPED - Auto connect from same appId and page origin | ||
| // TAB_AND_ORIGIN_SCOPED - Auto connect from same appId, page origin, and tab | ||
| // PAGE_SCOPED - No auto connect | ||
|
|
||
| const CAST_JOIN_POLICY: JoinPolicy = { | ||
| CUSTOM_CONTROLLER_SCOPED: 'custom_controller_scoped', | ||
| TAB_AND_ORIGIN_SCOPED: 'tab_and_origin_scoped', | ||
| ORIGIN_SCOPED: 'origin_scoped', | ||
| PAGE_SCOPED: 'page_scoped' | ||
| }; | ||
|
|
||
| export { CAST_JOIN_POLICY }; |
This file contains hidden or 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 hidden or 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,46 @@ | ||
| const CAST_REMOTE_PLAYER_EVENTS = { | ||
| ANY_CHANGE: 'anyChanged', | ||
| IS_CONNECTED_CHANGED: 'isConnectedChanged', | ||
| IS_MEDIA_LOADED_CHANGED: 'isMediaLoadedChanged', | ||
| QUEUE_DATA_CHANGED: 'queueDataChanged', | ||
| VIDEO_INFO_CHANGED: 'videoInfoChanged', | ||
| DURATION_CHANGED: 'durationChanged', | ||
| CURRENT_TIME_CHANGED: 'currentTimeChanged', | ||
| IS_PAUSED_CHANGED: 'isPausedChanged', | ||
| VOLUME_LEVEL_CHANGED: 'volumeLevelChanged', | ||
| CAN_CONTROL_VOLUME_CHANGED: 'canControlVolumeChanged', | ||
| IS_MUTED_CHANGED: 'isMutedChanged', | ||
| CAN_PAUSE_CHANGED: 'canPauseChanged', | ||
| CAN_SEEK_CHANGED: 'canSeekChanged', | ||
| DISPLAY_NAME_CHANGED: 'displayNameChanged', | ||
| STATUS_TEXT_CHANGED: 'statusTextChanged', | ||
| TITLE_CHANGED: 'titleChanged', | ||
| DISPLAY_STATUS_CHANGED: 'displayStatusChanged', | ||
| MEDIA_INFO_CHANGED: 'mediaInfoChanged', | ||
| IMAGE_URL_CHANGED: 'imageUrlChanged', | ||
| PLAYER_STATE_CHANGED: 'playerStateChanged', | ||
| IS_PLAYING_BREAK_CHANGED: 'isPlayingBreakChanged', | ||
| NUMBER_BREAK_CLIPS_CHANGED: 'numberBreakClipsChanged', | ||
| CURRENT_BREAK_CLIP_NUMBER_CHANGED: 'currentBreakClipNumberChanged', | ||
| CURRENT_BREAK_TIME_CHANGED: 'currentBreakTimeChanged', | ||
| CURRENT_BREAK_CLIP_TIME_CHANGED: 'currentBreakClipTimeChanged', | ||
| BREAK_ID_CHANGED: 'breakIdChanged', | ||
| BREAK_CLIP_ID_CHANGED: 'breakClipIdChanged', | ||
| WHEN_SKIPPABLE_CHANGED: 'whenSkippableChanged', | ||
| LIVE_SEEKABLE_RANGE_CHANGED: 'liveSeekableRangeChanged' | ||
| }; | ||
|
|
||
| const CAST_SESSION_EVENTS = { | ||
| APPLICATION_STATUS_CHANGED: 'applicationstatuschanged', | ||
| APPLICATION_METADATA_CHANGED: 'applicationmetadatachanged', | ||
| ACTIVE_INPUT_STATE_CHANGED: 'activeinputstatechanged', | ||
| VOLUME_CHANGED: 'volumechanged', | ||
| MEDIA_SESSION: 'mediasession' | ||
| }; | ||
|
|
||
| const CAST_CONTEXT_STATE = { | ||
| CAST_STATE_CHANGED: 'caststatechanged', | ||
| SESSION_STATE_CHANGED: 'sessionstatechanged' | ||
| }; | ||
|
|
||
| export { CAST_CONTEXT_STATE, CAST_REMOTE_PLAYER_EVENTS, CAST_SESSION_EVENTS }; |
This file contains hidden or 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,18 @@ | ||
| const CAST_SESSION_STATE = { | ||
| NO_SESSION: 'NO_SESSION', | ||
| SESSION_STARTING: 'SESSION_STARTING', | ||
| SESSION_STARTED: 'SESSION_STARTED', | ||
| SESSION_START_FAILED: 'SESSION_START_FAILED', | ||
| SESSION_ENDING: 'SESSION_ENDING', | ||
| SESSION_ENDED: 'SESSION_ENDED', | ||
| SESSION_RESUMED: 'SESSION_RESUMED' | ||
| }; | ||
|
|
||
| const CAST_DEVICE_STATE = { | ||
| NO_DEVICES_AVAILABLE: 'NO_DEVICES_AVAILABLE', | ||
| NOT_CONNECTED: 'NOT_CONNECTED', | ||
| CONNECTING: 'CONNECTING', | ||
| CONNECTED: 'CONNECTED' | ||
| }; | ||
|
|
||
| export { CAST_DEVICE_STATE, CAST_SESSION_STATE }; |
This file contains hidden or 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,8 @@ | ||
| interface JoinPolicy { | ||
| ORIGIN_SCOPED: string; | ||
| TAB_AND_ORIGIN_SCOPED: string; | ||
| PAGE_SCOPED: string; | ||
| CUSTOM_CONTROLLER_SCOPED: string; | ||
| } | ||
|
|
||
| export { JoinPolicy }; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.