All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jsMain.com.ditchoom.socket.Socket.kt Maven / Gradle / Ivy

There is a newer version: 1.2.1
Show newest version
package com.ditchoom.socket

import kotlinx.browser.window
import org.w3c.dom.WebSocket
import org.w3c.dom.get
import kotlin.time.ExperimentalTime

val isNodeJs = nodeJs()


private fun nodeJs() :Boolean {
    println("isNodeJs ${js("global.window") == null}")
    return js("global.window") == null
}
@ExperimentalUnsignedTypes
@ExperimentalTime
actual fun asyncClientSocket(): ClientToServerSocket {
    println("isNodeJs ${js("global.window") == null}")
    return if (isNodeJs) {
        NodeClientSocket()
    } else {
        throw UnsupportedOperationException("Sockets are not supported in the browser")
    }
}


@ExperimentalTime
actual fun clientSocket(blocking: Boolean): ClientToServerSocket =
    throw UnsupportedOperationException("Only non blocking io is supported with JS")

@ExperimentalUnsignedTypes
@ExperimentalTime
actual fun asyncServerSocket(): ServerSocket {
    if (isNodeJs) {
//        throw UnsupportedOperationException("Not implemented yet")
        return NodeServerSocket()
    } else {
        throw UnsupportedOperationException("Sockets are not supported in the browser")
    }
}

external fun require(module: String): dynamic




© 2015 - 2024 Weber Informatics LLC | Privacy Policy