Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public API Not Directly Usable From Javascript #32

Closed
davertay-j opened this issue Oct 22, 2020 · 3 comments
Closed

Public API Not Directly Usable From Javascript #32

davertay-j opened this issue Oct 22, 2020 · 3 comments
Milestone

Comments

@davertay-j
Copy link
Contributor

davertay-j commented Oct 22, 2020

Unable to invoke the Message.encode method from js, method is defined here:
https://github.com/JuulLabs/koap/blob/main/koap/src/commonMain/kotlin/Encoder.kt#L56

Example:

import koapModule from '@juullabs/koap'
import kotlin from 'kotlin'
const koap = koapModule.com.juul.koap
let token = new kotlin.Long(66)
let emptyPayload = new Uint8Array()
let kMsg = new koap.Message.Tcp(
    koap.Message.Code.Method.GET,
    token,
    new kotlin.kotlin.collections.ArrayList(
        [
            new koap.Message.Option.UriPath("dev"),
            new koap.Message.Option.UriQuery("abd")
        ]
    ),
    emptyPayload
}
let outMsg = koap.encode(kMsg)

Results in the exception: "Unhandled Rejection (TypeError): koap.encode is not a function"

IMHO there needs to be some javascript unit tests added to exercise the API to verify it performs as expected when published as a library.

@twyatt twyatt added this to the 0.3.4 milestone Oct 27, 2020
@twyatt
Copy link
Member

twyatt commented Oct 28, 2020

@davidtaylor-juul #35 fixes this issue, right? (i.e. can this issue be closed out now?)

@davertay-j
Copy link
Contributor Author

While #35 fixes the name mangling there are further issues preventing direct usage from Javascript. I recommend holding this ticket open until we can provide a slightly massaged API for js consumption and show a working example.

@davertay-j davertay-j changed the title Message.encode() Method Not Available To Javascript Public API Not Directly Usable From Javascript Oct 29, 2020
@davertay-j
Copy link
Contributor Author

I actually do have it working now. The issue was difficulty of interop with parts of the API that require List<T> objects an the inability to invoke Array.toList().

The solution is to use ArrayList instead and javascript arrays can be converted to such e.g.:

let myList = new kotlin.kotlin.collections.ArrayList(['a','b','c'])

Have updated the above example to suit. The syntax is pretty wild but this does the trick so this issue can indeed be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants