1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-30 05:31:07 +02:00

WebRTC JS module

This commit is contained in:
Alexandre Iooss
2020-10-21 22:10:39 +02:00
parent 0b3fb87fa2
commit 9d162b13ed
4 changed files with 128 additions and 89 deletions

View File

@ -13,7 +13,6 @@ export class GsWebSocket {
/**
* Open websocket.
*
* @param {Function} openCallback Function called when connection is established.
* @param {Function} closeCallback Function called when connection is lost.
*/
@ -34,19 +33,31 @@ export class GsWebSocket {
/**
* Exchange WebRTC session description with server.
*
* @param {string} data JSON formated data
* @param {Function} receiveCallback Function called when data is received
* @param {SessionDescription} localDescription WebRTC local SDP
* @param {string} stream Name of the stream
* @param {string} quality Requested quality
*/
exchangeDescription(data, receiveCallback) {
sendDescription(localDescription, stream, quality) {
if (this.socket.readyState !== 1) {
console.log("WebSocket not ready to send data");
return;
}
this.socket.send(data);
this.socket.send(JSON.stringify({
"webRtcSdp": localDescription,
"stream": stream,
"quality": quality
}));
}
/**
* Set callback function on new session description.
* @param {Function} callback Function called when data is received
*/
onDescription(callback) {
this.socket.addEventListener("message", (event) => {
// FIXME: json to session description
console.log("Message from server ", event.data);
receiveCallback(event);
callback(event.data);
});
}
}