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

feat: Notification based BufferedDataConnection #1143

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ProPablo
Copy link

@ProPablo ProPablo commented Sep 24, 2023

I have the use case of Datachannel of trying to send files from one client to the other. The speed is not particularly an issue anymore but I would still like to have Notifications/events for when a chunk is complete to create Progress Bars.

This PR addresses that. If connecting with the serialization 'notify', the Dataconnection will emit an additional event for when a chunk is done sending. The user can subscribe to this and use the information as they please. An example of this is:

var arr = await inputFile.arrayBuffer();
const blob = new Blob([inputFile]);
const nextId = conn.nextID;

conn.on('sentChunk', (chunk) => {
	if (chunk.id === nextId) {
		console.log('Sent chunk', chunk);
		if (chunk.n == chunk.total - 1) {
			console.log('Sent last chunk');
		}
	}
});
conn.send(arr);

I also have some ideas on what to do for the other Stream based serializations so I have kept the events in the base DataConnection without implementing these events. But BufferedDataConnection has got me covered nicely so far :)

I was thinking of adding a callback based api but favoured the event driven approach since I found it aligned well with what you guys were doing already.

Haven't made tests since I couldn't get them to work on my machine but I tried it with a personal example extensively, can give more examples if necessary, some of which reside in my continuation of #1075.

Thank you for your work and I hope this is useful to somebody as well

@ProPablo ProPablo changed the title Notification based BufferedDataConnection feat: Notification based BufferedDataConnection Sep 24, 2023
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