11import EventEmitter from "events" ;
2- import { PlayObject } from "../../core/Atomic.js" ;
2+ import { PlayObject , URLData } from "../../core/Atomic.js" ;
33import { buildTrackString , combinePartsToString , truncateStringToLength } from "../../core/StringUtils.js" ;
44import {
55 asPlayerStateDataMaybePlay ,
@@ -16,8 +16,7 @@ import { GetSessionsMetadata } from "@lukehagar/plexjs/sdk/models/operations/get
1616import { PlexAPI , HTTPClient , Fetcher } from "@lukehagar/plexjs" ;
1717import { Agent } from 'undici' ;
1818import { PlexApiSourceConfig } from "../common/infrastructure/config/source/plex.js" ;
19- import { isPortReachable , joinedUrl } from '../utils/NetworkUtils.js' ;
20- import normalizeUrl from 'normalize-url' ;
19+ import { isPortReachable , joinedUrl , normalizeWebAddress } from '../utils/NetworkUtils.js' ;
2120import { GetTokenDetailsResponse , GetTokenDetailsUserPlexAccount } from '@lukehagar/plexjs/sdk/models/operations/gettokendetails.js' ;
2221import { parseRegexSingle } from '@foxxmd/regex-buddy-core' ;
2322import { Readable } from 'node:stream' ;
@@ -42,7 +41,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
4241
4342 deviceId : string ;
4443
45- address : URL ;
44+ address : URLData ;
4645
4746 usersAllow : string [ ] = [ ] ;
4847 usersBlock : string [ ] = [ ] ;
@@ -121,8 +120,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
121120 this . logger . warn ( `When both 'librariesAllow' and 'librariesBlock' are specified only 'librariesAllow' is used.` ) ;
122121 }
123122
124- const normal = normalizeUrl ( this . config . data . url , { removeSingleSlash : true } ) ;
125- this . address = new URL ( normal ) ;
123+ this . address = normalizeWebAddress ( this . config . data . url ) ;
126124 this . logger . debug ( `Config URL: ${ this . config . data . url } | Normalized: ${ this . address . toString ( ) } ` ) ;
127125
128126 let httpClient : HTTPClient | undefined ;
@@ -151,7 +149,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
151149 }
152150
153151 this . plexApi = new PlexAPI ( {
154- serverURL : this . address . toString ( ) ,
152+ serverURL : this . address . url . toString ( ) ,
155153 accessToken : this . config . data . token ,
156154 httpClient
157155 } ) ;
@@ -161,7 +159,7 @@ export default class PlexApiSource extends MemoryPositionalSource {
161159
162160 protected async doCheckConnection ( ) : Promise < true | string | undefined > {
163161 try {
164- const reachable = await isPortReachable ( parseInt ( this . address . port ?? '80' ) , { host : this . address . hostname } ) ;
162+ const reachable = await isPortReachable ( this . address . port , { host : this . address . url . hostname } ) ;
165163 if ( ! reachable ) {
166164 throw new Error ( `Could not reach server at ${ this . address } }` ) ;
167165 }
0 commit comments