-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[MM-55503] Add support for new DesktopAPI #602
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
509b851
desktopAPI.joinCall
streamer45 2a06c08
desktopAPI.leaveCall
streamer45 1c5549a
desktopAPI.callsWidgetConnected
streamer45 3ef911c
desktopAPI.openLinkFromCallsWidget
streamer45 673b5e9
desktopAPI.resizeCallsWidget
streamer45 7c35586
desktopAPI.focusPopout
streamer45 0fdb978
desktopAPI.getDesktopSources & desktopAPI.onOpenScreenShareModal
streamer45 ad5ce0c
desktopAPI.onScreenShared
streamer45 e9b6b55
desktopAPI.getAppInfo
streamer45 07ce068
desktopAPI.sendJoinCallRequest & desktopAPI.openLinkFromCalls
streamer45 8c06247
desktopAPI.onCallsError
streamer45 79ec985
Better unsubscribing logic
streamer45 f94dbf9
desktopAPI.onOpenLinkFromCalls
streamer45 912aa4e
Restructure e2e tests
streamer45 5af6f17
e2e: Desktop API mocking
streamer45 fb7a880
Update desktop-api
streamer45 5f761d0
Fix test
streamer45 74757aa
Cleanup checks
streamer45 6852a5f
Remove onOpenLinkFromCalls handler
streamer45 e42115d
Update desktop api
streamer45 4a992e3
Merge remote-tracking branch 'origin/main' into MM-55503
streamer45 ba8afe5
Update desktop-api
streamer45 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
import {expect, test} from '@playwright/test'; | ||
import {readFile} from 'fs/promises'; | ||
|
||
import PlaywrightDevPage from '../page'; | ||
import type {DesktopAPICalls} from '../types'; | ||
import { | ||
getChannelNamesForTest, | ||
getUserStoragesForTest, | ||
} from '../utils'; | ||
|
||
const userStorages = getUserStoragesForTest(); | ||
|
||
const desktopAPICalls: DesktopAPICalls = { | ||
getAppInfo: false, | ||
onCallsError: false, | ||
openScreenShareModal: false, | ||
onScreenShared: false, | ||
sendCallsError: false, | ||
leaveCall: false, | ||
}; | ||
|
||
test.beforeEach(async ({page}, info) => { | ||
if (info.title.startsWith('desktopAPI')) { | ||
await page.exposeFunction('getAppInfo', () => { | ||
desktopAPICalls.getAppInfo = true; | ||
return {version: '5.7.0'}; | ||
}); | ||
|
||
await page.exposeFunction('onCallsError', () => { | ||
desktopAPICalls.onCallsError = true; | ||
}); | ||
|
||
await page.exposeFunction('openScreenShareModal', () => { | ||
desktopAPICalls.openScreenShareModal = true; | ||
}); | ||
|
||
await page.exposeFunction('onScreenShared', () => { | ||
desktopAPICalls.onScreenShared = true; | ||
}); | ||
|
||
await page.exposeFunction('sendCallsError', () => { | ||
desktopAPICalls.sendCallsError = true; | ||
}); | ||
|
||
await page.exposeFunction('leaveCall', () => { | ||
desktopAPICalls.leaveCall = true; | ||
}); | ||
|
||
await page.addInitScript(() => { | ||
window.desktopAPI = { | ||
getAppInfo: window.getAppInfo, | ||
openScreenShareModal: window.openScreenShareModal, | ||
onCallsError: () => { | ||
window.onCallsError(); | ||
|
||
return () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
}, | ||
onScreenShared: () => { | ||
window.onScreenShared(); | ||
|
||
return () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
}, | ||
sendCallsError: window.sendCallsError, | ||
leaveCall: window.leaveCall, | ||
}; | ||
}); | ||
} | ||
|
||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.goto(); | ||
}); | ||
|
||
test.describe('desktop', () => { | ||
test.use({storageState: userStorages[0]}); | ||
|
||
test('screen sharing < 5.1.0', async ({page}) => { | ||
await page.evaluate(() => { | ||
window.desktop = {version: '5.0.0'}; | ||
}); | ||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.startCall(); | ||
await page.locator('#calls-widget-toggle-menu-button').click(); | ||
await page.locator('#calls-widget-menu-screenshare').click(); | ||
await expect(page.locator('#calls-screen-source-modal')).toBeHidden(); | ||
await devPage.leaveCall(); | ||
}); | ||
|
||
test('screen source modal >= 5.1.0', async ({page}) => { | ||
const data = await readFile('./assets/screen.png', {encoding: 'base64'}); | ||
const sourceURI = `data:image/png;base64,${data}`; | ||
await page.evaluate((thumbnailURL) => { | ||
window.desktop = {version: '5.1.0'}; | ||
window.addEventListener('message', (event) => { | ||
if (event.data.type !== 'get-desktop-sources') { | ||
return; | ||
} | ||
|
||
window.postMessage({ | ||
type: 'desktop-sources-result', | ||
message: [ | ||
{id: '1', name: 'source_1', thumbnailURL}, | ||
{id: '2', name: 'source_2', thumbnailURL}, | ||
{id: '3', name: 'source_3', thumbnailURL}, | ||
], | ||
}, | ||
window.location.origin); | ||
}); | ||
}, sourceURI); | ||
|
||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.startCall(); | ||
await page.locator('#calls-widget-toggle-menu-button').click(); | ||
await page.locator('#calls-widget-menu-screenshare').click(); | ||
await expect(page.locator('#calls-screen-source-modal')).toBeVisible(); | ||
expect(await page.locator('#calls-screen-source-modal').screenshot()).toMatchSnapshot('calls-screen-source-modal.png'); | ||
await page.locator('#calls-screen-source-modal button:has-text("source_2")').click(); | ||
await page.locator('#calls-screen-source-modal button:has-text("Share")').click(); | ||
await expect(page.locator('#calls-screen-source-modal')).toBeHidden(); | ||
await devPage.leaveCall(); | ||
}); | ||
|
||
test('desktopAPI: screen sharing', async ({page}) => { | ||
await page.addInitScript(() => { | ||
window.desktopAPI.onScreenShared = (listener: (sourceID: string, withAudio: boolean) => void) => { | ||
window.desktopAPI.openScreenShareModal = () => { | ||
window.openScreenShareModal(); | ||
listener('', false); | ||
}; | ||
|
||
window.onScreenShared(); | ||
|
||
return () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
}; | ||
|
||
// Some browser API mocking needed given screen sharing is a little different | ||
// on Electron. | ||
|
||
// @ts-ignore | ||
navigator.mediaDevices.getUserMediaOriginal = navigator.mediaDevices.getUserMedia; | ||
navigator.mediaDevices.getUserMedia = (opts) => { | ||
if (opts?.audio) { | ||
// @ts-ignore | ||
return navigator.mediaDevices.getUserMediaOriginal({ | ||
video: false, | ||
audio: true, | ||
}); | ||
} | ||
|
||
return navigator.mediaDevices.getDisplayMedia({ | ||
video: true, | ||
audio: false, | ||
}); | ||
}; | ||
}); | ||
|
||
// start call in global widget | ||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.openWidget(getChannelNamesForTest()[0]); | ||
|
||
expect(desktopAPICalls.getAppInfo).toBe(true); | ||
expect(desktopAPICalls.onScreenShared).toBe(true); | ||
|
||
// click screen sharing button | ||
await page.locator('#calls-widget-toggle-menu-button').click(); | ||
await page.locator('#calls-widget-menu-screenshare').click(); | ||
|
||
expect(desktopAPICalls.openScreenShareModal).toBe(true); | ||
|
||
// verify we are screen sharing | ||
await expect(devPage.page.locator('#screen-player')).toBeVisible(); | ||
|
||
await devPage.leaveCall(); | ||
}); | ||
|
||
test('desktopAPI: screen sharing permissions error', async ({page}) => { | ||
await page.addInitScript(() => { | ||
window.desktopAPI.onScreenShared = (listener: (sourceID: string, withAudio: boolean) => void) => { | ||
window.desktopAPI.openScreenShareModal = () => { | ||
window.openScreenShareModal(); | ||
listener('', false); | ||
}; | ||
|
||
window.onScreenShared(); | ||
|
||
return () => {}; // eslint-disable-line @typescript-eslint/no-empty-function | ||
}; | ||
}); | ||
|
||
// start call in global widget | ||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.openWidget(getChannelNamesForTest()[0]); | ||
|
||
expect(desktopAPICalls.getAppInfo).toBe(true); | ||
expect(desktopAPICalls.onScreenShared).toBe(true); | ||
|
||
// click screen sharing button | ||
await page.locator('#calls-widget-toggle-menu-button').click(); | ||
await page.locator('#calls-widget-menu-screenshare').click(); | ||
|
||
expect(desktopAPICalls.openScreenShareModal).toBe(true); | ||
|
||
// verify screen sharing is failing | ||
await expect(page.locator('#screen-player')).toBeHidden(); | ||
await expect(page.getByTestId('calls-widget-banner-alert')).toBeVisible(); | ||
|
||
await devPage.leaveCall(); | ||
}); | ||
|
||
test('desktopAPI: calls client error', async ({page}) => { | ||
// start call in global widget | ||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.openWidget(getChannelNamesForTest()[0]); | ||
|
||
// Verify no error was sent | ||
expect(desktopAPICalls.sendCallsError).toBe(false); | ||
|
||
// Fake client failure | ||
await page.evaluate(() => { | ||
window.callsClient.disconnect(new Error('rtc peer error')); | ||
}); | ||
|
||
await expect(devPage.page.locator('#calls-widget')).toBeHidden(); | ||
|
||
// Verify error is getting sent | ||
expect(desktopAPICalls.sendCallsError).toBe(true); | ||
}); | ||
|
||
test('desktopAPI: leave call', async ({page}) => { | ||
// start call in global widget | ||
const devPage = new PlaywrightDevPage(page); | ||
await devPage.openWidget(getChannelNamesForTest()[0]); | ||
await devPage.leaveCall(); | ||
|
||
// Need to wait a moment since the the leave call happens in | ||
// a setTimeout handler. | ||
await devPage.wait(500); | ||
|
||
// Verify error is getting sent | ||
expect(desktopAPICalls.leaveCall).toBe(true); | ||
}); | ||
}); |
Binary file added
BIN
+11 KB
e2e/tests/desktop.spec.ts-snapshots/calls-screen-source-modal-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+11 KB
e2e/tests/desktop.spec.ts-snapshots/calls-screen-source-modal-webkit-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file removed
BIN
-12.8 KB
...ests/start_call.spec.ts-snapshots/calls-screen-source-modal-chromium-darwin.png
Binary file not shown.
Binary file removed
BIN
-11 KB
...tests/start_call.spec.ts-snapshots/calls-screen-source-modal-chromium-linux.png
Binary file not shown.
Binary file removed
BIN
-11 KB
e2e/tests/start_call.spec.ts-snapshots/calls-screen-source-modal-webkit-linux.png
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably don't need this anymore, it's unfortunately still there because of the
version
field, which has been replaced bygetAppInfo
under thedesktopAPI