merge master into branch

This commit is contained in:
schlagmichdoch 2023-03-03 18:01:24 +01:00
commit c0a4224a59
13 changed files with 587 additions and 493 deletions

View file

@ -36,6 +36,7 @@ class ServerConnection {
_onOpen() {
console.log('WS: server connected');
Events.fire('ws-connected');
if (this._isReconnect) Events.fire('notify-user', 'Connected.');
}
_sendRoomSecrets(roomSecrets) {
@ -152,15 +153,17 @@ class ServerConnection {
this._socket.close();
this._socket = null;
Events.fire('ws-disconnected');
this._isReconnect = true;
}
}
_onDisconnect() {
console.log('WS: server disconnected');
Events.fire('notify-user', 'No server connection. Retry in 5s...');
Events.fire('notify-user', 'Connecting..');
clearTimeout(this._reconnectTimer);
this._reconnectTimer = setTimeout(_ => this._connect(), 5000);
Events.fire('ws-disconnected');
this._isReconnect = true;
}
_onVisibilityChange() {
@ -326,26 +329,25 @@ class Peer {
this._onChunkReceived(message);
return;
}
message = JSON.parse(message);
console.log('RTC:', message);
switch (message.type) {
const messageJSON = JSON.parse(message);
switch (messageJSON.type) {
case 'request':
this._onFilesTransferRequest(message);
this._onFilesTransferRequest(messageJSON);
break;
case 'header':
this._onFilesHeader(message);
this._onFilesHeader(messageJSON);
break;
case 'partition':
this._onReceivedPartitionEnd(message);
this._onReceivedPartitionEnd(messageJSON);
break;
case 'partition-received':
this._sendNextPartition();
break;
case 'progress':
this._onDownloadProgress(message.progress);
this._onDownloadProgress(messageJSON.progress);
break;
case 'files-transfer-response':
this._onFileTransferRequestResponded(message);
this._onFileTransferRequestResponded(messageJSON);
break;
case 'file-transfer-complete':
this._onFileTransferCompleted();
@ -354,7 +356,7 @@ class Peer {
this._onMessageTransferCompleted();
break;
case 'text':
this._onTextReceived(message);
this._onTextReceived(messageJSON);
break;
}
}
@ -448,7 +450,7 @@ class Peer {
if (!this._requestAccepted.header.length) {
this._busy = false;
Events.fire('set-progress', {peerId: this._peerId, progress: 0, status: 'process'});
Events.fire('files-received', {sender: this._peerId, files: this._filesReceived, request: this._requestAccepted});
Events.fire('files-received', {sender: this._peerId, files: this._filesReceived, imagesOnly: this._requestAccepted.imagesOnly, totalSize: this._requestAccepted.totalSize});
this._filesReceived = [];
this._requestAccepted = null;
}
@ -499,6 +501,7 @@ class RTCPeer extends Peer {
constructor(serverConnection, peerId, roomType, roomSecret) {
super(serverConnection, peerId, roomType, roomSecret);
this.rtcSupported = true;
if (!peerId) return; // we will listen for a caller
this._connect(peerId, true);
}
@ -575,6 +578,13 @@ class RTCPeer extends Peer {
this._channel = channel;
}
_onMessage(message) {
if (typeof message === 'string') {
console.log('RTC:', JSON.parse(message));
}
super._onMessage(message);
}
getConnectionHash() {
const localDescriptionLines = this._conn.localDescription.sdp.split("\r\n");
const remoteDescriptionLines = this._conn.remoteDescription.sdp.split("\r\n");