mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 01:59:58 +00:00
Switch to eslint and fix issues
This commit is contained in:
@@ -26,7 +26,7 @@ export class AirPlayAuthCredentials {
|
||||
public clientSk: Uint8Array;
|
||||
public clientPk: Uint8Array;
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
clientId?: string
|
||||
, clientSk?: Uint8Array
|
||||
, clientPk?: Uint8Array) {
|
||||
@@ -53,7 +53,7 @@ export class AirPlayAuth {
|
||||
private credentials: AirPlayAuthCredentials;
|
||||
private baseUrl: URL;
|
||||
|
||||
constructor (address: string, credentials: AirPlayAuthCredentials) {
|
||||
constructor(address: string, credentials: AirPlayAuthCredentials) {
|
||||
this.address = address;
|
||||
this.credentials = credentials;
|
||||
|
||||
@@ -63,7 +63,7 @@ export class AirPlayAuth {
|
||||
/**
|
||||
* Begins pairing process.
|
||||
*/
|
||||
public async beginPairing () {
|
||||
public async beginPairing() {
|
||||
return this.sendPostRequest("/pair-pin-start");
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ export class AirPlayAuth {
|
||||
* beginPairing(). Coordinates the three pairing stages and
|
||||
* manages request responses.
|
||||
*/
|
||||
public async finishPairing (pin: string) {
|
||||
public async finishPairing(pin: string) {
|
||||
// Stage 1 response
|
||||
const { pk: serverPk
|
||||
, salt: serverSalt } = await this.pairSetupPin1();
|
||||
@@ -107,7 +107,7 @@ export class AirPlayAuth {
|
||||
* Triggering the receiver passcode display and receiving
|
||||
* its public key / salt.
|
||||
*/
|
||||
public async pairSetupPin1 (): Promise<any> {
|
||||
public async pairSetupPin1(): Promise<any> {
|
||||
const [ response ] = await this.sendPostRequestBplist(
|
||||
"/pair-setup-pin"
|
||||
, {
|
||||
@@ -125,7 +125,7 @@ export class AirPlayAuth {
|
||||
* public keys, sending them to the receiver and receiving its
|
||||
* proof.
|
||||
*/
|
||||
public async pairSetupPin2 (
|
||||
public async pairSetupPin2(
|
||||
pk: Buffer
|
||||
, proof: Buffer): Promise<any> {
|
||||
|
||||
@@ -143,7 +143,7 @@ export class AirPlayAuth {
|
||||
* secret hash and sending it to the receiver. Receiver then
|
||||
* responds confirming the pairing is complete.
|
||||
*/
|
||||
public async pairSetupPin3 (
|
||||
public async pairSetupPin3(
|
||||
sharedSecretHash: crypto.BinaryLike): Promise<any> {
|
||||
|
||||
// Create AES key
|
||||
@@ -182,7 +182,7 @@ export class AirPlayAuth {
|
||||
* Sends a POST request to receiver and returns the
|
||||
* response.
|
||||
*/
|
||||
public async sendPostRequest (
|
||||
public async sendPostRequest(
|
||||
path: string
|
||||
, contentType?: string
|
||||
, data?: Buffer | string): Promise<any> {
|
||||
@@ -216,7 +216,7 @@ export class AirPlayAuth {
|
||||
* Encodes binary plist data, sends a POST request to
|
||||
* receiver, then decodes and returns the response.
|
||||
*/
|
||||
public async sendPostRequestBplist (
|
||||
public async sendPostRequestBplist(
|
||||
path: string
|
||||
, data?: object): Promise<any> {
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import castv2 from "castv2";
|
||||
import Session from "./Session";
|
||||
|
||||
import { Message } from "../../messaging";
|
||||
import { sendMessage } from "../../lib/nativeMessaging"
|
||||
import { sendMessage } from "../../lib/nativeMessaging";
|
||||
|
||||
|
||||
const NS_MEDIA = "urn:x-cast:com.google.cast.media";
|
||||
@@ -27,7 +27,7 @@ export interface UpdateMessageData {
|
||||
export default class Media {
|
||||
private channel: castv2.Channel;
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
private referenceId: string
|
||||
, private session: Session) {
|
||||
|
||||
@@ -67,7 +67,7 @@ export default class Media {
|
||||
});
|
||||
}
|
||||
|
||||
public messageHandler (message: Message) {
|
||||
public messageHandler(message: Message) {
|
||||
switch (message.subject) {
|
||||
case "bridge:media/sendMediaMessage": {
|
||||
let error = false;
|
||||
@@ -87,7 +87,7 @@ export default class Media {
|
||||
}
|
||||
}
|
||||
|
||||
private sendMessage (subject: string, data: any) {
|
||||
private sendMessage(subject: string, data: any) {
|
||||
data._id = this.referenceId;
|
||||
(sendMessage as any)({
|
||||
subject
|
||||
|
||||
@@ -26,7 +26,7 @@ export default class Session {
|
||||
private transportConnection?: Channel;
|
||||
private app: any;
|
||||
|
||||
constructor (
|
||||
constructor(
|
||||
public host: string
|
||||
, public port: number
|
||||
, private appId: string
|
||||
@@ -46,7 +46,7 @@ export default class Session {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
private onConnect () {
|
||||
private onConnect() {
|
||||
let transportHeartbeat: Channel;
|
||||
|
||||
const sourceId = "sender-0";
|
||||
@@ -67,7 +67,7 @@ export default class Session {
|
||||
transportHeartbeat.send({ type: "PING" });
|
||||
}
|
||||
|
||||
this.clientHeartbeat!.send({ type: "PING" });
|
||||
this.clientHeartbeat?.send({ type: "PING" });
|
||||
}, 5000);
|
||||
|
||||
this.clientReceiver.send({
|
||||
@@ -124,7 +124,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
public messageHandler (message: Message) {
|
||||
public messageHandler(message: Message) {
|
||||
switch (message.subject) {
|
||||
case "bridge:session/close":
|
||||
this.close();
|
||||
@@ -159,7 +159,7 @@ export default class Session {
|
||||
}
|
||||
}
|
||||
|
||||
public createChannel (namespace: string) {
|
||||
public createChannel(namespace: string) {
|
||||
if (!this.channelMap.has(namespace)) {
|
||||
this.channelMap.set(namespace, this.client.createChannel(
|
||||
this.clientId!, this.transportId!
|
||||
@@ -167,16 +167,16 @@ export default class Session {
|
||||
}
|
||||
}
|
||||
|
||||
public close () {
|
||||
public close() {
|
||||
this.clientConnection?.send({ type: "CLOSE" });
|
||||
this.transportConnection?.send({ type: "CLOSE" });
|
||||
}
|
||||
|
||||
public stop () {
|
||||
public stop() {
|
||||
this.clientConnection?.send({ type: "STOP" });
|
||||
}
|
||||
|
||||
private sendMessage (subject: string, data: any = {}) {
|
||||
private sendMessage(subject: string, data: any = {}) {
|
||||
data._id = this.referenceId;
|
||||
sendMessage({
|
||||
// @ts-ignore
|
||||
@@ -185,7 +185,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
private _impl_addMessageListener (namespace: string) {
|
||||
private _impl_addMessageListener(namespace: string) {
|
||||
this.createChannel(namespace);
|
||||
this.channelMap.get(namespace)?.on("message", (data: any) => {
|
||||
this.sendMessage("shim:session/impl_addMessageListener", {
|
||||
@@ -195,7 +195,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
private _impl_sendMessage (
|
||||
private _impl_sendMessage(
|
||||
namespace: string
|
||||
, message: {} | string
|
||||
, messageId: string) {
|
||||
@@ -220,7 +220,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
private _impl_setReceiverMuted (muted: boolean, volumeId: string) {
|
||||
private _impl_setReceiverMuted(muted: boolean, volumeId: string) {
|
||||
|
||||
let error = false;
|
||||
|
||||
@@ -240,7 +240,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
private _impl_setReceiverVolumeLevel (newLevel: number, volumeId: string) {
|
||||
private _impl_setReceiverVolumeLevel(newLevel: number, volumeId: string) {
|
||||
|
||||
let error = false;
|
||||
|
||||
@@ -260,7 +260,7 @@ export default class Session {
|
||||
});
|
||||
}
|
||||
|
||||
private _impl_stop (stopId: string) {
|
||||
private _impl_stop(stopId: string) {
|
||||
let error = false;
|
||||
|
||||
try {
|
||||
|
||||
@@ -17,7 +17,7 @@ export default class StatusListener extends EventEmitter {
|
||||
private clientReceiver?: Channel;
|
||||
private clientHeartbeatIntervalId?: NodeJS.Timeout;
|
||||
|
||||
constructor (host: string, port: number) {
|
||||
constructor(host: string, port: number) {
|
||||
super();
|
||||
|
||||
this.client = new Client();
|
||||
@@ -35,7 +35,7 @@ export default class StatusListener extends EventEmitter {
|
||||
/**
|
||||
* Closes status listener connection.
|
||||
*/
|
||||
public deregister (): void {
|
||||
public deregister(): void {
|
||||
if (this.clientReceiver) {
|
||||
this.clientReceiver.send({ type: "CLOSE" });
|
||||
}
|
||||
@@ -44,7 +44,7 @@ export default class StatusListener extends EventEmitter {
|
||||
}
|
||||
|
||||
|
||||
private onConnect (): void {
|
||||
private onConnect(): void {
|
||||
const sourceId = "sender-0";
|
||||
const destinationId = "receiver-0";
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { Receiver } from "../../types";
|
||||
const existingSessions: Map<string, Session> = new Map();
|
||||
const existingMedia: Map<string, Media> = new Map();
|
||||
|
||||
export function handleSessionMessage (message: any) {
|
||||
export function handleSessionMessage(message: any) {
|
||||
if (!message.data._id) {
|
||||
console.error("Session message missing _id");
|
||||
return;
|
||||
@@ -34,7 +34,7 @@ export function handleSessionMessage (message: any) {
|
||||
}
|
||||
}
|
||||
|
||||
export function handleMediaMessage (message: any) {
|
||||
export function handleMediaMessage(message: any) {
|
||||
if (!message.data._id) {
|
||||
console.error("Media message missing _id");
|
||||
return;
|
||||
@@ -44,7 +44,7 @@ export function handleMediaMessage (message: any) {
|
||||
|
||||
if (existingMedia.has(mediaId)) {
|
||||
// Forward message to instance message handler
|
||||
existingMedia.get(mediaId)!.messageHandler(message);
|
||||
existingMedia.get(mediaId)?.messageHandler(message);
|
||||
} else {
|
||||
if (message.subject === "bridge:media/initialize") {
|
||||
// Get Session object media belongs to
|
||||
@@ -61,7 +61,7 @@ export function handleMediaMessage (message: any) {
|
||||
}
|
||||
}
|
||||
|
||||
export function stopReceiverApp (host: string, port: number) {
|
||||
export function stopReceiverApp(host: string, port: number) {
|
||||
const client = new castv2.Client();
|
||||
|
||||
client.connect({ host, port }, () => {
|
||||
|
||||
@@ -25,7 +25,7 @@ const browser = mdns.createBrowser(mdns.tcp("googlecast"), {
|
||||
]
|
||||
});
|
||||
|
||||
function onBrowserServiceUp (service: mdns.Service) {
|
||||
function onBrowserServiceUp(service: mdns.Service) {
|
||||
// Ignore without txt record
|
||||
if (!service.txtRecord) {
|
||||
return;
|
||||
@@ -44,7 +44,7 @@ function onBrowserServiceUp (service: mdns.Service) {
|
||||
});
|
||||
}
|
||||
|
||||
function onBrowserServiceDown (_service: mdns.Service) {
|
||||
function onBrowserServiceDown(_service: mdns.Service) {
|
||||
// TODO: Fix service down detection
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ interface InitializeOptions {
|
||||
shouldWatchStatus?: boolean;
|
||||
}
|
||||
|
||||
export function startDiscovery (options: InitializeOptions) {
|
||||
export function startDiscovery(options: InitializeOptions) {
|
||||
if (options.shouldWatchStatus) {
|
||||
browser.on("serviceUp", onStatusBrowserServiceUp);
|
||||
browser.on("serviceDown", onStatusBrowserServiceDown);
|
||||
@@ -67,7 +67,7 @@ export function startDiscovery (options: InitializeOptions) {
|
||||
// Receiver status listeners for status mode
|
||||
const statusListeners = new Map<string, StatusListener>();
|
||||
|
||||
function onStatusBrowserServiceUp (service: mdns.Service) {
|
||||
function onStatusBrowserServiceUp(service: mdns.Service) {
|
||||
if (!service.txtRecord) {
|
||||
return;
|
||||
}
|
||||
@@ -109,11 +109,11 @@ export function startDiscovery (options: InitializeOptions) {
|
||||
statusListeners.set(id, listener);
|
||||
}
|
||||
|
||||
function onStatusBrowserServiceDown (_service: mdns.Service) {
|
||||
function onStatusBrowserServiceDown(_service: mdns.Service) {
|
||||
// TODO: Fix service down detection
|
||||
}
|
||||
}
|
||||
|
||||
export function stopDiscovery () {
|
||||
export function stopDiscovery() {
|
||||
browser.stop();
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ import { convertSrtToVtt } from "../lib/subtitles";
|
||||
|
||||
export let mediaServer: http.Server | undefined;
|
||||
|
||||
export async function startMediaServer (filePath: string, port: number) {
|
||||
export async function startMediaServer(filePath: string, port: number) {
|
||||
if (mediaServer?.listening) {
|
||||
await stopMediaServer();
|
||||
stopMediaServer();
|
||||
}
|
||||
|
||||
let fileDir: string;
|
||||
@@ -74,7 +74,9 @@ export async function startMediaServer (filePath: string, port: number) {
|
||||
path.join(fileDir, dirEntry.name)));
|
||||
}
|
||||
}
|
||||
} catch (err) {}
|
||||
} catch (err) {
|
||||
// TODO: Handle?
|
||||
}
|
||||
|
||||
mediaServer = http.createServer(async (req, res) => {
|
||||
if (!req.url) {
|
||||
@@ -172,7 +174,7 @@ export async function startMediaServer (filePath: string, port: number) {
|
||||
mediaServer.listen(port);
|
||||
}
|
||||
|
||||
export function stopMediaServer () {
|
||||
export function stopMediaServer() {
|
||||
if (mediaServer?.listening) {
|
||||
mediaServer.close();
|
||||
mediaServer = undefined;
|
||||
|
||||
@@ -6,7 +6,7 @@ import path from "path";
|
||||
import { sendMessage } from "../lib/nativeMessaging";
|
||||
|
||||
|
||||
function fatal (message: string) {
|
||||
function fatal(message: string) {
|
||||
console.error(message);
|
||||
process.exit(1);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ function fatal (message: string) {
|
||||
let selectorApp: child_process.ChildProcess | undefined;
|
||||
let selectorAppOpen = false;
|
||||
|
||||
export function startReceiverSelector (data: string) {
|
||||
export function startReceiverSelector(data: string) {
|
||||
if (process.platform !== "darwin") {
|
||||
fatal("Invalid platform for native receiver selector.");
|
||||
}
|
||||
@@ -80,7 +80,7 @@ export function startReceiverSelector (data: string) {
|
||||
});
|
||||
}
|
||||
|
||||
export function stopReceiverSelector () {
|
||||
export function stopReceiverSelector() {
|
||||
if (!selectorApp?.killed) {
|
||||
selectorApp?.kill();
|
||||
selectorAppOpen = false;
|
||||
|
||||
Reference in New Issue
Block a user