First let me tell you that you can use Kandy js sdk, you can find about it here : https://developer.kandy.io/, I didn't test it but it looks very promising and provides many of the features you need.
In case you want to do it on your own(or you're just curious), WebSockets is the main gamer here.
Http protocol as you should know by now is a request-response protocol, the client make a request to the server and the server responds.
But sometimes we want the server to talk to the client in which we can use SSE(Server-Sent events), in other times we want to create a connection between the server and the client and we want both to be able to send to it and receive from it, that's what WebSockets are made for.
In your usecase you could have two strategies : peer-to-peer or centralized, in centralized strategy when user X wants to send something to user Y it has to first send it to the server and the server sends it to user Y.
For this you need websockets, you create a connection between user X and the server and another between the Server and user Y, you send the file from user X to the connection, the server then sends it through the other connection to user Y, user Y can send a new file to the Server so that the Server sends it to user X, and so on so goes.
From this you can conclude that Websockets has server part and client part, normally we launch websockets server that is different than the web server serving the application(both can be on the same Server computer or in different computers), if you don't want to bring your own server you can look at pusher : https://pusher.com/.
Pusher is a cloud service that provide sdks for many languages including javascript, in case you want to have your own server I can't talk about the server-side part of your problem because your question is a javascript question, for the client-part have a look at socket.io, this provides the client part as well as node server part but you can use the client part in case you don't want to use node for the server.
In case you want to build peer-to-peer connections, you can look at simple-peer.