flutterjanus / flutter_janus_client

A plugin that allows the flutter app to communicate with a Janus server using different transport mechanisms, such as WebSocket and HTTP(rest). It features a developer-friendly api to interact with various WebRTC Janus Plugins. Hence, it can be considered as a swiss-knife for WebRTC solutions.
MIT License
132 stars 76 forks source link

VideoRoomPlugin with dataChannel #91

Open FlavioCarnevale opened 1 year ago

FlavioCarnevale commented 1 year ago

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

shivanshtalwar0 commented 1 year ago

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

FlavioCarnevale commented 1 year ago

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?

shivanshtalwar0 commented 1 year ago

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

FlavioCarnevale commented 1 year ago

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

shivanshtalwar commented 1 year ago

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

shivanshtalwar0 commented 1 year ago

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

FlavioCarnevale commented 1 year ago

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

shivanshtalwar0 commented 1 year ago

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.

FlavioCarnevale commented 1 year ago

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