Skip to content

Commit

Permalink
Merge pull request #190 from hawken93/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
YouKnowBlom authored Jul 27, 2021
2 parents cd8d077 + e92b94a commit 4790694
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 127 deletions.
12 changes: 0 additions & 12 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,6 @@ import './components/maincontroller';
import './css/glyphicons.css';
import './css/jellyfin.css';

const senders = cast.framework.CastReceiverContext.getInstance().getSenders();
const id =
senders.length !== 0 && senders[0].id
? senders[0].id
: new Date().getTime();

window.deviceInfo = {
deviceId: id,
deviceName: 'Google Cast',
versionNumber: RECEIVERVERSION
};

window.mediaElement = document.getElementById('video-player');

window.playlist = [];
Expand Down
19 changes: 14 additions & 5 deletions src/components/jellyfinActions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
getSenderReportingData,
resetPlaybackScope,
extend,
broadcastToMessageBus
} from '../helpers';

Expand Down Expand Up @@ -199,12 +198,22 @@ export function pingTranscoder(
*/
export function load(
$scope: GlobalScope,
customData: PlaybackProgressInfo,
customData: any,
serverItem: BaseItemDto
): void {
resetPlaybackScope($scope);

extend($scope, customData);
// These are set up in maincontroller.createMediaInformation
$scope.playSessionId = customData.playSessionId;
$scope.audioStreamIndex = customData.audioStreamIndex;
$scope.subtitleStreamIndex = customData.subtitleStreamIndex;
$scope.startPositionTicks = customData.startPositionTicks;
$scope.canSeek = customData.canSeek;
$scope.itemId = customData.itemId;
$scope.liveStreamId = customData.liveStreamId;
$scope.mediaSourceId = customData.mediaSourceId;
$scope.playMethod = customData.playMethod;
$scope.runtimeTicks = customData.runtimeTicks;

$scope.item = serverItem;

Expand All @@ -230,7 +239,7 @@ export function play($scope: GlobalScope): void {
DocumentManager.getAppStatus() == 'audio'
) {
setTimeout(() => {
window.mediaManager.play();
window.playerManager.play();

if ($scope.mediaType == 'Audio') {
DocumentManager.setAppStatus('audio');
Expand Down Expand Up @@ -409,7 +418,7 @@ export async function detectBitrate(): Promise<number> {
*/
export function stopActiveEncodings($scope: GlobalScope): Promise<void> {
const options = {
deviceId: window.deviceInfo.deviceId,
deviceId: JellyfinApi.deviceId,
PlaySessionId: undefined
};

Expand Down
39 changes: 33 additions & 6 deletions src/components/jellyfinApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,55 @@ export abstract class JellyfinApi {
// Address of server
public static serverAddress: string | null = null;

// device name
public static deviceName = 'Google Cast';

// unique id
public static deviceId = '';

// version
public static versionNumber = RECEIVERVERSION;

public static setServerInfo(
userId: string,
accessToken: string,
serverAddress: string
serverAddress: string,
receiverName = ''
): void {
console.debug(
`JellyfinApi.setServerInfo: user:${userId}, token:${accessToken}, server:${serverAddress}`
`JellyfinApi.setServerInfo: user:${userId}, token:${accessToken}, ` +
`server:${serverAddress}, name:${receiverName}`
);
this.userId = userId;
this.accessToken = accessToken;
this.serverAddress = serverAddress;

// remove special characters from the receiver name
receiverName = receiverName.replace(/[^\w\s]/gi, '');

if (receiverName) {
this.deviceName = receiverName;
// deviceId just needs to be unique-ish
this.deviceId = btoa(receiverName);
} else {
const senders =
cast.framework.CastReceiverContext.getInstance().getSenders();

this.deviceName = 'Google Cast';
this.deviceId =
senders.length !== 0 && senders[0].id
? senders[0].id
: new Date().getTime().toString();
}
}

// create the necessary headers for authentication
private static getSecurityHeaders(): Dictionary<string> {
// TODO throw error if this fails

let auth =
`Emby Client="Chromecast", ` +
`Device="${window.deviceInfo.deviceName}", ` +
`DeviceId="${window.deviceInfo.deviceId}", ` +
`Version="${window.deviceInfo.versionNumber}"`;
`Jellyfin Client="Chromecast", Device="${this.deviceName}", ` +
`DeviceId="${this.deviceId}", Version="${this.versionNumber}"`;

if (this.userId) {
auth += `, UserId="${this.userId}"`;
Expand Down
Loading

0 comments on commit 4790694

Please sign in to comment.