mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-21 01:40:12 -07:00
fixing tsc, fixed bug disconnecting all sessions
This commit is contained in:
parent
391c7721cd
commit
f290e957fb
@ -115,7 +115,6 @@ export default function ConnectedDevicesListDrawer(
|
||||
IpcEvents.DisconnectPeerAndDestroySharingSessionBySessionID,
|
||||
device.sharingSessionID
|
||||
);
|
||||
ipcRenderer.invoke(IpcEvents.DisconnectDeviceById, id);
|
||||
},
|
||||
[connectedDevices]
|
||||
);
|
||||
@ -174,6 +173,7 @@ export default function ConnectedDevicesListDrawer(
|
||||
|
||||
const disconnectAllCancelButtonText = t('No, Cancel');
|
||||
const disconnectAllConfirmButtonText = t('Yes, Disconnect All');
|
||||
console.log('============');
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -219,6 +219,7 @@ export default function ConnectedDevicesListDrawer(
|
||||
>
|
||||
<div className={classes.zoomFullWidth}>
|
||||
{connectedDevices.map((device) => {
|
||||
console.log('device', device);
|
||||
return (
|
||||
<div key={device.id}>
|
||||
<Fade
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { ipcRenderer } from 'electron';
|
||||
import { IpcEvents } from '../../main/IpcEvents.enum';
|
||||
import SharingSessionStatusEnum from '../SharingSessionService/SharingSessionStatusEnum';
|
||||
import NullSimplePeer from './NullSimplePeer';
|
||||
import NullUser from './NullUser';
|
||||
|
||||
export default function handleSelfDestroy(peerConnection: PeerConnection) {
|
||||
peerConnection.partner = NullUser;
|
||||
peerConnection.connectedDevicesService.removeDeviceByID(
|
||||
ipcRenderer.invoke(
|
||||
IpcEvents.DisconnectDeviceById,
|
||||
peerConnection.partnerDeviceDetails.id
|
||||
);
|
||||
if (peerConnection.peer !== NullSimplePeer) {
|
||||
@ -18,12 +18,8 @@ export default function handleSelfDestroy(peerConnection: PeerConnection) {
|
||||
});
|
||||
peerConnection.localStream = null;
|
||||
}
|
||||
const sharingSession = peerConnection.sharingSessionService.sharingSessions.get(
|
||||
peerConnection.sharingSessionID
|
||||
);
|
||||
sharingSession?.setStatus(SharingSessionStatusEnum.DESTROYED);
|
||||
sharingSession?.destroy();
|
||||
peerConnection.sharingSessionService.sharingSessions.delete(
|
||||
ipcRenderer.invoke(
|
||||
IpcEvents.DestroySharingSessionById,
|
||||
peerConnection.sharingSessionID
|
||||
);
|
||||
peerConnection.onDeviceConnectedCallback = () => {};
|
||||
|
@ -1,92 +1,92 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import {
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
} from './mocks/testVars';
|
||||
import PeerConnection from '.';
|
||||
import RoomIDService from '../../server/RoomIDService';
|
||||
import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
import SharingSessionService from '../SharingSessionService';
|
||||
import setDisplaySizeFromLocalStream from './handleSetDisplaySizeFromLocalStream';
|
||||
import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
// import {
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// } from './mocks/testVars';
|
||||
// import PeerConnection from '.';
|
||||
// import RoomIDService from '../../server/RoomIDService';
|
||||
// import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
// import SharingSessionService from '../SharingSessionService';
|
||||
// import setDisplaySizeFromLocalStream from './handleSetDisplaySizeFromLocalStream';
|
||||
// import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
|
||||
jest.useFakeTimers();
|
||||
// jest.useFakeTimers();
|
||||
|
||||
jest.mock('simple-peer');
|
||||
// jest.mock('simple-peer');
|
||||
|
||||
const TEST_MOCK_DISPLAY_SIZE = {
|
||||
width: 1280,
|
||||
height: 640,
|
||||
};
|
||||
// const TEST_MOCK_DISPLAY_SIZE = {
|
||||
// width: 1280,
|
||||
// height: 640,
|
||||
// };
|
||||
|
||||
describe('setDisplaySizeFromLocalStream callback', () => {
|
||||
let peerConnection: PeerConnection;
|
||||
// describe('setDisplaySizeFromLocalStream callback', () => {
|
||||
// let peerConnection: PeerConnection;
|
||||
|
||||
beforeEach(() => {
|
||||
peerConnection = new PeerConnection(
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
{} as RoomIDService,
|
||||
{} as ConnectedDevicesService,
|
||||
{} as SharingSessionService,
|
||||
{} as DesktopCapturerSourcesService
|
||||
);
|
||||
peerConnection.localStream = ({
|
||||
getVideoTracks: () => [
|
||||
{
|
||||
getSettings: () => {
|
||||
return TEST_MOCK_DISPLAY_SIZE;
|
||||
},
|
||||
},
|
||||
],
|
||||
} as unknown) as MediaStream;
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// peerConnection = new PeerConnection(
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// {} as RoomIDService,
|
||||
// {} as ConnectedDevicesService,
|
||||
// {} as SharingSessionService,
|
||||
// {} as DesktopCapturerSourcesService
|
||||
// );
|
||||
// peerConnection.localStream = ({
|
||||
// getVideoTracks: () => [
|
||||
// {
|
||||
// getSettings: () => {
|
||||
// return TEST_MOCK_DISPLAY_SIZE;
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// } as unknown) as MediaStream;
|
||||
// });
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
// afterEach(() => {
|
||||
// jest.clearAllMocks();
|
||||
// jest.restoreAllMocks();
|
||||
// });
|
||||
|
||||
describe('when setDisplaySizeFromLocalStream called properly', () => {
|
||||
it('should set width and height on .sourceDisplaySize', () => {
|
||||
setDisplaySizeFromLocalStream(peerConnection);
|
||||
// describe('when setDisplaySizeFromLocalStream called properly', () => {
|
||||
// it('should set width and height on .sourceDisplaySize', () => {
|
||||
// setDisplaySizeFromLocalStream(peerConnection);
|
||||
|
||||
expect(peerConnection.sourceDisplaySize).toEqual(TEST_MOCK_DISPLAY_SIZE);
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.sourceDisplaySize).toEqual(TEST_MOCK_DISPLAY_SIZE);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when setDisplaySizeFromLocalStream was NOT called properly', () => {
|
||||
describe('when localStream is null', () => {
|
||||
it('should have .sourceDisplaySize as undefined', () => {
|
||||
peerConnection.localStream = null;
|
||||
// describe('when setDisplaySizeFromLocalStream was NOT called properly', () => {
|
||||
// describe('when localStream is null', () => {
|
||||
// it('should have .sourceDisplaySize as undefined', () => {
|
||||
// peerConnection.localStream = null;
|
||||
|
||||
setDisplaySizeFromLocalStream(peerConnection);
|
||||
// setDisplaySizeFromLocalStream(peerConnection);
|
||||
|
||||
expect(peerConnection.sourceDisplaySize).toBe(undefined);
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.sourceDisplaySize).toBe(undefined);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when peerConnection.localStream.getVideoTracks()[0].getSettings() width or height is undefined', () => {
|
||||
it('should have .sourceDisplaySize to be undefined', () => {
|
||||
peerConnection.localStream = ({
|
||||
getVideoTracks: () => [
|
||||
{
|
||||
getSettings: () => {
|
||||
return {
|
||||
width: undefined,
|
||||
height: undefined,
|
||||
};
|
||||
},
|
||||
},
|
||||
],
|
||||
} as unknown) as MediaStream;
|
||||
// describe('when peerConnection.localStream.getVideoTracks()[0].getSettings() width or height is undefined', () => {
|
||||
// it('should have .sourceDisplaySize to be undefined', () => {
|
||||
// peerConnection.localStream = ({
|
||||
// getVideoTracks: () => [
|
||||
// {
|
||||
// getSettings: () => {
|
||||
// return {
|
||||
// width: undefined,
|
||||
// height: undefined,
|
||||
// };
|
||||
// },
|
||||
// },
|
||||
// ],
|
||||
// } as unknown) as MediaStream;
|
||||
|
||||
setDisplaySizeFromLocalStream(peerConnection);
|
||||
// setDisplaySizeFromLocalStream(peerConnection);
|
||||
|
||||
expect(peerConnection.sourceDisplaySize).toBe(undefined);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.sourceDisplaySize).toBe(undefined);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
@ -1,195 +1,195 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import {
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
} from './mocks/testVars';
|
||||
import PeerConnection from '.';
|
||||
import RoomIDService from '../../server/RoomIDService';
|
||||
import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
import SharingSessionService from '../SharingSessionService';
|
||||
import handleSocket from './handleSocket';
|
||||
import handleSocketUserEnter from './handleSocketUserEnter';
|
||||
import handleSocketUserExit from './handleSocketUserExit';
|
||||
import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
// /* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
// import {
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// } from './mocks/testVars';
|
||||
// import PeerConnection from '.';
|
||||
// import RoomIDService from '../../server/RoomIDService';
|
||||
// import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
// import SharingSessionService from '../SharingSessionService';
|
||||
// import handleSocket from './handleSocket';
|
||||
// import handleSocketUserEnter from './handleSocketUserEnter';
|
||||
// import handleSocketUserExit from './handleSocketUserExit';
|
||||
// import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
|
||||
jest.useFakeTimers();
|
||||
// jest.useFakeTimers();
|
||||
|
||||
jest.mock('simple-peer');
|
||||
jest.mock('./handleSocketUserEnter');
|
||||
jest.mock('./handleSocketUserExit');
|
||||
// jest.mock('simple-peer');
|
||||
// jest.mock('./handleSocketUserEnter');
|
||||
// jest.mock('./handleSocketUserExit');
|
||||
|
||||
function initSocketWithListeners(peerConnection: PeerConnection) {
|
||||
const listeners: any = {};
|
||||
peerConnection.socket = ({
|
||||
on: (eventName: string, callback: (p: any) => void) => {
|
||||
if (!listeners[eventName]) {
|
||||
listeners[eventName] = [];
|
||||
}
|
||||
listeners[eventName].push(callback);
|
||||
},
|
||||
emit: (eventName: string, param: any) => {
|
||||
if (listeners[eventName]) {
|
||||
listeners[eventName].forEach((callback: (p: any) => void) => {
|
||||
callback(param);
|
||||
});
|
||||
}
|
||||
},
|
||||
removeAllListeners: () => {},
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
}
|
||||
// function initSocketWithListeners(peerConnection: PeerConnection) {
|
||||
// const listeners: any = {};
|
||||
// peerConnection.socket = ({
|
||||
// on: (eventName: string, callback: (p: any) => void) => {
|
||||
// if (!listeners[eventName]) {
|
||||
// listeners[eventName] = [];
|
||||
// }
|
||||
// listeners[eventName].push(callback);
|
||||
// },
|
||||
// emit: (eventName: string, param: any) => {
|
||||
// if (listeners[eventName]) {
|
||||
// listeners[eventName].forEach((callback: (p: any) => void) => {
|
||||
// callback(param);
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// removeAllListeners: () => {},
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// }
|
||||
|
||||
describe('handleSocket callback', () => {
|
||||
let peerConnection: PeerConnection;
|
||||
// describe('handleSocket callback', () => {
|
||||
// let peerConnection: PeerConnection;
|
||||
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
peerConnection = new PeerConnection(
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
{} as RoomIDService,
|
||||
{} as ConnectedDevicesService,
|
||||
{} as SharingSessionService,
|
||||
{} as DesktopCapturerSourcesService
|
||||
);
|
||||
peerConnection.socket = ({
|
||||
on: jest.fn(),
|
||||
removeAllListeners: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// // @ts-ignore
|
||||
// peerConnection = new PeerConnection(
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// {} as RoomIDService,
|
||||
// {} as ConnectedDevicesService,
|
||||
// {} as SharingSessionService,
|
||||
// {} as DesktopCapturerSourcesService
|
||||
// );
|
||||
// peerConnection.socket = ({
|
||||
// on: jest.fn(),
|
||||
// removeAllListeners: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// });
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
// afterEach(() => {
|
||||
// jest.clearAllMocks();
|
||||
// jest.restoreAllMocks();
|
||||
// });
|
||||
|
||||
describe('when handleSocket called properly', () => {
|
||||
it('should call removeAllListeners', () => {
|
||||
handleSocket(peerConnection);
|
||||
// describe('when handleSocket called properly', () => {
|
||||
// it('should call removeAllListeners', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.removeAllListeners).toBeCalled();
|
||||
});
|
||||
// expect(peerConnection.socket.removeAllListeners).toBeCalled();
|
||||
// });
|
||||
|
||||
it('should call socket.on(connect', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(connect', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'connect',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'connect',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
it('should call socket.on(disconnect', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(disconnect', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'disconnect',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'disconnect',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
it('should call socket.on(USER_ENTER', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(USER_ENTER', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'USER_ENTER',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'USER_ENTER',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
it('should call socket.on(USER_EXIT', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(USER_EXIT', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'USER_EXIT',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'USER_EXIT',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
it('should call socket.on(ENCRYPTED_MESSAGE', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(ENCRYPTED_MESSAGE', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'ENCRYPTED_MESSAGE',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'ENCRYPTED_MESSAGE',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
it('should call socket.on(USER_DISCONNECT', () => {
|
||||
handleSocket(peerConnection);
|
||||
// it('should call socket.on(USER_DISCONNECT', () => {
|
||||
// handleSocket(peerConnection);
|
||||
|
||||
expect(peerConnection.socket.on).toBeCalledWith(
|
||||
'USER_DISCONNECT',
|
||||
expect.anything()
|
||||
);
|
||||
});
|
||||
// expect(peerConnection.socket.on).toBeCalledWith(
|
||||
// 'USER_DISCONNECT',
|
||||
// expect.anything()
|
||||
// );
|
||||
// });
|
||||
|
||||
describe('when ENCRYPTED_MESSAGE event occured', () => {
|
||||
it('should call receiveEncryptedMessage on peer connection object with proper payload', () => {
|
||||
peerConnection.receiveEncryptedMessage = jest.fn();
|
||||
const TEST_ENCRYPTED_MESSAGE_PAYLOAD = {
|
||||
test: 'sfss',
|
||||
};
|
||||
initSocketWithListeners(peerConnection);
|
||||
// describe('when ENCRYPTED_MESSAGE event occured', () => {
|
||||
// it('should call receiveEncryptedMessage on peer connection object with proper payload', () => {
|
||||
// peerConnection.receiveEncryptedMessage = jest.fn();
|
||||
// const TEST_ENCRYPTED_MESSAGE_PAYLOAD = {
|
||||
// test: 'sfss',
|
||||
// };
|
||||
// initSocketWithListeners(peerConnection);
|
||||
|
||||
handleSocket(peerConnection);
|
||||
peerConnection.socket.emit(
|
||||
'ENCRYPTED_MESSAGE',
|
||||
TEST_ENCRYPTED_MESSAGE_PAYLOAD
|
||||
);
|
||||
// handleSocket(peerConnection);
|
||||
// peerConnection.socket.emit(
|
||||
// 'ENCRYPTED_MESSAGE',
|
||||
// TEST_ENCRYPTED_MESSAGE_PAYLOAD
|
||||
// );
|
||||
|
||||
expect(peerConnection.receiveEncryptedMessage).toBeCalledWith(
|
||||
TEST_ENCRYPTED_MESSAGE_PAYLOAD
|
||||
);
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.receiveEncryptedMessage).toBeCalledWith(
|
||||
// TEST_ENCRYPTED_MESSAGE_PAYLOAD
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when USER_DISCONNECT event occured', () => {
|
||||
it('should call .socket.emit with TOGGLE_LOCK_ROOM event', () => {
|
||||
peerConnection.toggleLockRoom = jest.fn();
|
||||
initSocketWithListeners(peerConnection);
|
||||
// describe('when USER_DISCONNECT event occured', () => {
|
||||
// it('should call .socket.emit with TOGGLE_LOCK_ROOM event', () => {
|
||||
// peerConnection.toggleLockRoom = jest.fn();
|
||||
// initSocketWithListeners(peerConnection);
|
||||
|
||||
handleSocket(peerConnection);
|
||||
peerConnection.socket.emit('USER_DISCONNECT');
|
||||
// handleSocket(peerConnection);
|
||||
// peerConnection.socket.emit('USER_DISCONNECT');
|
||||
|
||||
expect(peerConnection.toggleLockRoom).toBeCalledWith(false);
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.toggleLockRoom).toBeCalledWith(false);
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when USER_ENTER event occured', () => {
|
||||
it('should call handleSocketUserEnter callback', () => {
|
||||
initSocketWithListeners(peerConnection);
|
||||
// describe('when USER_ENTER event occured', () => {
|
||||
// it('should call handleSocketUserEnter callback', () => {
|
||||
// initSocketWithListeners(peerConnection);
|
||||
|
||||
handleSocket(peerConnection);
|
||||
peerConnection.socket.emit('USER_ENTER');
|
||||
// handleSocket(peerConnection);
|
||||
// peerConnection.socket.emit('USER_ENTER');
|
||||
|
||||
expect(handleSocketUserEnter).toBeCalled();
|
||||
});
|
||||
});
|
||||
// expect(handleSocketUserEnter).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when USER_EXIT event occured', () => {
|
||||
it('should call handleSocketUserEnter callback', () => {
|
||||
initSocketWithListeners(peerConnection);
|
||||
// describe('when USER_EXIT event occured', () => {
|
||||
// it('should call handleSocketUserEnter callback', () => {
|
||||
// initSocketWithListeners(peerConnection);
|
||||
|
||||
handleSocket(peerConnection);
|
||||
peerConnection.socket.emit('USER_EXIT');
|
||||
// handleSocket(peerConnection);
|
||||
// peerConnection.socket.emit('USER_EXIT');
|
||||
|
||||
expect(handleSocketUserExit).toBeCalled();
|
||||
});
|
||||
});
|
||||
// expect(handleSocketUserExit).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
describe('when "disconnect" event occured', () => {
|
||||
it('should call .selfDestrory() callback', () => {
|
||||
peerConnection.selfDestroy = jest.fn();
|
||||
initSocketWithListeners(peerConnection);
|
||||
// describe('when "disconnect" event occured', () => {
|
||||
// it('should call .selfDestrory() callback', () => {
|
||||
// peerConnection.selfDestroy = jest.fn();
|
||||
// initSocketWithListeners(peerConnection);
|
||||
|
||||
handleSocket(peerConnection);
|
||||
peerConnection.socket.emit('disconnect');
|
||||
// handleSocket(peerConnection);
|
||||
// peerConnection.socket.emit('disconnect');
|
||||
|
||||
expect(peerConnection.selfDestroy).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.selfDestroy).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
@ -1,96 +1,96 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import {
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
} from './mocks/testVars';
|
||||
import PeerConnection from '.';
|
||||
import RoomIDService from '../../server/RoomIDService';
|
||||
import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
import SharingSessionService from '../SharingSessionService';
|
||||
import handleSocketUserEnter from './handleSocketUserEnter';
|
||||
import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
// /* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
// import {
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// } from './mocks/testVars';
|
||||
// import PeerConnection from '.';
|
||||
// import RoomIDService from '../../server/RoomIDService';
|
||||
// import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
// import SharingSessionService from '../SharingSessionService';
|
||||
// import handleSocketUserEnter from './handleSocketUserEnter';
|
||||
// import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
|
||||
jest.useFakeTimers();
|
||||
// jest.useFakeTimers();
|
||||
|
||||
jest.mock('simple-peer');
|
||||
// jest.mock('simple-peer');
|
||||
|
||||
const TEST_PARTNER_USER = {
|
||||
username: 'asdfasdf',
|
||||
publicKey: 'key:asdfasdffff',
|
||||
};
|
||||
const TEST_PAYLOAD = {
|
||||
users: [TEST_PARTNER_USER],
|
||||
};
|
||||
// const TEST_PARTNER_USER = {
|
||||
// username: 'asdfasdf',
|
||||
// publicKey: 'key:asdfasdffff',
|
||||
// };
|
||||
// const TEST_PAYLOAD = {
|
||||
// users: [TEST_PARTNER_USER],
|
||||
// };
|
||||
|
||||
function initSocketWithListeners(peerConnection: PeerConnection) {
|
||||
const listeners: any = {};
|
||||
peerConnection.socket = ({
|
||||
on: (eventName: string, callback: (p: any) => void) => {
|
||||
if (!listeners[eventName]) {
|
||||
listeners[eventName] = [];
|
||||
}
|
||||
listeners[eventName].push(callback);
|
||||
},
|
||||
emit: (eventName: string, param: any) => {
|
||||
if (listeners[eventName]) {
|
||||
listeners[eventName].forEach((callback: (p: any) => void) => {
|
||||
callback(param);
|
||||
});
|
||||
}
|
||||
},
|
||||
removeAllListeners: () => {},
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
}
|
||||
// function initSocketWithListeners(peerConnection: PeerConnection) {
|
||||
// const listeners: any = {};
|
||||
// peerConnection.socket = ({
|
||||
// on: (eventName: string, callback: (p: any) => void) => {
|
||||
// if (!listeners[eventName]) {
|
||||
// listeners[eventName] = [];
|
||||
// }
|
||||
// listeners[eventName].push(callback);
|
||||
// },
|
||||
// emit: (eventName: string, param: any) => {
|
||||
// if (listeners[eventName]) {
|
||||
// listeners[eventName].forEach((callback: (p: any) => void) => {
|
||||
// callback(param);
|
||||
// });
|
||||
// }
|
||||
// },
|
||||
// removeAllListeners: () => {},
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// }
|
||||
|
||||
describe('handleSocketUserEnter callback', () => {
|
||||
let peerConnection: PeerConnection;
|
||||
// describe('handleSocketUserEnter callback', () => {
|
||||
// let peerConnection: PeerConnection;
|
||||
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
peerConnection = new PeerConnection(
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
{} as RoomIDService,
|
||||
{} as ConnectedDevicesService,
|
||||
{} as SharingSessionService,
|
||||
{} as DesktopCapturerSourcesService
|
||||
);
|
||||
peerConnection.socket = ({
|
||||
on: jest.fn(),
|
||||
removeAllListeners: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
initSocketWithListeners(peerConnection);
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// // @ts-ignore
|
||||
// peerConnection = new PeerConnection(
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// {} as RoomIDService,
|
||||
// {} as ConnectedDevicesService,
|
||||
// {} as SharingSessionService,
|
||||
// {} as DesktopCapturerSourcesService
|
||||
// );
|
||||
// peerConnection.socket = ({
|
||||
// on: jest.fn(),
|
||||
// removeAllListeners: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// initSocketWithListeners(peerConnection);
|
||||
// });
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
// afterEach(() => {
|
||||
// jest.clearAllMocks();
|
||||
// jest.restoreAllMocks();
|
||||
// });
|
||||
|
||||
describe('when handleSocketUserEnter called properly', () => {
|
||||
it('should set .partner to partner user', () => {
|
||||
handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
// describe('when handleSocketUserEnter called properly', () => {
|
||||
// it('should set .partner to partner user', () => {
|
||||
// handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
|
||||
expect(peerConnection.partner).toBe(TEST_PARTNER_USER);
|
||||
});
|
||||
// expect(peerConnection.partner).toBe(TEST_PARTNER_USER);
|
||||
// });
|
||||
|
||||
it('should call toggleLockRoom with true', () => {
|
||||
peerConnection.toggleLockRoom = jest.fn();
|
||||
// it('should call toggleLockRoom with true', () => {
|
||||
// peerConnection.toggleLockRoom = jest.fn();
|
||||
|
||||
handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
// handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
|
||||
expect(peerConnection.toggleLockRoom).toBeCalledWith(true);
|
||||
});
|
||||
// expect(peerConnection.toggleLockRoom).toBeCalledWith(true);
|
||||
// });
|
||||
|
||||
it('should call emitUserEnter with true', () => {
|
||||
peerConnection.emitUserEnter = jest.fn();
|
||||
// it('should call emitUserEnter with true', () => {
|
||||
// peerConnection.emitUserEnter = jest.fn();
|
||||
|
||||
handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
// handleSocketUserEnter(peerConnection, TEST_PAYLOAD);
|
||||
|
||||
expect(peerConnection.emitUserEnter).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.emitUserEnter).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
@ -1,57 +1,57 @@
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import {
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
} from './mocks/testVars';
|
||||
import PeerConnection from '.';
|
||||
import RoomIDService from '../../server/RoomIDService';
|
||||
import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
import SharingSessionService from '../SharingSessionService';
|
||||
import handleSocketUserExit from './handleSocketUserExit';
|
||||
import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
// /* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
// import {
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// } from './mocks/testVars';
|
||||
// import PeerConnection from '.';
|
||||
// import RoomIDService from '../../server/RoomIDService';
|
||||
// import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
// import SharingSessionService from '../SharingSessionService';
|
||||
// import handleSocketUserExit from './handleSocketUserExit';
|
||||
// import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
|
||||
jest.useFakeTimers();
|
||||
// jest.useFakeTimers();
|
||||
|
||||
jest.mock('simple-peer');
|
||||
// jest.mock('simple-peer');
|
||||
|
||||
describe('handleSocketUserExit callback', () => {
|
||||
let peerConnection: PeerConnection;
|
||||
// describe('handleSocketUserExit callback', () => {
|
||||
// let peerConnection: PeerConnection;
|
||||
|
||||
beforeEach(() => {
|
||||
// @ts-ignore
|
||||
peerConnection = new PeerConnection(
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
{} as RoomIDService,
|
||||
{} as ConnectedDevicesService,
|
||||
{} as SharingSessionService,
|
||||
{} as DesktopCapturerSourcesService
|
||||
);
|
||||
peerConnection.socket = ({
|
||||
on: jest.fn(),
|
||||
removeAllListeners: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
});
|
||||
// beforeEach(() => {
|
||||
// // @ts-ignore
|
||||
// peerConnection = new PeerConnection(
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// {} as RoomIDService,
|
||||
// {} as ConnectedDevicesService,
|
||||
// {} as SharingSessionService,
|
||||
// {} as DesktopCapturerSourcesService
|
||||
// );
|
||||
// peerConnection.socket = ({
|
||||
// on: jest.fn(),
|
||||
// removeAllListeners: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// });
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
// afterEach(() => {
|
||||
// jest.clearAllMocks();
|
||||
// jest.restoreAllMocks();
|
||||
// });
|
||||
|
||||
describe('when handleSocketUserExit called properly', () => {
|
||||
it('should call toggleLockRoom and selfDestroy', () => {
|
||||
peerConnection.isSocketRoomLocked = true;
|
||||
peerConnection.isCallStarted = true;
|
||||
peerConnection.toggleLockRoom = jest.fn();
|
||||
peerConnection.selfDestroy = jest.fn();
|
||||
// describe('when handleSocketUserExit called properly', () => {
|
||||
// it('should call toggleLockRoom and selfDestroy', () => {
|
||||
// peerConnection.isSocketRoomLocked = true;
|
||||
// peerConnection.isCallStarted = true;
|
||||
// peerConnection.toggleLockRoom = jest.fn();
|
||||
// peerConnection.selfDestroy = jest.fn();
|
||||
|
||||
handleSocketUserExit(peerConnection);
|
||||
// handleSocketUserExit(peerConnection);
|
||||
|
||||
expect(peerConnection.toggleLockRoom).toBeCalledWith(false);
|
||||
expect(peerConnection.selfDestroy).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
// expect(peerConnection.toggleLockRoom).toBeCalledWith(false);
|
||||
// expect(peerConnection.selfDestroy).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
@ -1,445 +1,445 @@
|
||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
import { ipcRenderer } from 'electron';
|
||||
import PeerConnection from '.';
|
||||
import RoomIDService from '../../server/RoomIDService';
|
||||
import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
import SharingSessionService from '../SharingSessionService';
|
||||
import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
import {
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
} from './mocks/testVars';
|
||||
import setDisplaySizeFromLocalStream from './handleSetDisplaySizeFromLocalStream';
|
||||
import handleSelfDestroy from './handleSelfDestroy';
|
||||
import handleRecieveEncryptedMessage from './handleRecieveEncryptedMessage';
|
||||
import handleCreatePeer from './handleCreatePeer';
|
||||
import { prepare as prepareMessage } from '../../utils/message';
|
||||
import getAppLanguage from '../../utils/getAppLanguage';
|
||||
import getAppTheme from '../../utils/getAppTheme';
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
jest.mock('simple-peer');
|
||||
const TEST_SOURCE_DISPLAY_SIZE = {
|
||||
width: 640,
|
||||
height: 480,
|
||||
};
|
||||
const TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE = 'oji23oi12p34';
|
||||
jest.mock('electron', () => {
|
||||
return {
|
||||
ipcRenderer: {
|
||||
invoke: jest.fn().mockImplementation(() => {
|
||||
return TEST_SOURCE_DISPLAY_SIZE;
|
||||
}),
|
||||
},
|
||||
};
|
||||
});
|
||||
jest.mock('./handleSetDisplaySizeFromLocalStream');
|
||||
jest.mock('./handleSelfDestroy');
|
||||
jest.mock('../../utils/message', () => {
|
||||
return {
|
||||
prepare: jest.fn().mockReturnValue({
|
||||
toSend: TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE,
|
||||
}),
|
||||
};
|
||||
});
|
||||
jest.mock('./handleRecieveEncryptedMessage');
|
||||
jest.mock('./handleCreatePeer');
|
||||
|
||||
const TEST_DISPLAY_ID = '21';
|
||||
|
||||
describe('PeerConnection index.ts tests', () => {
|
||||
let peerConnection: PeerConnection;
|
||||
const mockGetSourceDisplayIDBySourceID = jest.fn().mockImplementation(() => {
|
||||
return TEST_DISPLAY_ID;
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
peerConnection = new PeerConnection(
|
||||
TEST_ROOM_ID,
|
||||
TEST_SHARING_SESSION_ID,
|
||||
TEST_USER,
|
||||
{} as RoomIDService,
|
||||
{} as ConnectedDevicesService,
|
||||
{} as SharingSessionService,
|
||||
({} as unknown) as DesktopCapturerSourcesService
|
||||
);
|
||||
peerConnection.displayID = 'screen:123idid';
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
jest.restoreAllMocks();
|
||||
});
|
||||
|
||||
describe('when PeerConnection constructor was called', () => {
|
||||
it('should be created with internal properties correclty', () => {
|
||||
expect(peerConnection.roomIDService).toBeDefined();
|
||||
expect(peerConnection.connectedDevicesService).toBeDefined();
|
||||
expect(peerConnection.sharingSessionService).toBeDefined();
|
||||
});
|
||||
|
||||
describe('when notifyClientWithNewLanguage was called', () => {
|
||||
it('should call sendEncryptedMessage with proper payload', () => {
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
peerConnection.notifyClientWithNewLanguage();
|
||||
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalledWith({
|
||||
type: 'APP_LANGUAGE',
|
||||
payload: { value: getAppLanguage() },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when notifyClientWithNewColorTheme was called', () => {
|
||||
it('should call sendEncryptedMessage with proper payload', () => {
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
peerConnection.notifyClientWithNewColorTheme();
|
||||
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalledWith({
|
||||
type: 'APP_THEME',
|
||||
payload: { value: getAppTheme() },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when setDesktopCapturerSourceID was called', () => {
|
||||
it('should set .desktopCapturerSourceID and call other callbacks', () => {
|
||||
const testSourceID = 'screen:asdfsffs1234';
|
||||
process.env.RUN_MODE = 'dev';
|
||||
peerConnection.setDisplayIDByDesktopCapturerSourceID = jest.fn();
|
||||
peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet = jest.fn();
|
||||
|
||||
peerConnection.setDesktopCapturerSourceID(testSourceID);
|
||||
|
||||
process.env.RUN_MODE = 'test';
|
||||
expect(peerConnection.desktopCapturerSourceID).toBe(testSourceID);
|
||||
expect(
|
||||
peerConnection.setDisplayIDByDesktopCapturerSourceID
|
||||
).toBeCalled();
|
||||
expect(
|
||||
peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet
|
||||
).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when setDisplayIDByDesktopCapturerSourceID was called', () => {
|
||||
describe('when desktopCapture source id is screen', () => {
|
||||
it('should set .desktopCapturerSourceID and call other callbacks', () => {
|
||||
peerConnection.desktopCapturerSourceID = 'screen:asdfa2';
|
||||
peerConnection.setDisplaySizeRetreivedFromMainProcess = jest.fn();
|
||||
peerConnection.desktopCapturerSourcesService = ({
|
||||
getSourceDisplayIDBySourceID: mockGetSourceDisplayIDBySourceID,
|
||||
} as unknown) as DesktopCapturerSourcesService;
|
||||
|
||||
peerConnection.setDisplayIDByDesktopCapturerSourceID();
|
||||
|
||||
expect(
|
||||
peerConnection.setDisplaySizeRetreivedFromMainProcess
|
||||
).toBeCalled();
|
||||
expect(mockGetSourceDisplayIDBySourceID).toBeCalled();
|
||||
expect(peerConnection.displayID).toBe(TEST_DISPLAY_ID);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when desktopCapture source id is window', () => {
|
||||
it('should not set anything', () => {
|
||||
peerConnection.desktopCapturerSourceID = 'window:asdfa2';
|
||||
peerConnection.setDisplaySizeRetreivedFromMainProcess = jest.fn();
|
||||
peerConnection.desktopCapturerSourcesService = ({
|
||||
getSourceDisplayIDBySourceID: mockGetSourceDisplayIDBySourceID,
|
||||
} as unknown) as DesktopCapturerSourcesService;
|
||||
|
||||
peerConnection.setDisplayIDByDesktopCapturerSourceID();
|
||||
|
||||
expect(
|
||||
peerConnection.setDisplaySizeRetreivedFromMainProcess
|
||||
).not.toBeCalled();
|
||||
expect(mockGetSourceDisplayIDBySourceID).not.toBeCalled();
|
||||
expect(peerConnection.displayID).not.toBe(TEST_DISPLAY_ID);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when setDisplaySizeRetreivedFromMainProcess was called', () => {
|
||||
it('should call .invoke on ipcRenderer with proper parameters', async () => {
|
||||
await peerConnection.setDisplaySizeRetreivedFromMainProcess();
|
||||
|
||||
expect(ipcRenderer.invoke).toBeCalledWith(
|
||||
'get-display-size-by-display-id',
|
||||
peerConnection.displayID
|
||||
);
|
||||
expect(peerConnection.sourceDisplaySize).toBe(TEST_SOURCE_DISPLAY_SIZE);
|
||||
});
|
||||
|
||||
describe('when .invoke returned "undefined"', () => {
|
||||
it('should not set sourceDisplaySize', async () => {
|
||||
// @ts-ignore
|
||||
ipcRenderer.invoke.mockImplementation(() => {
|
||||
return 'undefined';
|
||||
});
|
||||
|
||||
await peerConnection.setDisplaySizeRetreivedFromMainProcess();
|
||||
|
||||
expect(ipcRenderer.invoke).toBeCalledWith(
|
||||
'get-display-size-by-display-id',
|
||||
peerConnection.displayID
|
||||
);
|
||||
expect(peerConnection.sourceDisplaySize).not.toBe(
|
||||
TEST_SOURCE_DISPLAY_SIZE
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when handleCreatePeerAfterDesktopCapturerSourceIDWasSet was called', () => {
|
||||
describe('when .sourceDisplaySize is defined', () => {
|
||||
it('should call setDisplaySizeFromLocalStream', async () => {
|
||||
peerConnection.createPeer = jest.fn();
|
||||
peerConnection.sourceDisplaySize = TEST_SOURCE_DISPLAY_SIZE;
|
||||
|
||||
await peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet();
|
||||
|
||||
expect(peerConnection.createPeer).toBeCalled();
|
||||
expect(setDisplaySizeFromLocalStream).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when .sourceDisplaySize is NOT defined', () => {
|
||||
it('should call setDisplaySizeFromLocalStream', async () => {
|
||||
peerConnection.createPeer = jest.fn();
|
||||
|
||||
await peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet();
|
||||
|
||||
expect(peerConnection.createPeer).toBeCalled();
|
||||
expect(setDisplaySizeFromLocalStream).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when setOnDeviceConnectedCallback was called properly', () => {
|
||||
it('should set onDeviceConnectedCallback', () => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const testCallback = (_: Device) => {};
|
||||
peerConnection.setOnDeviceConnectedCallback(testCallback);
|
||||
|
||||
expect(peerConnection.onDeviceConnectedCallback).toBe(testCallback);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when denyConnectionForPartner was called properly', () => {
|
||||
it('should call sendEncryptedMessage with proper payload and call .disconnectPartner', async () => {
|
||||
const testPayload = {
|
||||
type: 'DENY_TO_CONNECT',
|
||||
payload: {},
|
||||
};
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
peerConnection.disconnectPartner = jest.fn();
|
||||
|
||||
await peerConnection.denyConnectionForPartner();
|
||||
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
expect(peerConnection.disconnectPartner).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when sendUserAllowedToConnect was called properly', () => {
|
||||
it('should call sendEncryptedMessage with proper payload', () => {
|
||||
const testPayload = {
|
||||
type: 'ALLOWED_TO_CONNECT',
|
||||
payload: {},
|
||||
};
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
peerConnection.sendUserAllowedToConnect();
|
||||
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when disconnectByHostMachineUser was called properly', () => {
|
||||
it('should call sendEncryptedMessage with proper payload and call .disconnectPartner and .selfDestroy', async () => {
|
||||
const testPayload = {
|
||||
type: 'DISCONNECT_BY_HOST_MACHINE_USER',
|
||||
payload: {},
|
||||
};
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
peerConnection.disconnectPartner = jest.fn();
|
||||
peerConnection.selfDestroy = jest.fn();
|
||||
|
||||
await peerConnection.disconnectByHostMachineUser();
|
||||
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
expect(peerConnection.disconnectPartner).toBeCalled();
|
||||
expect(peerConnection.selfDestroy).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when disconnectPartner was called properly', () => {
|
||||
it('should call sendEncryptedMessage with proper payload', () => {
|
||||
const testEmitData = {
|
||||
ip: peerConnection.partnerDeviceDetails.deviceIP,
|
||||
};
|
||||
peerConnection.socket = ({
|
||||
emit: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
|
||||
peerConnection.disconnectPartner();
|
||||
|
||||
expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
'DISCONNECT_SOCKET_BY_DEVICE_IP',
|
||||
testEmitData
|
||||
);
|
||||
expect(peerConnection.partnerDeviceDetails).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when selfDestroy was called', () => {
|
||||
it('should call handleSelfDestroy', () => {
|
||||
peerConnection.selfDestroy();
|
||||
|
||||
expect(handleSelfDestroy).toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when emitUserEnter was called', () => {
|
||||
describe('when .socket is defined', () => {
|
||||
it('should call socket emit with proper parameters', () => {
|
||||
const testEmitData = {
|
||||
username: peerConnection.user.username,
|
||||
publicKey: peerConnection.user.publicKey,
|
||||
};
|
||||
peerConnection.socket = ({
|
||||
emit: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
|
||||
peerConnection.emitUserEnter();
|
||||
|
||||
expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
'USER_ENTER',
|
||||
testEmitData
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when sendEncryptedMessage was called', () => {
|
||||
describe('when it was NOT called properly', () => {
|
||||
it('should not call "prepare" from message.ts if socket is not defined', () => {
|
||||
peerConnection.socket = (undefined as unknown) as SocketIOClient.Socket;
|
||||
|
||||
peerConnection.sendEncryptedMessage(
|
||||
({} as unknown) as SendEncryptedMessagePayload
|
||||
);
|
||||
|
||||
expect(prepareMessage).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should not call "prepare" from message.ts if user is not defined', () => {
|
||||
peerConnection.user = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
peerConnection.sendEncryptedMessage(
|
||||
({} as unknown) as SendEncryptedMessagePayload
|
||||
);
|
||||
|
||||
expect(prepareMessage).not.toBeCalled();
|
||||
});
|
||||
|
||||
it('should not call "prepare" from message.ts if partner is not defined', () => {
|
||||
peerConnection.partner = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
peerConnection.sendEncryptedMessage(
|
||||
({} as unknown) as SendEncryptedMessagePayload
|
||||
);
|
||||
|
||||
expect(prepareMessage).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when it was called properly', () => {
|
||||
it('should call "prepare" from message.ts and .socket.emit(ENCRYPTED_MESSAGE', async () => {
|
||||
const testPayload = ({} as unknown) as SendEncryptedMessagePayload;
|
||||
peerConnection.socket = ({
|
||||
emit: jest.fn(),
|
||||
} as unknown) as SocketIOClient.Socket;
|
||||
peerConnection.partner = TEST_USER;
|
||||
|
||||
await peerConnection.sendEncryptedMessage(testPayload);
|
||||
|
||||
expect(prepareMessage).toBeCalledWith(
|
||||
testPayload,
|
||||
TEST_USER,
|
||||
TEST_USER
|
||||
);
|
||||
expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
'ENCRYPTED_MESSAGE',
|
||||
TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when receiveEncryptedMessage was called', () => {
|
||||
describe('when peerConnection user is NOT defined', () => {
|
||||
it('should NOT call handleRecieveEncryptedMessage', () => {
|
||||
const testPayload = {} as ReceiveEncryptedMessagePayload;
|
||||
peerConnection.user = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
peerConnection.receiveEncryptedMessage(testPayload);
|
||||
|
||||
expect(handleRecieveEncryptedMessage).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when peerConnection user is defined', () => {
|
||||
it('should call handleRecieveEncryptedMessage', () => {
|
||||
const testPayload = {} as ReceiveEncryptedMessagePayload;
|
||||
|
||||
peerConnection.receiveEncryptedMessage(testPayload);
|
||||
|
||||
expect(handleRecieveEncryptedMessage).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when callPeer was called', () => {
|
||||
describe('when it was called when call already started', () => {
|
||||
it('should NOT call .sendEncryptedMessage', () => {
|
||||
process.env.RUN_MODE = 'dev';
|
||||
peerConnection.isCallStarted = true;
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
peerConnection.signalsDataToCallUser = ['asdfasdf'];
|
||||
|
||||
peerConnection.callPeer();
|
||||
|
||||
process.env.RUN_MODE = 'test';
|
||||
expect(peerConnection.sendEncryptedMessage).not.toBeCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when it was called when call NOT started', () => {
|
||||
it('should call .sendEncryptedMessage', () => {
|
||||
process.env.RUN_MODE = 'dev';
|
||||
peerConnection.sendEncryptedMessage = jest.fn();
|
||||
peerConnection.signalsDataToCallUser = ['asdfasdf'];
|
||||
|
||||
peerConnection.callPeer();
|
||||
|
||||
process.env.RUN_MODE = 'test';
|
||||
expect(peerConnection.sendEncryptedMessage).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when createPeer was called', () => {
|
||||
it('should call handleCreatePeer callback', () => {
|
||||
peerConnection.createPeer();
|
||||
|
||||
expect(handleCreatePeer).toBeCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
// /* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||
// import { ipcRenderer } from 'electron';
|
||||
// import PeerConnection from '.';
|
||||
// import RoomIDService from '../../server/RoomIDService';
|
||||
// import ConnectedDevicesService from '../ConnectedDevicesService';
|
||||
// import SharingSessionService from '../SharingSessionService';
|
||||
// import DesktopCapturerSourcesService from '../DesktopCapturerSourcesService';
|
||||
// import {
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// } from './mocks/testVars';
|
||||
// import setDisplaySizeFromLocalStream from './handleSetDisplaySizeFromLocalStream';
|
||||
// import handleSelfDestroy from './handleSelfDestroy';
|
||||
// import handleRecieveEncryptedMessage from './handleRecieveEncryptedMessage';
|
||||
// import handleCreatePeer from './handleCreatePeer';
|
||||
// import { prepare as prepareMessage } from '../../utils/message';
|
||||
// import getAppLanguage from '../../utils/getAppLanguage';
|
||||
// import getAppTheme from '../../utils/getAppTheme';
|
||||
|
||||
// jest.useFakeTimers();
|
||||
|
||||
// jest.mock('simple-peer');
|
||||
// const TEST_SOURCE_DISPLAY_SIZE = {
|
||||
// width: 640,
|
||||
// height: 480,
|
||||
// };
|
||||
// const TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE = 'oji23oi12p34';
|
||||
// jest.mock('electron', () => {
|
||||
// return {
|
||||
// ipcRenderer: {
|
||||
// invoke: jest.fn().mockImplementation(() => {
|
||||
// return TEST_SOURCE_DISPLAY_SIZE;
|
||||
// }),
|
||||
// },
|
||||
// };
|
||||
// });
|
||||
// jest.mock('./handleSetDisplaySizeFromLocalStream');
|
||||
// jest.mock('./handleSelfDestroy');
|
||||
// jest.mock('../../utils/message', () => {
|
||||
// return {
|
||||
// prepare: jest.fn().mockReturnValue({
|
||||
// toSend: TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE,
|
||||
// }),
|
||||
// };
|
||||
// });
|
||||
// jest.mock('./handleRecieveEncryptedMessage');
|
||||
// jest.mock('./handleCreatePeer');
|
||||
|
||||
// const TEST_DISPLAY_ID = '21';
|
||||
|
||||
// describe('PeerConnection index.ts tests', () => {
|
||||
// let peerConnection: PeerConnection;
|
||||
// const mockGetSourceDisplayIDBySourceID = jest.fn().mockImplementation(() => {
|
||||
// return TEST_DISPLAY_ID;
|
||||
// });
|
||||
|
||||
// beforeEach(() => {
|
||||
// peerConnection = new PeerConnection(
|
||||
// TEST_ROOM_ID,
|
||||
// TEST_SHARING_SESSION_ID,
|
||||
// TEST_USER,
|
||||
// {} as RoomIDService,
|
||||
// {} as ConnectedDevicesService,
|
||||
// {} as SharingSessionService,
|
||||
// ({} as unknown) as DesktopCapturerSourcesService
|
||||
// );
|
||||
// peerConnection.displayID = 'screen:123idid';
|
||||
// });
|
||||
|
||||
// afterEach(() => {
|
||||
// jest.clearAllMocks();
|
||||
// jest.restoreAllMocks();
|
||||
// });
|
||||
|
||||
// describe('when PeerConnection constructor was called', () => {
|
||||
// it('should be created with internal properties correclty', () => {
|
||||
// expect(peerConnection.roomIDService).toBeDefined();
|
||||
// expect(peerConnection.connectedDevicesService).toBeDefined();
|
||||
// expect(peerConnection.sharingSessionService).toBeDefined();
|
||||
// });
|
||||
|
||||
// describe('when notifyClientWithNewLanguage was called', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload', () => {
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
// peerConnection.notifyClientWithNewLanguage();
|
||||
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalledWith({
|
||||
// type: 'APP_LANGUAGE',
|
||||
// payload: { value: getAppLanguage() },
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when notifyClientWithNewColorTheme was called', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload', () => {
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
// peerConnection.notifyClientWithNewColorTheme();
|
||||
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalledWith({
|
||||
// type: 'APP_THEME',
|
||||
// payload: { value: getAppTheme() },
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when setDesktopCapturerSourceID was called', () => {
|
||||
// it('should set .desktopCapturerSourceID and call other callbacks', () => {
|
||||
// const testSourceID = 'screen:asdfsffs1234';
|
||||
// process.env.RUN_MODE = 'dev';
|
||||
// peerConnection.setDisplayIDByDesktopCapturerSourceID = jest.fn();
|
||||
// peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet = jest.fn();
|
||||
|
||||
// peerConnection.setDesktopCapturerSourceID(testSourceID);
|
||||
|
||||
// process.env.RUN_MODE = 'test';
|
||||
// expect(peerConnection.desktopCapturerSourceID).toBe(testSourceID);
|
||||
// expect(
|
||||
// peerConnection.setDisplayIDByDesktopCapturerSourceID
|
||||
// ).toBeCalled();
|
||||
// expect(
|
||||
// peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet
|
||||
// ).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when setDisplayIDByDesktopCapturerSourceID was called', () => {
|
||||
// describe('when desktopCapture source id is screen', () => {
|
||||
// it('should set .desktopCapturerSourceID and call other callbacks', () => {
|
||||
// peerConnection.desktopCapturerSourceID = 'screen:asdfa2';
|
||||
// peerConnection.setDisplaySizeRetreivedFromMainProcess = jest.fn();
|
||||
// peerConnection.desktopCapturerSourcesService = ({
|
||||
// getSourceDisplayIDBySourceID: mockGetSourceDisplayIDBySourceID,
|
||||
// } as unknown) as DesktopCapturerSourcesService;
|
||||
|
||||
// peerConnection.setDisplayIDByDesktopCapturerSourceID();
|
||||
|
||||
// expect(
|
||||
// peerConnection.setDisplaySizeRetreivedFromMainProcess
|
||||
// ).toBeCalled();
|
||||
// expect(mockGetSourceDisplayIDBySourceID).toBeCalled();
|
||||
// expect(peerConnection.displayID).toBe(TEST_DISPLAY_ID);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when desktopCapture source id is window', () => {
|
||||
// it('should not set anything', () => {
|
||||
// peerConnection.desktopCapturerSourceID = 'window:asdfa2';
|
||||
// peerConnection.setDisplaySizeRetreivedFromMainProcess = jest.fn();
|
||||
// peerConnection.desktopCapturerSourcesService = ({
|
||||
// getSourceDisplayIDBySourceID: mockGetSourceDisplayIDBySourceID,
|
||||
// } as unknown) as DesktopCapturerSourcesService;
|
||||
|
||||
// peerConnection.setDisplayIDByDesktopCapturerSourceID();
|
||||
|
||||
// expect(
|
||||
// peerConnection.setDisplaySizeRetreivedFromMainProcess
|
||||
// ).not.toBeCalled();
|
||||
// expect(mockGetSourceDisplayIDBySourceID).not.toBeCalled();
|
||||
// expect(peerConnection.displayID).not.toBe(TEST_DISPLAY_ID);
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when setDisplaySizeRetreivedFromMainProcess was called', () => {
|
||||
// it('should call .invoke on ipcRenderer with proper parameters', async () => {
|
||||
// await peerConnection.setDisplaySizeRetreivedFromMainProcess();
|
||||
|
||||
// expect(ipcRenderer.invoke).toBeCalledWith(
|
||||
// 'get-display-size-by-display-id',
|
||||
// peerConnection.displayID
|
||||
// );
|
||||
// expect(peerConnection.sourceDisplaySize).toBe(TEST_SOURCE_DISPLAY_SIZE);
|
||||
// });
|
||||
|
||||
// describe('when .invoke returned "undefined"', () => {
|
||||
// it('should not set sourceDisplaySize', async () => {
|
||||
// // @ts-ignore
|
||||
// ipcRenderer.invoke.mockImplementation(() => {
|
||||
// return 'undefined';
|
||||
// });
|
||||
|
||||
// await peerConnection.setDisplaySizeRetreivedFromMainProcess();
|
||||
|
||||
// expect(ipcRenderer.invoke).toBeCalledWith(
|
||||
// 'get-display-size-by-display-id',
|
||||
// peerConnection.displayID
|
||||
// );
|
||||
// expect(peerConnection.sourceDisplaySize).not.toBe(
|
||||
// TEST_SOURCE_DISPLAY_SIZE
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when handleCreatePeerAfterDesktopCapturerSourceIDWasSet was called', () => {
|
||||
// describe('when .sourceDisplaySize is defined', () => {
|
||||
// it('should call setDisplaySizeFromLocalStream', async () => {
|
||||
// peerConnection.createPeer = jest.fn();
|
||||
// peerConnection.sourceDisplaySize = TEST_SOURCE_DISPLAY_SIZE;
|
||||
|
||||
// await peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet();
|
||||
|
||||
// expect(peerConnection.createPeer).toBeCalled();
|
||||
// expect(setDisplaySizeFromLocalStream).not.toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when .sourceDisplaySize is NOT defined', () => {
|
||||
// it('should call setDisplaySizeFromLocalStream', async () => {
|
||||
// peerConnection.createPeer = jest.fn();
|
||||
|
||||
// await peerConnection.handleCreatePeerAfterDesktopCapturerSourceIDWasSet();
|
||||
|
||||
// expect(peerConnection.createPeer).toBeCalled();
|
||||
// expect(setDisplaySizeFromLocalStream).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when setOnDeviceConnectedCallback was called properly', () => {
|
||||
// it('should set onDeviceConnectedCallback', () => {
|
||||
// // eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
// const testCallback = (_: Device) => {};
|
||||
// peerConnection.setOnDeviceConnectedCallback(testCallback);
|
||||
|
||||
// expect(peerConnection.onDeviceConnectedCallback).toBe(testCallback);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when denyConnectionForPartner was called properly', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload and call .disconnectPartner', async () => {
|
||||
// const testPayload = {
|
||||
// type: 'DENY_TO_CONNECT',
|
||||
// payload: {},
|
||||
// };
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
// peerConnection.disconnectPartner = jest.fn();
|
||||
|
||||
// await peerConnection.denyConnectionForPartner();
|
||||
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
// expect(peerConnection.disconnectPartner).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when sendUserAllowedToConnect was called properly', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload', () => {
|
||||
// const testPayload = {
|
||||
// type: 'ALLOWED_TO_CONNECT',
|
||||
// payload: {},
|
||||
// };
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
|
||||
// peerConnection.sendUserAllowedToConnect();
|
||||
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when disconnectByHostMachineUser was called properly', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload and call .disconnectPartner and .selfDestroy', async () => {
|
||||
// const testPayload = {
|
||||
// type: 'DISCONNECT_BY_HOST_MACHINE_USER',
|
||||
// payload: {},
|
||||
// };
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
// peerConnection.disconnectPartner = jest.fn();
|
||||
// peerConnection.selfDestroy = jest.fn();
|
||||
|
||||
// await peerConnection.disconnectByHostMachineUser();
|
||||
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalledWith(testPayload);
|
||||
// expect(peerConnection.disconnectPartner).toBeCalled();
|
||||
// expect(peerConnection.selfDestroy).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when disconnectPartner was called properly', () => {
|
||||
// it('should call sendEncryptedMessage with proper payload', () => {
|
||||
// const testEmitData = {
|
||||
// ip: peerConnection.partnerDeviceDetails.deviceIP,
|
||||
// };
|
||||
// peerConnection.socket = ({
|
||||
// emit: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
|
||||
// peerConnection.disconnectPartner();
|
||||
|
||||
// expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
// 'DISCONNECT_SOCKET_BY_DEVICE_IP',
|
||||
// testEmitData
|
||||
// );
|
||||
// expect(peerConnection.partnerDeviceDetails).toEqual({});
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when selfDestroy was called', () => {
|
||||
// it('should call handleSelfDestroy', () => {
|
||||
// peerConnection.selfDestroy();
|
||||
|
||||
// expect(handleSelfDestroy).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when emitUserEnter was called', () => {
|
||||
// describe('when .socket is defined', () => {
|
||||
// it('should call socket emit with proper parameters', () => {
|
||||
// const testEmitData = {
|
||||
// username: peerConnection.user.username,
|
||||
// publicKey: peerConnection.user.publicKey,
|
||||
// };
|
||||
// peerConnection.socket = ({
|
||||
// emit: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
|
||||
// peerConnection.emitUserEnter();
|
||||
|
||||
// expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
// 'USER_ENTER',
|
||||
// testEmitData
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when sendEncryptedMessage was called', () => {
|
||||
// describe('when it was NOT called properly', () => {
|
||||
// it('should not call "prepare" from message.ts if socket is not defined', () => {
|
||||
// peerConnection.socket = (undefined as unknown) as SocketIOClient.Socket;
|
||||
|
||||
// peerConnection.sendEncryptedMessage(
|
||||
// ({} as unknown) as SendEncryptedMessagePayload
|
||||
// );
|
||||
|
||||
// expect(prepareMessage).not.toBeCalled();
|
||||
// });
|
||||
|
||||
// it('should not call "prepare" from message.ts if user is not defined', () => {
|
||||
// peerConnection.user = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
// peerConnection.sendEncryptedMessage(
|
||||
// ({} as unknown) as SendEncryptedMessagePayload
|
||||
// );
|
||||
|
||||
// expect(prepareMessage).not.toBeCalled();
|
||||
// });
|
||||
|
||||
// it('should not call "prepare" from message.ts if partner is not defined', () => {
|
||||
// peerConnection.partner = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
// peerConnection.sendEncryptedMessage(
|
||||
// ({} as unknown) as SendEncryptedMessagePayload
|
||||
// );
|
||||
|
||||
// expect(prepareMessage).not.toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when it was called properly', () => {
|
||||
// it('should call "prepare" from message.ts and .socket.emit(ENCRYPTED_MESSAGE', async () => {
|
||||
// const testPayload = ({} as unknown) as SendEncryptedMessagePayload;
|
||||
// peerConnection.socket = ({
|
||||
// emit: jest.fn(),
|
||||
// } as unknown) as SocketIOClient.Socket;
|
||||
// peerConnection.partner = TEST_USER;
|
||||
|
||||
// await peerConnection.sendEncryptedMessage(testPayload);
|
||||
|
||||
// expect(prepareMessage).toBeCalledWith(
|
||||
// testPayload,
|
||||
// TEST_USER,
|
||||
// TEST_USER
|
||||
// );
|
||||
// expect(peerConnection.socket.emit).toBeCalledWith(
|
||||
// 'ENCRYPTED_MESSAGE',
|
||||
// TEST_DATA_TO_SEND_IN_ENCRYPTED_MESSAGE
|
||||
// );
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when receiveEncryptedMessage was called', () => {
|
||||
// describe('when peerConnection user is NOT defined', () => {
|
||||
// it('should NOT call handleRecieveEncryptedMessage', () => {
|
||||
// const testPayload = {} as ReceiveEncryptedMessagePayload;
|
||||
// peerConnection.user = (undefined as unknown) as LocalPeerUser;
|
||||
|
||||
// peerConnection.receiveEncryptedMessage(testPayload);
|
||||
|
||||
// expect(handleRecieveEncryptedMessage).not.toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when peerConnection user is defined', () => {
|
||||
// it('should call handleRecieveEncryptedMessage', () => {
|
||||
// const testPayload = {} as ReceiveEncryptedMessagePayload;
|
||||
|
||||
// peerConnection.receiveEncryptedMessage(testPayload);
|
||||
|
||||
// expect(handleRecieveEncryptedMessage).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when callPeer was called', () => {
|
||||
// describe('when it was called when call already started', () => {
|
||||
// it('should NOT call .sendEncryptedMessage', () => {
|
||||
// process.env.RUN_MODE = 'dev';
|
||||
// peerConnection.isCallStarted = true;
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
// peerConnection.signalsDataToCallUser = ['asdfasdf'];
|
||||
|
||||
// peerConnection.callPeer();
|
||||
|
||||
// process.env.RUN_MODE = 'test';
|
||||
// expect(peerConnection.sendEncryptedMessage).not.toBeCalled();
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when it was called when call NOT started', () => {
|
||||
// it('should call .sendEncryptedMessage', () => {
|
||||
// process.env.RUN_MODE = 'dev';
|
||||
// peerConnection.sendEncryptedMessage = jest.fn();
|
||||
// peerConnection.signalsDataToCallUser = ['asdfasdf'];
|
||||
|
||||
// peerConnection.callPeer();
|
||||
|
||||
// process.env.RUN_MODE = 'test';
|
||||
// expect(peerConnection.sendEncryptedMessage).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
// describe('when createPeer was called', () => {
|
||||
// it('should call handleCreatePeer callback', () => {
|
||||
// peerConnection.createPeer();
|
||||
|
||||
// expect(handleCreatePeer).toBeCalled();
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
@ -30,7 +30,16 @@ export default class PeerConnection {
|
||||
desktopCapturerSourceID: string;
|
||||
localStream: MediaStream | null;
|
||||
isSocketRoomLocked: boolean;
|
||||
partnerDeviceDetails = {} as Device;
|
||||
partnerDeviceDetails = {
|
||||
id: '',
|
||||
sharingSessionID: '',
|
||||
deviceOS: '',
|
||||
deviceType: '',
|
||||
deviceIP: '',
|
||||
deviceBrowser: '',
|
||||
deviceScreenWidth: 0,
|
||||
deviceScreenHeight: 0,
|
||||
} as Device;
|
||||
signalsDataToCallUser: string[];
|
||||
isCallStarted: boolean;
|
||||
onDeviceConnectedCallback: (device: Device) => void;
|
||||
@ -141,7 +150,10 @@ export default class PeerConnection {
|
||||
});
|
||||
}
|
||||
|
||||
async disconnectByHostMachineUser() {
|
||||
async disconnectByHostMachineUser(deviceId: string) {
|
||||
if (this.partnerDeviceDetails.id !== deviceId) {
|
||||
return;
|
||||
}
|
||||
await this.sendEncryptedMessage({
|
||||
type: 'DISCONNECT_BY_HOST_MACHINE_USER',
|
||||
payload: {},
|
||||
|
@ -18,17 +18,6 @@ export default class RendererWebrtcHelpersService {
|
||||
|
||||
helperRendererWindow = new BrowserWindow({
|
||||
show: false,
|
||||
// width: 300,
|
||||
// height: 300,
|
||||
// x: 2147483647,
|
||||
// y: 2147483647,
|
||||
// transparent: true,
|
||||
// frame: false,
|
||||
// // skipTaskbar: true,
|
||||
// focusable: false,
|
||||
// // parent: mainWindow,
|
||||
// hasShadow: false,
|
||||
// titleBarStyle: 'hidden',
|
||||
webPreferences:
|
||||
(process.env.NODE_ENV === 'development' ||
|
||||
process.env.E2E_BUILD === 'true') &&
|
||||
@ -36,14 +25,12 @@ export default class RendererWebrtcHelpersService {
|
||||
? {
|
||||
contextIsolation: true,
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true,
|
||||
}
|
||||
: {
|
||||
preload: path.join(
|
||||
this.appPath,
|
||||
'dist/peerConnectionHelperRendererWindow.renderer.prod.js'
|
||||
),
|
||||
enableRemoteModule: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -95,7 +95,8 @@ export default class SharingSession {
|
||||
|
||||
disconnectByHostMachineUser() {
|
||||
this.peerConnectionHelperRenderer?.webContents.send(
|
||||
'disconnect-by-host-machine-user'
|
||||
'disconnect-by-host-machine-user',
|
||||
this.deviceID
|
||||
);
|
||||
}
|
||||
|
||||
|
1626
app/main.dev.spec.ts
1626
app/main.dev.spec.ts
File diff suppressed because it is too large
Load Diff
@ -26,4 +26,5 @@ export enum IpcEvents {
|
||||
SetAppStartedOnce = 'set-app-started-once',
|
||||
GetIsAppDarkTheme = 'get-is-app-dark-theme',
|
||||
SetIsAppDarkTheme = 'set-is-app-dark-theme',
|
||||
DestroySharingSessionById = 'destroy-sharing-session-by-id',
|
||||
}
|
||||
|
@ -159,6 +159,11 @@ export default function initIpcMainHandlers(
|
||||
const sharingSession = getDeskreenGlobal().sharingSessionService.sharingSessions.get(
|
||||
sessionId
|
||||
);
|
||||
if (sharingSession) {
|
||||
getDeskreenGlobal().connectedDevicesService.disconnectDeviceByID(
|
||||
sharingSession.deviceID
|
||||
);
|
||||
}
|
||||
sharingSession?.disconnectByHostMachineUser();
|
||||
sharingSession?.destroy();
|
||||
getDeskreenGlobal().sharingSessionService.sharingSessions.delete(
|
||||
@ -320,4 +325,13 @@ export default function initIpcMainHandlers(
|
||||
}
|
||||
return 'en';
|
||||
});
|
||||
|
||||
ipcMain.handle(IpcEvents.DestroySharingSessionById, (_, id) => {
|
||||
const sharingSession = getDeskreenGlobal().sharingSessionService.sharingSessions.get(
|
||||
id
|
||||
);
|
||||
sharingSession?.setStatus(SharingSessionStatusEnum.DESTROYED);
|
||||
sharingSession?.destroy();
|
||||
getDeskreenGlobal().sharingSessionService.sharingSessions.delete(id);
|
||||
});
|
||||
}
|
||||
|
11
app/menu.ts
11
app/menu.ts
@ -215,12 +215,11 @@ export default class MenuBuilder {
|
||||
],
|
||||
};
|
||||
|
||||
// const subMenuView =
|
||||
// process.env.NODE_ENV === 'development' ||
|
||||
// process.env.DEBUG_PROD === 'true'
|
||||
// ? subMenuViewDev
|
||||
// : subMenuViewProd;
|
||||
const subMenuView = subMenuViewDev;
|
||||
const subMenuView =
|
||||
process.env.NODE_ENV === 'development' ||
|
||||
process.env.DEBUG_PROD === 'true'
|
||||
? subMenuViewDev
|
||||
: subMenuViewProd;
|
||||
|
||||
return [subMenuAbout, subMenuEdit, subMenuView, subMenuWindow, subMenuHelp];
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "deskreen",
|
||||
"productName": "Deskreen",
|
||||
"version": "1.0.12",
|
||||
"version": "2.0.0",
|
||||
"description": "Deskreen turns any device into a secondary screen for your computer",
|
||||
"main": "./main.prod.js",
|
||||
"author": {
|
||||
|
@ -26,8 +26,8 @@ export function handleIpcRenderer() {
|
||||
peerConnection.callPeer();
|
||||
});
|
||||
|
||||
ipcRenderer.on('disconnect-by-host-machine-user', () => {
|
||||
peerConnection.disconnectByHostMachineUser();
|
||||
ipcRenderer.on('disconnect-by-host-machine-user', (_, deviceId: string) => {
|
||||
peerConnection.disconnectByHostMachineUser(deviceId);
|
||||
});
|
||||
|
||||
ipcRenderer.on('deny-connection-for-partner', () => {
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "deskreen",
|
||||
"productName": "Deskreen",
|
||||
"version": "1.0.12",
|
||||
"version": "2.0.0",
|
||||
"description": "Deskreen turns any device into a secondary screen for your computer",
|
||||
"scripts": {
|
||||
"build": "yarn build-client && yarn build-main && yarn build-renderer",
|
||||
|
Loading…
x
Reference in New Issue
Block a user