I believe that you are sending the same localstream to both the parties (party-B and party-C) in multiconnection because if you try to make different local streams for different connections it will throw error as it will try to access mic and camera again which is not possible(i believe).
You must be creating localstream something like this:
stream = sessionFactory.createLocalMediaStream(LOCAL_MEDIA_ID);
For sending the stream of Party-B to Party-C you can do this:
In place of myStream (for peer connection with C) you can add the remoteStreamB(remote stream that you are getting from B). This will add the stream that you are getting from B as localstream in second peerconnection that is with C.
For sending remote stream from Party-C to Party-B:
- Suppose you have peerconnection1 with Party-B. To add the remote stream from C to as local stream first you will have to remove the current tracks and then add the new tracks.
for this you can do something like this
AudioTrack t1 = mystream.audioTracks.get(0);
VideoTrack v1 = myStream.videoTracks.get(0);
if(myStream.removeTrack(t1)){
if(myStream.removeTrack(v1)){
t1 = remoteStreamC.audioTracks.get(0);
v1 = remoteStreamC.videoTracks.get(0);
myStream.addTrack(t1);
myStream.addTrack(v1);
}
}
By this way you will change the content of the localstream that you are sending to B. Now that stream will be having audio and video tracks coming from remotestreamC.
But to make this process error free you will have to use error handling because when someone breaks the connection (either B or C) you will be getting null tracks.... In that case you will have to immediately send the hangup request to the other party as well.