Hi all! How do I modify such a thing to kotlin: ``...
# react
j
Hi all! How do I modify such a thing to kotlin:
Copy code
<ReactPlayer
              config={{
                file: {
                  hlsOptions: {
                    forceHLS: true,
                    debug: false,
                    xhrSetup: function(xhr, url) {
                      if (needsAuth(url)) {
                        xhr.setRequestHeader('Authorization', getToken())
                      }
                    },
                  },
                },
              }}
            />
I saw the things on https://play.kotlinlang.org/hands-on/Building%20Web%20Applications%20with%20React%20and%20Kotlin%20JS/07_Using_Packages_From_NPM but I can't wrap my head around it
I am going in this direction, does it make sense?
Copy code
@file:JsModule("react-player")
@file:JsNonModule

import org.w3c.xhr.XMLHttpRequest
import react.*

@JsName("default")
external val reactPlayer: RClass<ReactPlayerProps>

external interface ReactPlayerProps : RProps {
    var url: String
    var controls: Boolean
    var config: ReactPlayerConfig
}

@JsName("config")
external interface ReactPlayerConfig: RProps {
    var file: FileConfig
}

@JsName("file")
external class FileConfig {
    var hlsOptions: HlsOptions
}

@JsName("hlsOptions")
external class HlsOptions {
    var forceHLS: Boolean
    var debug: Boolean
    var xhrSetup: (XMLHttpRequest, String) -> Unit
}
a
this is correct, does it not work?
j
I don't see the header being changed
and then use the hls config defined here: https://github.com/video-dev/hls.js/blob/master/src/config.ts
I have this code:
Copy code
@file:JsModule("react-player")
@file:JsNonModule

package com.klitsie.pubquiz.app.component.edit

import react.*

@JsName("default")
external val reactPlayer: RClass<ReactPlayerProps>

external interface ReactPlayerProps : RProps {
    var url: String
    var controls: Boolean
    var config: Config?
}

@JsName("Config")
external interface Config {
    var file: FileConfig?
}

@JsName("FileConfig")
external interface FileConfig {
    var forceHLS: Boolean
    var hlsOptions: HlsConfig
}
Copy code
@file:JsModule("hls.js")
@file:JsNonModule

package com.klitsie.pubquiz.app.component.edit

import org.w3c.xhr.XMLHttpRequest

@JsName("HlsConfig")
external interface HlsConfig {
    var debug: Boolean
    var xhrSetup: (xhr: XMLHttpRequest, url: String) -> Unit
}
Copy code
val token = tokenMemoryStorage.value.value ?: "NO_TOKEN"
                    reactPlayer {
                        attrs.url = "<https://127.0.0.1:8442/content/video/adnovum_video.mp4>"
                        val hlsOptions = object: HlsConfig {
                            override var debug: Boolean = true
                            override var xhrSetup = { xhr: XMLHttpRequest, _: String ->
                                xhr.setRequestHeader("Authorization", "bearer $token")
                            }
                        }

                        attrs.config =
                            object : Config {
                                override var file: FileConfig? = object: FileConfig {
                                    override var forceHLS: Boolean = true
                                    override var hlsOptions: HlsConfig = hlsOptions
                                }
                        }
                    }
Copy code
implementation(npm("react-player", "2.6.2"))
                implementation(npm("hls.js", "0.14.16"))
It just doesn't do anything 😞
like the player is there
it works
but there is no header added to the request