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 Support Implementation #1866

Closed
mekya opened this issue Feb 3, 2020 · 1 comment
Closed

DataChannel Support Implementation #1866

mekya opened this issue Feb 3, 2020 · 1 comment
Assignees

Comments

@mekya
Copy link
Contributor

mekya commented Feb 3, 2020

  • Publisher create data channel
  • Publisher can send data
  • Player listens created data channel
  • Players can send data

Provide simple methods and configurations to send and receive message(callback in webrtc_adaptor.js) for ease of use of lovely developers :)

Supported Options - Configurations in AppSettings

  • Enable/disable DataChannel
  • Player's data can be delivered to whole players and publisher (+Cluster Support)
  • Data can be sent only to publisher (+Cluster Support)
  • Player can only receive incoming messages (+Cluster Support)
  • Video Conference Support

JavaScript Implementation 3
Single Node Implementation 6
Cluster Support 6

@mekya mekya self-assigned this Feb 3, 2020
@mekya mekya assigned burak-58 and unassigned mekya Feb 24, 2020
@mekya
Copy link
Contributor Author

mekya commented Feb 27, 2020

In Publishing

DataChannel should be created on client side by in initPeerConnectionmethod.
after following line thiz.remotePeerConnection[streamId].ontrack = function(event) { thiz.onTrack(event, closedStreamId); }

			const dataChannelOptions = {
				ordered: true, // do not guarantee order
			  };
			dataChannel = thiz.remotePeerConnection[streamId].createDataChannel("use_stream_id", dataChannelOptions);
			
			dataChannel.onerror = (error) => {
				console.log("Data Channel Error:", error);
			  };
			  
			  dataChannel.onmessage = (event) => {
				console.log("Got Data Channel Message:", event.data);
			  };
			  
			  dataChannel.onopen = () => {
				dataChannel.send("Hello World!");
			  };
			  
			  dataChannel.onclose = () => {
				console.log("The Data Channel is Closed");
			  };

On Server side, there is ready onDataChannel callback method in WebRTCEncoderAdaptor. Just add observer in that method

@Override
	public void onDataChannel(DataChannel dataChannel) {
		logger.info("onDataChannel for stream Id {}", streamId);
		
		dataChannel.registerObserver(new DataChannel.Observer() {
			
			@Override
			public void onStateChange() {
			}
			
			@Override
			public void onMessage(org.webrtc.DataChannel.Buffer buffer) {
			}
			
			@Override
			public void onBufferedAmountChange(long previousAmount) {
			}
		});
	}

After that you can use send method to send message and receive the message onMessage method.

In Playing

Server side creates the data channel startInternal in WebRTCClient

DataChannel dataChannel = peerConnection.createDataChannel(streamId, new DataChannel.Init());
			
			dataChannel.registerObserver(new DataChannel.Observer() {
				
				@Override
				public void onStateChange() {
					System.out.println("WebRTCClient.startInternal().new Observer() {...}.onStateChange()");
				}
				
				@Override
				public void onMessage(Buffer buffer) {
					System.out.println("WebRTCClient.startInternal().new Observer() {...}.onMessage()");
					
				}
				
				@Override
				public void onBufferedAmountChange(long previousAmount) {
					System.out.println("WebRTCClient.startInternal().new Observer() {...}.onBufferedAmountChange()");
					
				}
			});

Client side, received the callback ondatachannel method as follows.

thiz.remotePeerConnection[streamId].ondatachannel = function(ev) {
				ev.channel.onopen = function() {
					console.log('Data channel is open and ready to be used.');
				};

				ev.channel.onmessage = function(event) {
					console.log('Data Channel OnMessage ');
				}
				ev.channel.onclose = () => {
					console.log("The Data Channel is Closed");
				};

				ev.channel.onerror = (error) => {
					console.log("Data Channel Error:", error);
				};
			}

@mekya mekya closed this as completed May 5, 2020
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