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

DataChannel example #44

Open
mdrlzy opened this issue Aug 2, 2023 · 2 comments
Open

DataChannel example #44

mdrlzy opened this issue Aug 2, 2023 · 2 comments

Comments

@mdrlzy
Copy link

mdrlzy commented Aug 2, 2023

Looks like PeerConnection.createDataChannel does not trigger PeerConnection.Observer.onDataChannel
Maybe I'm doing something wrong
So could you provide small example?

@ApplY3D
Copy link

ApplY3D commented Nov 12, 2023

It will be triggered after the two peers establish a connection

@ApplY3D
Copy link

ApplY3D commented Nov 13, 2023

also you could set negotiated=true and id=0 to all your peers and you will not need onDataChannel anymore

val dataChannelConfig = DataChannel.Init()
dataChannelConfig.negotiated = true
dataChannelConfig.id = 0
dataChannel = localPeer?.createDataChannel("ch0", dataChannelConfig)
dataChannel?.registerObserver(object : DataChannel.Observer {
    override fun onBufferedAmountChange(p0: Long) {}
    override fun onMessage(buffer: DataChannel.Buffer?) {
        if (buffer == null) return
        val msg = StandardCharsets.UTF_8.decode(buffer.data)
    }

    override fun onStateChange() {
        if (dataChannel?.state() == DataChannel.State.OPEN) {
            // peers connected, channel open
        }
    }
})

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