mirror of
https://github.com/pavlobu/deskreen.git
synced 2025-05-21 01:40:12 -07:00
WIP, sharing session defined with unit tests
This commit is contained in:
parent
765b815dc6
commit
99b6cbba7f
@ -32,7 +32,7 @@ export default function AllowConnectionForDeviceAlert(
|
||||
<Col>
|
||||
<Text>{`Device IP: `}</Text>
|
||||
<span id="allow-connection-device-alert-device-ip-span">
|
||||
{device?.deviceIp}
|
||||
{device?.deviceIP}
|
||||
</span>
|
||||
</Col>
|
||||
</Row>
|
||||
@ -43,12 +43,12 @@ export default function AllowConnectionForDeviceAlert(
|
||||
</Row>
|
||||
<Row>
|
||||
<Col>
|
||||
<Text>{`Device OS: ${device?.deviceOs}`}</Text>
|
||||
<Text>{`Device OS: ${device?.deviceOS}`}</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
<Col>
|
||||
<Text>{`session ID: ${device?.sessionId}`}</Text>
|
||||
<Text>{`session ID: ${device?.sharingSessionID}`}</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
</Alert>
|
||||
|
@ -165,11 +165,11 @@ export default function ConnectedDevicesListDrawer(
|
||||
>
|
||||
<Card>
|
||||
<Text className="device-ip-container">
|
||||
{device.deviceIp}
|
||||
{device.deviceIP}
|
||||
</Text>
|
||||
<Text>{device.deviceType}</Text>
|
||||
<Text>{device.deviceOs}</Text>
|
||||
<Text>{device.sessionId}</Text>
|
||||
<Text>{device.deviceOS}</Text>
|
||||
<Text>{device.sharingSessionID}</Text>
|
||||
<Button
|
||||
intent="danger"
|
||||
onClick={(): void => {
|
||||
|
@ -19,11 +19,11 @@ const getDeviceConnectedPopoverContent = (
|
||||
<Col xs={12}>
|
||||
<H6>Connected Device:</H6>
|
||||
<Text>{`Type: ${pendingConnectionDevice?.deviceType}`}</Text>
|
||||
<Text>{`OS: ${pendingConnectionDevice?.deviceOs}`}</Text>
|
||||
<Text>{`OS: ${pendingConnectionDevice?.deviceOS}`}</Text>
|
||||
<div id="connected-button-popover-div-with-ip">
|
||||
<Text>{`IP: ${pendingConnectionDevice?.deviceIp}`}</Text>
|
||||
<Text>{`IP: ${pendingConnectionDevice?.deviceIP}`}</Text>
|
||||
</div>
|
||||
<Text>{`SessionId: ${pendingConnectionDevice?.sessionId}`}</Text>
|
||||
<Text>{`sharingSessionID: ${pendingConnectionDevice?.sharingSessionID}`}</Text>
|
||||
</Col>
|
||||
</Row>
|
||||
<Row>
|
||||
|
@ -68,7 +68,7 @@ exports[`should match exact snapshot 1`] = `
|
||||
</Blueprint3.Text>
|
||||
</div>
|
||||
<Blueprint3.Text>
|
||||
SessionId: undefined
|
||||
sharingSessionID: undefined
|
||||
</Blueprint3.Text>
|
||||
</Col>
|
||||
</Row>
|
||||
|
@ -16,9 +16,9 @@ export default function ConfirmStep(props: ConfirmStepProps) {
|
||||
|
||||
<Card style={{ marginBottom: '10px' }}>
|
||||
<Text>{`Device: ${props.device?.deviceType}`}</Text>
|
||||
<Text>{`Device IP: ${props.device?.deviceIp}`}</Text>
|
||||
<Text>{`Device OS: ${props.device?.deviceOs}`}</Text>
|
||||
<Text>{`Session ID: ${props.device?.sessionId}`}</Text>
|
||||
<Text>{`Device IP: ${props.device?.deviceIP}`}</Text>
|
||||
<Text>{`Device OS: ${props.device?.deviceOS}`}</Text>
|
||||
<Text>{`Session ID: ${props.device?.sharingSessionID}`}</Text>
|
||||
</Card>
|
||||
<div style={{ marginBottom: '10px' }}>
|
||||
<Text className="bp3-text-muted">
|
||||
|
@ -1,72 +1,72 @@
|
||||
[
|
||||
{
|
||||
"id": "123414",
|
||||
"sessionId": "14422424",
|
||||
"deviceOs": "Android",
|
||||
"sharingSessionID": "14422424",
|
||||
"deviceOS": "Android",
|
||||
"deviceType": "Mobile",
|
||||
"deviceIp": "123.123.123.123"
|
||||
"deviceIP": "123.123.123.123"
|
||||
},
|
||||
{
|
||||
"id": "1123",
|
||||
"sessionId": "43",
|
||||
"deviceOs": "IOS",
|
||||
"sharingSessionID": "43",
|
||||
"deviceOS": "IOS",
|
||||
"deviceType": "Mobile",
|
||||
"deviceIp": "124.124.124.124"
|
||||
"deviceIP": "124.124.124.124"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"sessionId": "22",
|
||||
"deviceOs": "Windows",
|
||||
"sharingSessionID": "22",
|
||||
"deviceOS": "Windows",
|
||||
"deviceType": "PS",
|
||||
"deviceIp": "255.255.124.124"
|
||||
"deviceIP": "255.255.124.124"
|
||||
},
|
||||
{
|
||||
"id": "33",
|
||||
"sessionId": "22",
|
||||
"deviceOs": "Ubuntu",
|
||||
"sharingSessionID": "22",
|
||||
"deviceOS": "Ubuntu",
|
||||
"deviceType": "PC",
|
||||
"deviceIp": "4.4.4.124"
|
||||
"deviceIP": "4.4.4.124"
|
||||
},
|
||||
{
|
||||
"id": "414",
|
||||
"sessionId": "423",
|
||||
"deviceOs": "Blackberry",
|
||||
"sharingSessionID": "423",
|
||||
"deviceOS": "Blackberry",
|
||||
"deviceType": "Mobile",
|
||||
"deviceIp": "224.224.224.124"
|
||||
"deviceIP": "224.224.224.124"
|
||||
},
|
||||
{
|
||||
"id": "1133223",
|
||||
"sessionId": "4133",
|
||||
"deviceOs": "IOS",
|
||||
"sharingSessionID": "4133",
|
||||
"deviceOS": "IOS",
|
||||
"deviceType": "Mobile",
|
||||
"deviceIp": "24.24.24.24"
|
||||
"deviceIP": "24.24.24.24"
|
||||
},
|
||||
{
|
||||
"id": "1321123",
|
||||
"sessionId": "44133",
|
||||
"deviceOs": "Android",
|
||||
"sharingSessionID": "44133",
|
||||
"deviceOS": "Android",
|
||||
"deviceType": "Mobile",
|
||||
"deviceIp": "14.14.14.14"
|
||||
"deviceIP": "14.14.14.14"
|
||||
},
|
||||
{
|
||||
"id": "993",
|
||||
"sessionId": "91322",
|
||||
"deviceOs": "Debian",
|
||||
"sharingSessionID": "91322",
|
||||
"deviceOS": "Debian",
|
||||
"deviceType": "PC",
|
||||
"deviceIp": "1.1.14.14"
|
||||
"deviceIP": "1.1.14.14"
|
||||
},
|
||||
{
|
||||
"id": "7757",
|
||||
"sessionId": "1111",
|
||||
"deviceOs": "MacOS",
|
||||
"sharingSessionID": "1111",
|
||||
"deviceOS": "MacOS",
|
||||
"deviceType": "Mac",
|
||||
"deviceIp": "12.12.14.14"
|
||||
"deviceIP": "12.12.14.14"
|
||||
},
|
||||
{
|
||||
"id": "123332",
|
||||
"sessionId": "323231",
|
||||
"deviceOs": "MacOS",
|
||||
"sharingSessionID": "323231",
|
||||
"deviceOS": "MacOS",
|
||||
"deviceType": "Mac",
|
||||
"deviceIp": "11.11.14.14"
|
||||
"deviceIP": "11.11.14.14"
|
||||
}
|
||||
]
|
||||
|
@ -1,7 +1,7 @@
|
||||
interface Device {
|
||||
id: string;
|
||||
sessionId: string;
|
||||
deviceOs: string;
|
||||
sharingSessionID: string;
|
||||
deviceOS: string;
|
||||
deviceType: string;
|
||||
deviceIp: string;
|
||||
deviceIP: string;
|
||||
}
|
||||
|
34
app/features/SharingSessionsService/SharingSession.spec.ts
Normal file
34
app/features/SharingSessionsService/SharingSession.spec.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import SharingSessionService from '.';
|
||||
import SharingType from './SharingType';
|
||||
|
||||
jest.useFakeTimers();
|
||||
|
||||
describe('SharingSession unit tests', () => {
|
||||
let sharingSession: SharingSessionService;
|
||||
|
||||
beforeEach(() => {
|
||||
sharingSession = new SharingSessionService();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
describe('when new SahringSession() is called', () => {
|
||||
it('should create sharing session with id', () => {
|
||||
expect(sharingSession.id).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should crete sharing session with deviceID equal to "" ', () => {
|
||||
expect(sharingSession.deviceID).toBe('');
|
||||
});
|
||||
|
||||
it('should create sharing session with sharingType equal to NOT_SET', () => {
|
||||
expect(sharingSession.sharingType).toBe(SharingType.NOT_SET);
|
||||
});
|
||||
|
||||
it('should create sharing session with sharingStream set to null', () => {
|
||||
expect(sharingSession.sharingStream).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
33
app/features/SharingSessionsService/SharingSessionServiceType.d.ts
vendored
Normal file
33
app/features/SharingSessionsService/SharingSessionServiceType.d.ts
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
import SharingType from './SharingType';
|
||||
|
||||
export default interface SharingSessionType {
|
||||
id: string;
|
||||
deviceID: string;
|
||||
sharingType: SharingType;
|
||||
sharingStream: MediaStream | null;
|
||||
roomID: string;
|
||||
connectedDeviceAt: Date;
|
||||
sharingStartedAt: Date;
|
||||
status: SharingSessionStatus;
|
||||
statusObserverCallbacks: SharingSessionStatusObserverCallback[];
|
||||
notifyStatusObservers: () => void;
|
||||
updateStatus: (newStatus: SharingSessionStatus) => void;
|
||||
setDevice: (id: string) => void; // updates connectedDeviceAt with timestamp
|
||||
setSharingStream: (stream: MediaStream) => void;
|
||||
getSharingStreamForUsage: () => MediaStream;
|
||||
setSharingType: (type: SharingType) => void;
|
||||
addStatusObserverCallback: (
|
||||
callback: SharingSessionStatusObserverCallback
|
||||
) => void;
|
||||
}
|
||||
|
||||
export enum SharingSessionStatus {
|
||||
NOT_CONNECTED,
|
||||
CONNECTED,
|
||||
SHARING,
|
||||
ERROR,
|
||||
}
|
||||
|
||||
export type SharingSessionStatusObserverCallback = (
|
||||
sharingSessionID: string
|
||||
) => void;
|
@ -0,0 +1,6 @@
|
||||
interface SharingSessionService {
|
||||
sharingSessions: SharingSession[];
|
||||
createNewSharingSession: () => SharingSession;
|
||||
pollForInactiveSessions: () => void;
|
||||
getSharingSessionByID: (id: string) => SharingSession;
|
||||
}
|
7
app/features/SharingSessionsService/SharingType.ts
Normal file
7
app/features/SharingSessionsService/SharingType.ts
Normal file
@ -0,0 +1,7 @@
|
||||
enum SharingType {
|
||||
NOT_SET,
|
||||
SCREEN,
|
||||
APP,
|
||||
}
|
||||
|
||||
export default SharingType;
|
36
app/features/SharingSessionsService/index.ts
Normal file
36
app/features/SharingSessionsService/index.ts
Normal file
@ -0,0 +1,36 @@
|
||||
/* eslint-disable @typescript-eslint/lines-between-class-members */
|
||||
import uuid from 'uuid';
|
||||
import SharingSessionServiceType, {
|
||||
SharingSessionStatus,
|
||||
SharingSessionStatusObserverCallback,
|
||||
} from './SharingSessionServiceType';
|
||||
import SharingType from './SharingType';
|
||||
|
||||
export default class SharingSessionService
|
||||
implements SharingSessionServiceType {
|
||||
id: string;
|
||||
deviceID: string;
|
||||
sharingType: SharingType;
|
||||
sharingStream: MediaStream | null;
|
||||
roomID: string;
|
||||
connectedDeviceAt: Date;
|
||||
sharingStartedAt: Date;
|
||||
status: SharingSessionStatus;
|
||||
statusObserverCallbacks: SharingSessionStatusObserverCallback[];
|
||||
notifyStatusObservers: () => void;
|
||||
updateStatus: (newStatus: SharingSessionStatus) => void;
|
||||
setDevice: (id: string) => void;
|
||||
setSharingStream: (stream: MediaStream) => void;
|
||||
getSharingStreamForUsage: () => MediaStream;
|
||||
setSharingType: (type: SharingType) => void;
|
||||
addStatusObserverCallback: (
|
||||
callback: SharingSessionStatusObserverCallback
|
||||
) => void;
|
||||
|
||||
constructor() {
|
||||
this.id = uuid.v4();
|
||||
this.deviceID = '';
|
||||
this.sharingType = SharingType.NOT_SET;
|
||||
this.sharingStream = null;
|
||||
}
|
||||
}
|
49
app/server/roomIDService.ts
Normal file
49
app/server/roomIDService.ts
Normal file
@ -0,0 +1,49 @@
|
||||
/* eslint-disable class-methods-use-this */
|
||||
const shortID = require('shortid');
|
||||
|
||||
class RoomIDService {
|
||||
private static instance: RoomIDService;
|
||||
|
||||
private nextAvailableRoomIDNumber: number;
|
||||
|
||||
private takenRoomIDs: Set<string>;
|
||||
|
||||
constructor() {
|
||||
this.takenRoomIDs = new Set<string>();
|
||||
// TODO: load saved taken room ids from local storage, will be useful for saved devices feature in FUTURE
|
||||
this.nextAvailableRoomIDNumber = 1;
|
||||
}
|
||||
|
||||
public getSimpleAvailableRoomID(): string {
|
||||
while (this.takenRoomIDs.has(`${this.nextAvailableRoomIDNumber}`)) {
|
||||
this.nextAvailableRoomIDNumber += 1;
|
||||
}
|
||||
return `${this.nextAvailableRoomIDNumber}`;
|
||||
}
|
||||
|
||||
public getShortIDStringOfAvailableRoom(): string {
|
||||
let newID = shortID();
|
||||
while (this.takenRoomIDs.has(newID)) {
|
||||
newID = shortID();
|
||||
}
|
||||
return shortID();
|
||||
}
|
||||
|
||||
public markRoomIDAsTaken(id: string) {
|
||||
this.takenRoomIDs.add(id);
|
||||
}
|
||||
|
||||
public unmarkRoomIDAsTaken(id: string) {
|
||||
this.takenRoomIDs.delete(id);
|
||||
}
|
||||
|
||||
public static getInstance(): RoomIDService {
|
||||
if (!RoomIDService.instance) {
|
||||
RoomIDService.instance = new RoomIDService();
|
||||
}
|
||||
|
||||
return RoomIDService.instance;
|
||||
}
|
||||
}
|
||||
|
||||
export default RoomIDService.getInstance();
|
@ -242,6 +242,7 @@
|
||||
"@types/shortid": "^0.0.29",
|
||||
"@types/socket.io": "^2.1.11",
|
||||
"@types/socket.io-client": "^1.4.33",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/webpack": "^4.41.21",
|
||||
"@types/webpack-env": "^1.15.2",
|
||||
"@typescript-eslint/eslint-plugin": "^3.6.1",
|
||||
|
@ -26,7 +26,7 @@ const largeQRCodeDialog = Selector('#qr-code-dialog-inner');
|
||||
const connectedInfoStepperButton = Selector(
|
||||
'#connected-device-info-stepper-button'
|
||||
);
|
||||
const popoverDivWithDeviceIP = Selector(
|
||||
const popoverDivWithdeviceIP = Selector(
|
||||
'#connected-button-popover-div-with-ip'
|
||||
);
|
||||
const disconnectOneDeviceButton = Selector('button').withExactText(
|
||||
@ -58,7 +58,7 @@ const connectedDevicesButton = Selector(
|
||||
const connectedDevicesHeader = Selector('.bp3-text-muted').withText(
|
||||
'Connected Devices'
|
||||
);
|
||||
const getDeviceIPContainerByIP = (ip) =>
|
||||
const getdeviceIPContainerByIP = (ip) =>
|
||||
Selector('.device-ip-container').withText(ip);
|
||||
const yesDisconnectAllButton = Selector('button').withText(
|
||||
'Yes, Disconnect All'
|
||||
@ -69,7 +69,7 @@ const darkColorAppSettingButton = Selector('button').withText('Dark');
|
||||
const lightColorAppSettingButton = Selector('button').withText('Light');
|
||||
const darkUIClassName = Selector('.bp3-dark');
|
||||
|
||||
async function getConnectedDeviceIPFromAllowToConnectDeviceAlert() {
|
||||
async function getConnecteddeviceIPFromAllowToConnectDeviceAlert() {
|
||||
const deviceIPTextElement = Selector(
|
||||
'#allow-connection-device-alert-device-ip-span'
|
||||
);
|
||||
@ -80,7 +80,7 @@ async function getConnectedDeviceIPFromAllowToConnectDeviceAlert() {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
async function connectTestDeviceAndGetIP(t) {
|
||||
await t.click(connectTestDeviceButton());
|
||||
return getConnectedDeviceIPFromAllowToConnectDeviceAlert();
|
||||
return getConnecteddeviceIPFromAllowToConnectDeviceAlert();
|
||||
}
|
||||
|
||||
async function connectTestDevice(t) {
|
||||
@ -89,7 +89,7 @@ async function connectTestDevice(t) {
|
||||
|
||||
async function connectAndAllowTestDeviceAndGetIP(t) {
|
||||
await connectTestDevice(t);
|
||||
const ip = getConnectedDeviceIPFromAllowToConnectDeviceAlert();
|
||||
const ip = getConnecteddeviceIPFromAllowToConnectDeviceAlert();
|
||||
await t.click(allowToConnectButton());
|
||||
return ip;
|
||||
}
|
||||
@ -246,7 +246,7 @@ test(`when on step 2,
|
||||
const ip = await connectAndAllowTestDeviceAndGetIP(t);
|
||||
await openConnectedDeviceInfoPopover(t);
|
||||
|
||||
const textWithIp = await popoverDivWithDeviceIP().innerText;
|
||||
const textWithIp = await popoverDivWithdeviceIP().innerText;
|
||||
await t.expect(textWithIp.includes(ip)).ok();
|
||||
});
|
||||
|
||||
@ -375,7 +375,7 @@ test(`when on step 4 (Success Step),
|
||||
const ip = await connectDeviceSharingAppWindowAndGetIP(t);
|
||||
await openConnectedDevicesListDrawer(t);
|
||||
|
||||
await t.expect(getDeviceIPContainerByIP(ip).exists).ok();
|
||||
await t.expect(getdeviceIPContainerByIP(ip).exists).ok();
|
||||
});
|
||||
|
||||
test(`when multiple devices are connected,
|
||||
@ -390,10 +390,10 @@ test(`when multiple devices are connected,
|
||||
|
||||
await openConnectedDevicesListDrawer(t);
|
||||
|
||||
await t.expect(getDeviceIPContainerByIP(ipOne).exists).ok();
|
||||
await t.expect(getDeviceIPContainerByIP(ipTwo).exists).ok();
|
||||
await t.expect(getDeviceIPContainerByIP(ipThree).exists).ok();
|
||||
await t.expect(getDeviceIPContainerByIP(ipFour).exists).ok();
|
||||
await t.expect(getdeviceIPContainerByIP(ipOne).exists).ok();
|
||||
await t.expect(getdeviceIPContainerByIP(ipTwo).exists).ok();
|
||||
await t.expect(getdeviceIPContainerByIP(ipThree).exists).ok();
|
||||
await t.expect(getdeviceIPContainerByIP(ipFour).exists).ok();
|
||||
});
|
||||
|
||||
test(`when device is connected,
|
||||
@ -405,7 +405,7 @@ test(`when device is connected,
|
||||
await openConnectedDevicesListDrawer(t);
|
||||
await t.click(disconnectOneDeviceButton());
|
||||
|
||||
await t.expect(getDeviceIPContainerByIP(ip).exists).notOk();
|
||||
await t.expect(getdeviceIPContainerByIP(ip).exists).notOk();
|
||||
});
|
||||
|
||||
test(`when multiple devices are connected,
|
||||
@ -425,10 +425,10 @@ test(`when multiple devices are connected,
|
||||
|
||||
await openConnectedDevicesListDrawer(t);
|
||||
|
||||
await t.expect(getDeviceIPContainerByIP(ipOne).exists).notOk();
|
||||
await t.expect(getDeviceIPContainerByIP(ipTwo).exists).notOk();
|
||||
await t.expect(getDeviceIPContainerByIP(ipThree).exists).notOk();
|
||||
await t.expect(getDeviceIPContainerByIP(ipFour).exists).notOk();
|
||||
await t.expect(getdeviceIPContainerByIP(ipOne).exists).notOk();
|
||||
await t.expect(getdeviceIPContainerByIP(ipTwo).exists).notOk();
|
||||
await t.expect(getdeviceIPContainerByIP(ipThree).exists).notOk();
|
||||
await t.expect(getdeviceIPContainerByIP(ipFour).exists).notOk();
|
||||
});
|
||||
|
||||
test(`when device is connected,
|
||||
|
@ -2193,6 +2193,11 @@
|
||||
resolved "https://packages.deskreen.com/@types%2funist/-/unist-2.0.3.tgz#9c088679876f374eb5983f150d4787aa6fb32d7e"
|
||||
integrity sha512-FvUupuM3rlRsRtCN+fDudtmytGO6iHJuuRKS1Ss0pG5z8oX0diNEw94UEL7hgDbpN94rgaK5R7sWm6RrSkZuAQ==
|
||||
|
||||
"@types/uuid@^8.3.0":
|
||||
version "8.3.0"
|
||||
resolved "https://packages.deskreen.com/@types%2fuuid/-/uuid-8.3.0.tgz#215c231dff736d5ba92410e6d602050cce7e273f"
|
||||
integrity sha512-eQ9qFW/fhfGJF8WKHGEHZEyVWfZxrT+6CLIJGBcZPfxUh/+BnEj+UCGYMlr9qZuX/2AltsvwrGqp0LhEW8D0zQ==
|
||||
|
||||
"@types/webpack-env@^1.15.2":
|
||||
version "1.15.2"
|
||||
resolved "https://packages.deskreen.com/@types%2fwebpack-env/-/webpack-env-1.15.2.tgz#927997342bb9f4a5185a86e6579a0a18afc33b0a"
|
||||
|
Loading…
x
Reference in New Issue
Block a user