gdx-backend-jtransc icon indicating copy to clipboard operation
gdx-backend-jtransc copied to clipboard

Support Gdx.Net

Open soywiz opened this issue 9 years ago • 6 comments

  • [ ] HttpRequest stuff should work on browser.
  • [ ] openUri should work on browser too.
  • [ ] client/server socket won't work on browser due to limitations (just websockets), but could be implemented for C++/flash targets

soywiz avatar May 26 '16 19:05 soywiz

Are there any plans of supporting cross-platform web sockets? This is basically the only way to implement somewhat reliable real-time multiplayer game on the HTML5 target.

I implemented an unofficial web sockets extension using nv-websocket-client and native web sockets on GWT. Not sure if it helps though, but some third party libraries might prove useful.

czyzby avatar May 27 '16 20:05 czyzby

Sure. We are already doing that. I will include it here as an extension:

Kotlin code looks like this (though I will backport to Java so it won't require kotlin at all). We have two implementations: one for haxe and other for java using one websocket library from maven.

https://github.com/soywiz/haxe-ws

@HaxeAddMembers("var ws:haxe.net.WebSocket;")
@HaxeAddLibraries("haxe-ws:0.0.6")
class WebSocketHaxe(url: String, subprotocols: Array<String>?) : WebSocket(url) {
    init {
        ws_init(url, subprotocols)
        process()
    }

    @HaxeMethodBody("""
        if (p1 != null) {
            this.ws = haxe.net.WebSocket.create(p0._str, cast p1.toArray()); // Array<String>
        } else {
            this.ws = haxe.net.WebSocket.create(p0._str);
        }
        this.ws.onopen = function() { this.{% METHOD nova.net.ws.WebSocketHaxe:onConnectSend %}(); };
        this.ws.onclose = function() { this.{% METHOD nova.net.ws.WebSocketHaxe:onDisconnectedSend %}(); };
        this.ws.onmessageString = function(m:String) { this.{% METHOD nova.net.ws.WebSocketHaxe:onStringMessageSend %}(HaxeNatives.str(m)); };
    """)
    private fun ws_init(url: String, subprotocols: Array<String>?) {
    }

    @HaxeMethodBody("this.ws.process();")
    private fun process_int(): Unit {
    }

    private fun process(): Unit {
        process_int()
        EventLoop.setTimeout(20) { process() }
    }

    @JTranscKeep
    private fun onConnectSend() = onConnect.dispatch(Unit)

    @JTranscKeep
    private fun onDisconnectedSend() = onDisconnected.dispatch(Unit)

    @JTranscKeep
    private fun onStringMessageSend(msg: String) = onStringMessage.dispatch(msg)

    @JTranscKeep
    private fun onBinaryMessageSend(msg: ByteArray) = onBinaryMessage.dispatch(msg)

    @HaxeMethodBody("")
    override fun connect() = super.connect()

    @HaxeMethodBody("this.ws.sendString(p0._str);")
    override fun send(message: String) = super.send(message)

    //@HaxeMethodBody("this.ws.sendBytes(haxe.io.Bytes.ofData(p0.data.view.getData()));")
    override fun send(message: ByteArray) = super.send(message)
}

soywiz avatar May 27 '16 22:05 soywiz

How is this issue going? I can see that there is a websockets module, does it work? How should I use it?

SnowyCoder avatar Dec 27 '18 18:12 SnowyCoder

I think @soywiz moved on to Korge.

czyzby avatar Dec 28 '18 11:12 czyzby

That’s right. At this point im not updating jtransc actively. I am finishing my libraries right now. After that maybe i continue working on jtransc to target places like homebrew or consoles where kotlin-native doesnt work. Unless they allow to generate c++ directly so it can be compiled using the standard gcc/g++.

Despite of that im still accepting PRs at this point, so if anyone wants to implement this i will happily merge it.

soywiz avatar Dec 29 '18 01:12 soywiz

Ok, thanks

SnowyCoder avatar Jan 01 '19 20:01 SnowyCoder