Linter and formatter #6
							
								
								
									
										7
									
								
								.eslintrc.cjs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7
									
								
								.eslintrc.cjs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,7 @@ | |||||||
|  | /* eslint-env node */ | ||||||
|  | module.exports = { | ||||||
|  |     extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'], | ||||||
|  |     parser: '@typescript-eslint/parser', | ||||||
|  |     plugins: ['@typescript-eslint'], | ||||||
|  |     root: true, | ||||||
|  |   }; | ||||||
							
								
								
									
										1247
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1247
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -13,6 +13,9 @@ | |||||||
|   "author": "", |   "author": "", | ||||||
|   "license": "ISC", |   "license": "ISC", | ||||||
|   "devDependencies": { |   "devDependencies": { | ||||||
|  |     "@typescript-eslint/eslint-plugin": "^6.13.2", | ||||||
|  |     "@typescript-eslint/parser": "^6.13.2", | ||||||
|  |     "eslint": "^8.55.0", | ||||||
|     "parcel": "^2.10.3", |     "parcel": "^2.10.3", | ||||||
|     "process": "^0.11.10", |     "process": "^0.11.10", | ||||||
|     "ts-loader": "^9.5.1", |     "ts-loader": "^9.5.1", | ||||||
|   | |||||||
| @@ -20,21 +20,16 @@ export class MinistreamApiClient { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async listStreams(): Promise<StreamInfo[]> { |     async listStreams(): Promise<StreamInfo[]> { | ||||||
|         var data: StreamInfo[] = []; |         let data: StreamInfo[] = []; | ||||||
|         var url = "/whip" |         let url = "/whip" | ||||||
|         if (this.ENV !== "production") { |         if (this.ENV !== "production") { | ||||||
|             url = "http://localhost:8080/whip" |             url = "http://localhost:8080/whip" | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         try { |         const resp = await fetch( | ||||||
|             const resp = await fetch( |             url, | ||||||
|                 url, |         ); | ||||||
|             ); |         data = await resp.json() as unknown as StreamInfo[]; | ||||||
|             data = await resp.json() as unknown as StreamInfo[]; |  | ||||||
|         } |  | ||||||
|         catch (e) { |  | ||||||
|             throw e; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         const sortedStreams = data.sort((a, b) => { |         const sortedStreams = data.sort((a, b) => { | ||||||
|             if (a.streamKey > b.streamKey) { |             if (a.streamKey > b.streamKey) { | ||||||
| @@ -49,7 +44,7 @@ export class MinistreamApiClient { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async postOffer(streamKey: string, offer_sdp: RTCSessionDescription): Promise<RTCSessionDescription> { |     async postOffer(streamKey: string, offer_sdp: RTCSessionDescription): Promise<RTCSessionDescription> { | ||||||
|         var url = "/whip/" + streamKey |         let url = "/whip/" + streamKey | ||||||
|         if (this.ENV !== "production") { |         if (this.ENV !== "production") { | ||||||
|             url = "http://localhost:8080/whip/" + streamKey |             url = "http://localhost:8080/whip/" + streamKey | ||||||
|         } |         } | ||||||
| @@ -66,7 +61,7 @@ export class MinistreamApiClient { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async siteInfo(): Promise<SiteInfo> { |     async siteInfo(): Promise<SiteInfo> { | ||||||
|         var url = "/api/siteinfo" |         let url = "/api/siteinfo" | ||||||
|         if (this.ENV !== "production") { |         if (this.ENV !== "production") { | ||||||
|             url = "http://localhost:8080/api/siteinfo" |             url = "http://localhost:8080/api/siteinfo" | ||||||
|         } |         } | ||||||
|   | |||||||
| @@ -1,10 +1,10 @@ | |||||||
| import { createRoot } from "react-dom/client"; | import { createRoot } from "react-dom/client"; | ||||||
| import { Menu } from "./menu"; | import { Menu } from "./menu"; | ||||||
| import { createContext, useEffect, useState } from "react"; | import { useEffect, useState } from "react"; | ||||||
| import { MediaContainer } from "./media"; | import { MediaContainer } from "./media"; | ||||||
| import { MinistreamApiClient, StreamInfo } from "./api"; | import { MinistreamApiClient, StreamInfo } from "./api"; | ||||||
| import React from "react"; | import React from "react"; | ||||||
| import { Log } from "./log"; | import * as Log from "./log"; | ||||||
|  |  | ||||||
| interface AppProps { | interface AppProps { | ||||||
|     api: MinistreamApiClient |     api: MinistreamApiClient | ||||||
| @@ -13,7 +13,7 @@ interface AppProps { | |||||||
| const titleKey = "ministream.title" | const titleKey = "ministream.title" | ||||||
|  |  | ||||||
| function setTitleFromLocalstorage() { | function setTitleFromLocalstorage() { | ||||||
|     var title = localStorage.getItem(titleKey) |     const title = localStorage.getItem(titleKey) | ||||||
|     if (title) { |     if (title) { | ||||||
|         setTitle(title) |         setTitle(title) | ||||||
|     } |     } | ||||||
|   | |||||||
							
								
								
									
										103
									
								
								src/js/log.ts
									
									
									
									
									
								
							
							
						
						
									
										103
									
								
								src/js/log.ts
									
									
									
									
									
								
							| @@ -1,61 +1,58 @@ | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| export namespace Log { | function levelToNumber(level: Level): number { | ||||||
|     var currentLevel: Level = "INFO" |     switch (level) { | ||||||
|  |         case "DEBUG": | ||||||
|  |             return 0 | ||||||
|  |         case "INFO": | ||||||
|  |             return 1 | ||||||
|  |         case "ERROR": | ||||||
|  |             return 2 | ||||||
|  |         case "WARN": | ||||||
|  |             return 3 | ||||||
|  |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|     if (process.env.NODE_ENV !== 'production') {  | let currentLevel: Level = "INFO" | ||||||
|         currentLevel = "DEBUG" |  | ||||||
|  | if (process.env.NODE_ENV !== 'production') { | ||||||
|  |     currentLevel = "DEBUG" | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export type Level = "ERROR" | "WARN" | "INFO" | "DEBUG" | ||||||
|  |  | ||||||
|  | export function setLevel(level: Level) { | ||||||
|  |     currentLevel = level | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export interface LogArgs { | ||||||
|  |     [key: string]: string | ||||||
|  | } | ||||||
|  |  | ||||||
|  | const doLog = (level: Level, message: string, extras?: LogArgs) => { | ||||||
|  |     let logLine = `[${level}] ${message}` | ||||||
|  |  | ||||||
|  |     if (extras) { | ||||||
|  |         Object.keys(extras).forEach((key) => { | ||||||
|  |             logLine = logLine + ` ${key}=${extras[key]}` | ||||||
|  |         }) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     export type Level = "ERROR" | "WARN" | "INFO" | "DEBUG" |     if (levelToNumber(level) >= levelToNumber(currentLevel)) { | ||||||
|  |         console.log(logLine) | ||||||
|     export function setLevel(level: Level) { |  | ||||||
|         currentLevel = level |  | ||||||
|     } |     } | ||||||
|  | } | ||||||
|  |  | ||||||
|  | export function Error(message: string, extras?: LogArgs) { | ||||||
|     export interface LogArgs { |     doLog("ERROR", message, extras) | ||||||
|         [key: string]: string | } | ||||||
|     } | export function Warn(message: string, extras?: LogArgs) { | ||||||
|  |     doLog("WARN", message, extras) | ||||||
|     export function Error(message: string, extras?: LogArgs) { | } | ||||||
|         doLog("ERROR", message, extras) | export function Info(message: string, extras?: LogArgs) { | ||||||
|     } |     doLog("INFO", message, extras) | ||||||
|     export function Warn(message: string, extras?: LogArgs) { | } | ||||||
|         doLog("WARN", message, extras) | export function Debug(message: string, extras?: LogArgs) { | ||||||
|     } |     doLog("DEBUG", message, extras) | ||||||
|     export function Info(message: string, extras?: LogArgs) { | } | ||||||
|         doLog("INFO", message, extras) |  | ||||||
|     } |  | ||||||
|     export function Debug(message: string, extras?: LogArgs) { |  | ||||||
|         doLog("DEBUG", message, extras) |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function doLog(level: Level, message: string, extras?: LogArgs) { |  | ||||||
|         var logLine = `[${level}] ${message}` |  | ||||||
|  |  | ||||||
|         if (extras) { |  | ||||||
|             Object.keys(extras).forEach((key) => { |  | ||||||
|                 logLine = logLine + ` ${key}=${extras[key]}` |  | ||||||
|             }) |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         if (levelToNumber(level) >= levelToNumber(currentLevel)) { |  | ||||||
|             console.log(logLine) |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     function levelToNumber(level: Level): number { |  | ||||||
|         switch (level) { |  | ||||||
|             case "DEBUG": |  | ||||||
|                 return 0 |  | ||||||
|             case "INFO": |  | ||||||
|                 return 1 |  | ||||||
|             case "ERROR": |  | ||||||
|                 return 2 |  | ||||||
|             case "WARN": |  | ||||||
|                 return 3 |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -1,8 +1,7 @@ | |||||||
| import { ComponentProps, useRef, useEffect, useState } from "react" | import { useRef, useEffect, useState } from "react" | ||||||
| import { MinistreamApiClient } from "./api" | import { MinistreamApiClient } from "./api" | ||||||
| import { resolve } from "path" |  | ||||||
| import React from "react" | import React from "react" | ||||||
| import { Log } from "./log" | import * as Log from "./log"; | ||||||
|  |  | ||||||
| type MediaContainerProps = { | type MediaContainerProps = { | ||||||
|     selectedStream: string | null |     selectedStream: string | null | ||||||
| @@ -151,7 +150,7 @@ interface LoadingText { | |||||||
| } | } | ||||||
|  |  | ||||||
| export function LoadingText({ text, spinner = false }: LoadingText) { | export function LoadingText({ text, spinner = false }: LoadingText) { | ||||||
|     var spinnerElement = (<></>) |     let spinnerElement = (<></>) | ||||||
|     if (spinner) { |     if (spinner) { | ||||||
|         spinnerElement = (<Spinner />) |         spinnerElement = (<Spinner />) | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -1,4 +1,3 @@ | |||||||
| import { createRoot } from "react-dom/client"; |  | ||||||
| import React from "react"; | import React from "react"; | ||||||
| import { StreamInfo } from "./api"; | import { StreamInfo } from "./api"; | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user