flutter_janus_client icon indicating copy to clipboard operation
flutter_janus_client copied to clipboard

VideoRoomPlugin with dataChannel

Open d34d9007 opened this issue 3 years ago • 10 comments

Hi, I am trying to configure a dataChannel in the VideoRoomPlugin but when I send a message I get nothing in the data stream.

d34d9007 avatar Oct 21 '22 14:10 d34d9007

I see, this was expected, i need to test it and will get back to you accordingly

shivanshtalwar0 avatar Oct 21 '22 19:10 shivanshtalwar0

Hi Shivansh, To better explain the problem. In my room there is a subscriber who has already created a channel and I want to listen to it. I did so:

   videoRoom.webRTCHandle!.peerConnection!.onDataChannel = (channel) {
            log("LISTEN CHANNNEL: ${channel.label} ");
            channel.onBufferedAmountLow = (currentAmount) {
              log(currentAmount.toString(), name: "onBufferedAmountLow");
            };

      channel.onBufferedAmountChange = (currentAmount, changedAmount) {
        log(currentAmount.toString(), name: "onBufferedAmountChange");
        log(changedAmount.toString(), name: "onBufferedAmountChange");
      };

      channel.onMessage = (data) {
        log(data.text, name: "onMessage");
      };

      channel.onDataChannelState = (state) {
        log(state.name, name: "onDataChannelState");
      };

      channel.stateChangeStream.listen((state) {
        log(state.name, name: "stateChangeStream");
      });

      channel.messageStream.listen((message) {
        log(message.text, name: "messageStream");
      });
    };

Is it correct to listen to the channel in this way?

d34d9007 avatar Oct 24 '22 10:10 d34d9007

Nope this will not work because there is no data channel created on peerconnection object on webrtc handle You need to call initDataChannel to create data channel with supported label So check this out https://github.com/flutterjanus/flutter_janus_client/blob/d72cd770285f1ccfac04eae0add59a0772be640a/lib/janus_plugin.dart#L464 Try calling initDataChannel then directly access peerconnection object for data channel callback although i would advise you to use helper streams to listen to events rather that directly accessing webrtcHandle?.peerconnection it is there for custom functionality only. Try this and i believe it should work for you if it doesn't i will add data channel support in one of examples to illustrate how to use data channel with other media streams. You can also look at setup method of textroom plugin which shows the use of initDataChannel method

https://github.com/flutterjanus/flutter_janus_client/blob/d72cd770285f1ccfac04eae0add59a0772be640a/lib/wrapper_plugins/janus_text_room_plugin.dart#L19

shivanshtalwar0 avatar Oct 25 '22 17:10 shivanshtalwar0

Hi Shivansh, could you write an example? we can't get it to work. Thank you

d34d9007 avatar Oct 26 '22 10:10 d34d9007

check videocall example i have updated with datachannel illustration similar to videocall demo

https://github.com/flutterjanus/flutter_janus_client/commit/edea8f80ab8280a5da0459542095877725e36843 i hope it helps you

shivanshtalwar avatar Oct 27 '22 13:10 shivanshtalwar

Closing because of no activity you can request to reopen if you still think there are some issues.

shivanshtalwar0 avatar Oct 28 '22 23:10 shivanshtalwar0

Hi @shivanshtalwar , I followed your VideoCall example but I still don't get any message in the stream. I used initDataChannel and verified that the channel has been created and is open. I also verified that sending the message works. I put a log inside the sendData function and it is executed correctly.

I call plugin.data?.listen in joinRoom, when data is VideoRoomConfigured. But I don't get any message.

if (data is VideoRoomConfigured) {
        log("VideoRoomConfigured", name: "configured log flavio");
        print('typed event with jsep' + event.jsep.toString());
        await plugin.handleRemoteJsep(event.jsep);

        plugin.data?.listen((message) async {
          log(message.text, name: "Message received");
        });
      }

Can you help me? Thanks

Thank you

d34d9007 avatar Nov 02 '22 13:11 d34d9007

I have update for you, i tried setting up data channel with video room, i was able to establish data channel open connection but couldn't send anything through, till the time i investigate it further i would suggest to use textroom plugin along with videoroom plugin which seems more scalable setup to me.

shivanshtalwar0 avatar Nov 28 '22 08:11 shivanshtalwar0

Hi @shivanshtalwar0, Thank you! Looking forward to your update.

d34d9007 avatar Dec 12 '22 09:12 d34d9007