Skip to content

Kotlin definitions and extensions for the simple-peer p2p webrtc library

Notifications You must be signed in to change notification settings

IIlllII/simple-peer-kt-ext

Repository files navigation

simple-peer-kt-ext

Kotlin definitions and extension for the awesome simple-peer Meant to be used in kotlin javascript projects.

Gradle use

Add to build.gradle.kts

dependencies {
    implementation("com.bitbreeds.p2p","simple-peer-kt-ext","0.1-SNAPSHOT")
    implementation(npm("simple-peer","9.7.2"))
}

Use

For use of simple peer, see https://github.com/feross/simple-peer. The first example there can be implemented like this using kotlin.

In a real case, peers need to be in different browsers, and share signals over some other communication (typically websocket).

fun main() {
        val peer1 = Peer()
        val peer2 = Peer()

        peer1.on("signal") { data ->
            print("Data")
            peer2.signal(data)
        }

        peer2.on("signal") { data ->
            print("Data")
            peer1.signal(data)
        }

        peer1.on("connect") {
            peer1.send("hey peer2, how is it going")
        }

        peer2.on("data") { data ->
            console.log("got a message from peer1: $data")
        }
}

About

Kotlin definitions and extensions for the simple-peer p2p webrtc library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published