Skip to content

Commit

Permalink
lint: Add eslint and fix results
Browse files Browse the repository at this point in the history
  • Loading branch information
bekriebel committed Aug 24, 2021
1 parent 88c92c5 commit c3f3a2b
Show file tree
Hide file tree
Showing 8 changed files with 727 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# don't ever lint node_modules
node_modules
# don't lint build output (make sure it's set to your correct build folder name)
dist
# don't lint nyc coverage output
coverage
7 changes: 7 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// eslint-disable-next-line no-undef
module.exports = {
root: true,
parser: "@typescript-eslint/parser",
plugins: ["@typescript-eslint"],
extends: ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
};
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
},
"devDependencies": {
"@league-of-foundry-developers/foundry-vtt-types": "^0.8.9-2",
"@typescript-eslint/eslint-plugin": "^4.29.3",
"@typescript-eslint/parser": "^4.29.3",
"buffer": "^6.0.3",
"copy-webpack-plugin": "^9.0.1",
"crypto-browserify": "^3.12.0",
"eslint": "^7.32.0",
"process": "^0.11.10",
"source-map-loader": "^3.0.0",
"stream-browserify": "^3.0.0",
Expand Down
72 changes: 39 additions & 33 deletions src/LiveKitClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default class LiveKitClient {
/* LiveKit Internal methods */
/* -------------------------------------------- */

addAllParticipants() {
addAllParticipants(): void {
if (!this.liveKitRoom) {
log.warn(
"Attempting to add participants before the LiveKit room is available"
Expand All @@ -72,7 +72,7 @@ export default class LiveKitClient {
});
}

addConnectionButtons(element: JQuery<HTMLElement>) {
addConnectionButtons(element: JQuery<HTMLElement>): void {
if (element.length !== 1) {
log.warn("Can't find CameraView configure element", element);
return;
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class LiveKitClient {
}
}

addStatusIndicators(userId: string) {
addStatusIndicators(userId: string): void {
// Get the user camera view and notification bar
const userCameraView = ui.webrtc?.getUserCameraView(userId);
const userNotificationBar =
Expand Down Expand Up @@ -156,7 +156,7 @@ export default class LiveKitClient {
userId: string,
userAudioTrack: RemoteAudioTrack,
audioElement: HTMLAudioElement
) {
): Promise<void> {
if (userAudioTrack.attachedElements.includes(audioElement)) {
log.debug(
"Audio track",
Expand Down Expand Up @@ -195,7 +195,10 @@ export default class LiveKitClient {
audioElement.muted = this.settings.get("client", "muteAll") === true;
}

attachVideoTrack(userVideoTrack: VideoTrack, videoElement: HTMLVideoElement) {
attachVideoTrack(
userVideoTrack: VideoTrack,
videoElement: HTMLVideoElement
): void {
if (userVideoTrack.attachedElements.includes(videoElement)) {
log.debug(
"Video track",
Expand All @@ -214,7 +217,7 @@ export default class LiveKitClient {
userVideoTrack.attach(videoElement);
}

async changeAudioSource() {
async changeAudioSource(): Promise<void> {
if (
!this.audioTrack ||
this.settings.get("client", "audioSrc") === "disabled"
Expand All @@ -239,7 +242,7 @@ export default class LiveKitClient {
}
}

async changeVideoSource() {
async changeVideoSource(): Promise<void> {
if (
!this.videoTrack ||
this.settings.get("client", "videoSrc") === "disabled"
Expand Down Expand Up @@ -338,7 +341,7 @@ export default class LiveKitClient {
* If the element doesn't exist, but a video element does, it will create it.
* @param {string} userId The ID of the User entity
* @param {HTMLVideoElement} videoElement The HTMLVideoElement of the user
* @return {HTMLVideoElement|null}
* @return {HTMLAudioElement|null}
*/
getUserAudioElement(
userId: string,
Expand All @@ -361,7 +364,7 @@ export default class LiveKitClient {
// Bind volume control
ui.webrtc?.element
.find(`.camera-view[data-user=${userId}] .webrtc-volume-slider`)
.change(this.onVolumeChange.bind(this));
.on("change", this.onVolumeChange.bind(this));
}

if (audioElement instanceof HTMLAudioElement) {
Expand All @@ -372,12 +375,12 @@ export default class LiveKitClient {
return null;
}

async initializeLocalTracks() {
async initializeLocalTracks(): Promise<void> {
await this.initializeAudioTrack();
await this.initializeVideoTrack();
}

async initializeAudioTrack() {
async initializeAudioTrack(): Promise<void> {
// Make sure the track is initially unset
this.audioTrack = null;

Expand Down Expand Up @@ -405,7 +408,7 @@ export default class LiveKitClient {
}
}

async initializeVideoTrack() {
async initializeVideoTrack(): Promise<void> {
// Make sure the track is initially unset
this.videoTrack = null;

Expand All @@ -430,7 +433,7 @@ export default class LiveKitClient {
}
}

onAudioPlaybackStatusChanged(canPlayback: boolean) {
onAudioPlaybackStatusChanged(canPlayback: boolean): void {
if (!canPlayback) {
log.warn("Cannot play audio/video, waiting for user interaction");
this.windowClickListener =
Expand All @@ -439,7 +442,7 @@ export default class LiveKitClient {
}
}

onConnected() {
onConnected(): void {
log.debug("Client connected");

// Set up room callbacks
Expand All @@ -458,7 +461,7 @@ export default class LiveKitClient {
this.setConnectionButtons(true);
}

onDisconnected() {
onDisconnected(): void {
log.debug("Client disconnected");
ui.notifications?.warn(
`${getGame().i18n.localize(`${LANG_NAME}.onDisconnected`)}`
Expand All @@ -470,13 +473,13 @@ export default class LiveKitClient {
// TODO: Add some incremental back-off reconnect logic here
}

onIsSpeakingChanged(userId: string | undefined, speaking: boolean) {
onIsSpeakingChanged(userId: string | undefined, speaking: boolean): void {
if (userId) {
ui.webrtc?.setUserIsSpeaking(userId, speaking);
}
}

onParticipantConnected(participant: RemoteParticipant) {
onParticipantConnected(participant: RemoteParticipant): void {
log.debug("Participant connected:", participant);

const { fvttUserId } = JSON.parse(participant.metadata || "");
Expand Down Expand Up @@ -512,7 +515,7 @@ export default class LiveKitClient {
this.render();
}

onParticipantDisconnected(participant: RemoteParticipant) {
onParticipantDisconnected(participant: RemoteParticipant): void {
log.debug("Participant disconnected:", participant);

// Remove the participant from the ID mapping
Expand All @@ -523,13 +526,13 @@ export default class LiveKitClient {
this.render();
}

async onReconnected() {
onReconnected(): void {
log.info("Reconnect issued");
// Re-render just in case users changed
this.render();
}

onReconnecting() {
onReconnecting(): void {
log.warn("Reconnecting to room");
ui.notifications?.warn(
`${getGame().i18n.localize("WEBRTC.ConnectionLostWarning")}`
Expand All @@ -539,7 +542,7 @@ export default class LiveKitClient {
onRemoteTrackMuteChanged(
publication: RemoteTrackPublication,
participant: RemoteParticipant
) {
): void {
const { fvttUserId } = JSON.parse(participant.metadata || "");
const userCameraView = ui.webrtc?.getUserCameraView(fvttUserId);

Expand All @@ -557,7 +560,10 @@ export default class LiveKitClient {
}
}

onRenderCameraViews(cameraviews: CameraViews, html: JQuery<HTMLElement>) {
onRenderCameraViews(
cameraviews: CameraViews,
html: JQuery<HTMLElement>
): void {
const cameraBox = html.find(`[data-user="${getGame().user?.id}"]`);
const element = cameraBox.find('[data-action="configure"]');
this.addConnectionButtons(element);
Expand All @@ -567,7 +573,7 @@ export default class LiveKitClient {
track: RemoteTrack,
publication: RemoteTrackPublication,
participant: RemoteParticipant
) {
): Promise<void> {
log.debug("onTrackSubscribed:", track, publication, participant);
const { fvttUserId } = JSON.parse(participant.metadata || "");
const videoElement = ui.webrtc?.getUserVideoElement(fvttUserId);
Expand Down Expand Up @@ -595,11 +601,11 @@ export default class LiveKitClient {
}
}

async onTrackUnSubscribed(
onTrackUnSubscribed(
track: RemoteTrack,
publication: RemoteTrackPublication,
participant: RemoteParticipant
) {
): void {
log.debug("onTrackUnSubscribed:", track, publication, participant);
track.detach();
}
Expand All @@ -608,14 +614,14 @@ export default class LiveKitClient {
* Change volume control for a stream
* @param {Event} event The originating change event from interaction with the range input
*/
onVolumeChange(event: JQuery.ChangeEvent) {
onVolumeChange(event: JQuery.ChangeEvent): void {
const input = event.currentTarget;
const box = input.closest(".camera-view");
const volume = AudioHelper.inputToVolume(input.value);
box.getElementsByTagName("audio")[0].volume = volume;
}

onWindowClick() {
onWindowClick(): void {
if (this.windowClickListener) {
window.removeEventListener("click", this.windowClickListener);
this.render();
Expand All @@ -641,7 +647,7 @@ export default class LiveKitClient {
: false;
}

setAudioEnabledState(enable: boolean) {
setAudioEnabledState(enable: boolean): void {
if (!this.audioTrack) {
log.debug("setAudioEnabledState called but no audio track available");
return;
Expand All @@ -656,7 +662,7 @@ export default class LiveKitClient {
}
}

setConnectionButtons(connected: boolean) {
setConnectionButtons(connected: boolean): void {
const userCameraView = ui.webrtc?.getUserCameraView(
getGame().user?.id || ""
);
Expand All @@ -676,7 +682,7 @@ export default class LiveKitClient {
}
}

setLocalParticipantCallbacks() {
setLocalParticipantCallbacks(): void {
this.liveKitRoom?.localParticipant
.on(
ParticipantEvent.IsSpeakingChanged,
Expand All @@ -690,7 +696,7 @@ export default class LiveKitClient {
});
}

setLocalTrackCallbacks() {
setLocalTrackCallbacks(): void {
// Set up local track callbacks
this.liveKitRoom?.localParticipant.tracks.forEach((publication) => {
const { track } = publication;
Expand All @@ -706,7 +712,7 @@ export default class LiveKitClient {
});
}

setRemoteParticipantCallbacks(participant: RemoteParticipant) {
setRemoteParticipantCallbacks(participant: RemoteParticipant): void {
const { fvttUserId } = JSON.parse(participant.metadata || "");

participant
Expand All @@ -719,7 +725,7 @@ export default class LiveKitClient {
});
}

setRoomCallbacks() {
setRoomCallbacks(): void {
if (!this.liveKitRoom) {
log.warn(
"Attempted to set up room callbacks before the LiveKit room is ready"
Expand Down
4 changes: 3 additions & 1 deletion src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ export async function loadScript(scriptSrc: string): Promise<boolean> {
});
}

export function registerModuleSetting(settingsObject: ModuleSettingsObject) {
export function registerModuleSetting(
settingsObject: ModuleSettingsObject
): void {
getGame().settings.register(MODULE_NAME, settingsObject.name, {
name: `${LANG_NAME}.${settingsObject.name}`,
hint: `${LANG_NAME}.${settingsObject.name}Hint`,
Expand Down
1 change: 0 additions & 1 deletion src/utils/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import LiveKitAVClient from "../LiveKitAVClient";
import { MODULE_NAME } from "./constants";
import { getGame } from "./helpers";
import registerModuleSettings from "./registerModuleSettings";
Expand Down
18 changes: 10 additions & 8 deletions src/utils/logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import { LOG_PREFIX, MODULE_NAME } from "./constants";
* Enabled by default and configured when game settings are available
* @param {...*} args Arguments to console.debug
*/
// eslint-disable-next-line import/no-mutable-exports
export let debug: (...args: any[]) => void = console.debug.bind(
export let debug: (...args: unknown[]) => void = console.debug.bind(
console,
LOG_PREFIX
);
Expand All @@ -20,8 +19,7 @@ export let debug: (...args: any[]) => void = console.debug.bind(
* Enabled by default and configured when game settings are available
* @param {...*} args Arguments to console.info
*/
// eslint-disable-next-line import/no-mutable-exports
export let info: (...args: any[]) => void = console.info.bind(
export let info: (...args: unknown[]) => void = console.info.bind(
console,
LOG_PREFIX
);
Expand All @@ -31,7 +29,7 @@ export let info: (...args: any[]) => void = console.info.bind(
* @param {...*} args Arguments to console.warn
*/

export const warn: (...args: any[]) => void = console.warn.bind(
export const warn: (...args: unknown[]) => void = console.warn.bind(
console,
LOG_PREFIX
);
Expand All @@ -44,7 +42,7 @@ export const warn: (...args: any[]) => void = console.warn.bind(
* Display error messages on the console
* @param {...*} args Arguments to console.error
*/
export const error: (...args: any[]) => void = console.error.bind(
export const error: (...args: unknown[]) => void = console.error.bind(
console,
LOG_PREFIX
);
Expand All @@ -55,8 +53,12 @@ export function setDebug(value: boolean): void {
debug = console.debug.bind(console, LOG_PREFIX);
info = console.info.bind(console, LOG_PREFIX);
} else {
debug = () => {};
info = () => {};
debug = () => {
return;
};
info = () => {
return;
};
}

Hooks.callAll(`${MODULE_NAME}DebugSet`, value);
Expand Down
Loading

0 comments on commit c3f3a2b

Please sign in to comment.