pchab / ProjectRTC

WebRTC Live Streaming on nodeJS (+ android client !)
Other
1.04k stars 476 forks source link

Enhancement: chat functionality #13

Open dwsrumwq7cyey7qv opened 9 years ago

dwsrumwq7cyey7qv commented 9 years ago

Hello, I am thankful for the project and I am especially interested in the combination of the web und android client. The video communication works wonderful, but I am searching for a way to extend the project for a chat functionality. As far as I understood, the node.js server creates a stream for each participant. Is it possible to use this stream to also pass on textual data? Or should there be an additional stream, such that there are two streams - one for audio/ video and text? How should this functionality be implemented on android? Thank you in advice!

pchab commented 9 years ago

Hello,

Thank you for your interest in my project. The easiest way to add text chat imo would be to use the socket.io channel to send messages. It already support a chat room functionality. As you can see in the code, I've implemented 2 kind of message, "id" and "message" (which could be confusing in your case, I should probably rename it to "signal" or something like that). Just add a third kind of message (like "chat"). That way, I don't think it would be too much work to add this functionality.

On Mon, May 4, 2015 at 10:18 AM, dwsrumwq7cyey7qv notifications@github.com wrote:

Hello, I am thankful for the project and I am especially interested in the combination of the web und android client. The video communication works wonderful, but I am searching for a way to extend the project for a chat functionality. As far as I understood, the node.js server creates a stream for each participant. Is it possible to use this stream to also pass on textual data? Or should there be an additional stream, such that there are two streams - one for audio/ video and text? How should this functionality be implemented on android? Thank you in advice!

— Reply to this email directly or view it on GitHub https://github.com/pchab/ProjectRTC/issues/13.

KristjanLiiva commented 8 years ago

Just as an addon, you can also use WebRTC DataChannel. This way the messages are not sent over the node js server. Example code, for WebRtcClient.java, for the AndroidRTC. And in the Web client should implement the onDataChannel.

private class Peer implements SdpObserver, PeerConnection.Observer {
        private PeerConnection pc;
        private DataChannel dc;
        ...

        private class DcObserver implements DataChannel.Observer {
            @Override
            public void onMessage(DataChannel.Buffer buffer) {

                // as an example write a response back
                String response = "Response message";
                ByteBuffer send = ByteBuffer.wrap(response.getBytes());
                dc.send(new DataChannel.Buffer(send, false));
            }

            @Override
            public void onStateChange(){

            }
        }
        public Peer(String id, int endPoint) {
            Log.d(TAG,"new Peer: "+id + " " + endPoint);
            this.pc = factory.createPeerConnection(iceServers, pcConstraints, this);
            this.id = id;
            this.endPoint = endPoint;

            pc.addStream(localMS); //, new MediaConstraints()
            dc = pc.createDataChannel("sendDataChannel", new DataChannel.Init());
            DcObserver dcObserver = new DcObserver();
            dc.registerObserver(dcObserver);

            mListener.onStatusChanged("CONNECTING");
        }
}

I just wrote it and it works together with a web page that is implementing the onDataChannel. But for some reason I could not get it working when the web client calls createDataChannel. The onDataChannel is never called in Android. In any case, I am sure it is something that i have missed somewhere. Just thought it might help someone.