# All files / src/types loader.ts

0% Statements 0/0
0% Branches 2/2
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133

     import Level from '../loader/level';

    export interface LoaderContext {
      // target URL
      url: string
      // loader response type (arraybuffer or default response type for playlist)
      responseType: string
      // start byte range offset
      rangeStart?: number
      // end byte range offset
      rangeEnd?: number
      // true if onProgress should report partial chunk of loaded content
      progressData?: boolean
    }

    export interface LoaderConfiguration {
      // Max number of load retries
      maxRetry: number
      // Timeout after which `onTimeOut` callback will be triggered
      // (if loading is still not finished after that delay)
      timeout: number
      // Delay between an I/O error and following connection retry (ms).
      // This to avoid spamming the server
      retryDelay: number
      // max connection retry delay (ms)
      maxRetryDelay: number
    }

    export interface LoaderResponse {
      url: string,
      // TODO(jstackhouse): SharedArrayBuffer, es2017 extension to TS
      data: string | ArrayBuffer
    }

    export interface LoaderStats {
      // performance.now() just after load() has been called
      trequest: number
      // performance.now() of first received byte
      tfirst: number
      // performance.now() on load complete
      tload: number
      // performance.now() on parse completion
      tparsed: number
      // number of loaded bytes
      loaded: number
      // total number of bytes
      total: number
    }

    type LoaderOnSuccess < T extends LoaderContext > = (
      response: LoaderResponse,
      stats: LoaderStats,
      context: T,
      networkDetails: any
    ) => void;

    type LoaderOnProgress < T extends LoaderContext > = (
      stats: LoaderStats,
      context: T,
      data: string | ArrayBuffer,
      networkDetails: any,
    ) => void;

    type LoaderOnError < T extends LoaderContext > = (
      error: {
        // error status code
        code: number,
        // error description
        text: string,
      },
      context: T,
      networkDetails: any,
    ) => void;

    type LoaderOnTimeout < T extends LoaderContext > = (
      stats: LoaderStats,
      context: T,
    ) => void;

    export interface LoaderCallbacks<T extends LoaderContext>{
      onSuccess: LoaderOnSuccess<T>,
      onError: LoaderOnError<T>,
      onTimeout: LoaderOnTimeout<T>,
      onProgress?: LoaderOnProgress<T>,
    }

    export interface Loader<T extends LoaderContext> {
      destroy(): void
      abort(): void
      load(
        context: LoaderContext,
        config: LoaderConfiguration,
        callbacks: LoaderCallbacks<T>,
      ): void

      context: T
    }

    /**
     * `type` property values for this loaders' context object
     * @enum
     *
     */
    export enum PlaylistContextType {
      MANIFEST = 'manifest',
      LEVEL = 'level',
      AUDIO_TRACK = 'audioTrack',
      SUBTITLE_TRACK= 'subtitleTrack'
    }

    /**
     * @enum {string}
     */
    export enum PlaylistLevelType {
      MAIN = 'main',
      AUDIO = 'audio',
      SUBTITLE = 'subtitle'
    }

    export interface PlaylistLoaderContext extends LoaderContext {
      loader?: Loader<PlaylistLoaderContext>

      type: PlaylistContextType
      // the level index to load
      level: number | null
      // TODO: what is id?
      id: number | null
      // defines if the loader is handling a sidx request for the playlist
      isSidxRequest?: boolean
      // internal reprsentation of a parsed m3u8 level playlist
      levelDetails?: Level
    }