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