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

Added support for data channel subprotocol #2157

Merged
merged 1 commit into from
May 19, 2020
Merged

Added support for data channel subprotocol #2157

merged 1 commit into from
May 19, 2020

Conversation

lminiero
Copy link
Member

This is actually a subset of #1898, which is where we implemented support for real-time text to the SIP plugin using data channels. Per the standard, RTT on data channels requires a dedicated subprotocol, and since we didn't support it in Janus, that PR also implemented that part. That said, this feature doesn't really need to be tied to that effort, so I decided to make a separate PR instead, that we could merge sooner.

It's important to point out that the subprotocol is used when a new channel is created, and is not something you can change dynamically after a specific channel has been created. As such, you should always use it in conjunction with a label: this way, if the label doesn't exist, a new channel for it will be created, and the subprotocol you specified be assigned to it and used for all messages exchanged on it.

At the moment this only implements support for the feature, but no plugin really makes use of it. Anyway, it's easy to test with the EchoTest, since if you send data channel messages to that plugin with a specific label and opening a new channel with a specific subprotocol, it will use it for the response as well. As such, you can modify the echotest.js code like this:

function sendData() {
	var data = $('#datasend').val();
	if(data === "") {
		bootbox.alert('Insert a message to send on the DataChannel');
		return;
	}
	echotest.data({
		text: data,
		label: "new-channel",		// <--- let's use a custom channel, as protocol is
		protocol: "my-subprotocol",	// <--- only used when a new channel is opened
		error: function(reason) { bootbox.alert(reason); },
		success: function() { $('#datasend').val(''); },
	});
}

and you should see the response coming from the label you specified, and on the subprotocol used for the new channel. The same can be done from a plugin code as well, by properly setting the protocol in the janus_plugin_data structure:

janus_plugin_data data = {
	.label = "new-channel",
	.protocol = "my-subprotocol",
	.binary = FALSE,
	.buffer = text,
	.length = strlen(text)
};
gateway->relay_data(handle, &data);

@lminiero
Copy link
Member Author

Merging.

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

Successfully merging this pull request may close these issues.

None yet

1 participant