Skip to content
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

[WIP] initial bringup for casting #37

Open
wants to merge 51 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
f479a63
[WIP] initial bringup for casting
afkcodes Jun 2, 2024
b6b48cd
Merge branch 'dev' of https://github.com/afkcodes/audio_x into featur…
afkcodes Jun 2, 2024
5779c22
added sessionrequest, remoteplayer,controller and other updates
afkcodes Jun 2, 2024
a0df64c
device selection and connection setup
afkcodes Jun 3, 2024
a43f1dd
finetuned eq presets and updates hls source
afkcodes Jun 17, 2024
f370c87
Merge pull request #40 from afkcodes/feature/eq-finetune
afkcodes Jun 17, 2024
5d4d146
Merge pull request #41 from afkcodes/dev
afkcodes Jun 17, 2024
2e87317
v1.0.8
afkcodes Jun 17, 2024
bee0511
Merge pull request #42 from afkcodes/v1.0.8
afkcodes Jun 17, 2024
5f5b4d4
Merge pull request #43 from afkcodes/dev
afkcodes Jun 17, 2024
40b36c4
mediaSession next and previous handler and queue updates
afkcodes Jun 21, 2024
01bdc7a
update README
afkcodes Jun 21, 2024
a521342
minor behaviour change in support of audio_x for seeking (retain stat…
afkcodes Jun 21, 2024
67b8e38
bufferedDuration is now fixed
afkcodes Jun 21, 2024
6f100f4
Merge pull request #44 from afkcodes/feature/queue-seek-updates
afkcodes Jun 21, 2024
4d9cb76
v1.0.9
afkcodes Jun 21, 2024
144e610
Merge pull request #45 from afkcodes/feature/v1.0.9
afkcodes Jun 21, 2024
093aa3e
update readme
afkcodes Jun 22, 2024
e99e390
added bass boost and fixed distortion in playback
afkcodes Jul 30, 2024
a9c3fb5
fix currentIndex being incorrectly set
afkcodes Jul 30, 2024
d0e04d9
fix equalizer initialization
afkcodes Jul 31, 2024
03ed307
revert eq initialization and queue ended event
afkcodes Aug 1, 2024
90808c0
more fixes on eq initialization
afkcodes Aug 1, 2024
a804cf8
fix zeroth index for queue
afkcodes Aug 1, 2024
3c9913c
eq updates for clarity
afkcodes Aug 2, 2024
b7214f6
beta-13
afkcodes Aug 4, 2024
730eb30
handle native hls playback & fetchFn handling updates
afkcodes Sep 6, 2024
3c0c7da
update Readme
afkcodes Sep 6, 2024
9e3af64
Merge pull request #48 from afkcodes/feature/eq-config-updates
afkcodes Sep 6, 2024
3fd226f
v1.0.10
afkcodes Sep 6, 2024
44d5ff0
Merge pull request #49 from afkcodes/feature/v1.0.10
afkcodes Sep 6, 2024
61843ea
intial work for shuffle and loop
Dec 14, 2024
1025a03
update dependencies
afkcodes Feb 10, 2025
9a6fb55
Merge pull request #50 from afkcodes/feature/package-updates
afkcodes Feb 10, 2025
a9888b3
even with dev
afkcodes Feb 10, 2025
88554f0
introduce looping, single and queue
afkcodes Feb 17, 2025
81042de
introduce shuffling of queue
afkcodes Feb 17, 2025
6cd4f59
update keywords and reset version
afkcodes Feb 17, 2025
770ac2b
update hls js version
afkcodes Feb 17, 2025
611a55b
Merge pull request #51 from afkcodes/feature/loop-and-shuffle
afkcodes Feb 17, 2025
3e82cea
update readme
afkcodes Feb 17, 2025
a88360b
Merge pull request #52 from afkcodes/feature/update-readme
afkcodes Feb 17, 2025
18b114d
v1.0.12
afkcodes Feb 17, 2025
c649fb0
Merge branch 'dev' of github.com:afkcodes/audio_x into dev
afkcodes Feb 17, 2025
426ab66
Merge pull request #53 from afkcodes/dev
afkcodes Feb 17, 2025
26cf5a7
update Readme
afkcodes Feb 21, 2025
58499f0
[WIP] initial bringup for casting
afkcodes Jun 2, 2024
25c55c7
added sessionrequest, remoteplayer,controller and other updates
afkcodes Jun 2, 2024
e0b0075
device selection and connection setup
afkcodes Jun 3, 2024
f0d0546
rebase with dev
afkcodes Feb 22, 2025
4ea013f
testing updates
afkcodes Feb 23, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions src/adapters/cast.ts
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;
21 changes: 21 additions & 0 deletions src/constants/cast.ts
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 };
3 changes: 2 additions & 1 deletion src/constants/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const ERROR_MSG_MAP: ErrorMessageMap = Object.freeze({
});

const URLS = {
HLS: 'https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js'
HLS: 'https://cdn.jsdelivr.net/npm/hls.js/dist/hls.min.js',
CAST: 'https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1'
};

export { AUDIO_X_CONSTANTS, ERROR_MSG_MAP, PLAYBACK_STATE, URLS };
46 changes: 46 additions & 0 deletions src/events/castEvents.ts
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 };
18 changes: 18 additions & 0 deletions src/states/castState.ts
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 };
8 changes: 8 additions & 0 deletions src/types/cast.types.ts
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 };