Skip to content
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

chore: migrate src/EmulationManager to TypeScript #5766

Merged
merged 1 commit into from Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 8 additions & 19 deletions src/EmulationManager.js → src/EmulationManager.ts
Expand Up @@ -13,32 +13,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {CDPSession} from './Connection';

// Used as a TypeDef
// eslint-disable-next-line no-unused-vars
const {CDPSession} = require('./Connection');
export class EmulationManager {
_client: CDPSession;
_emulatingMobile = false;
_hasTouch = false;

class EmulationManager {
/**
* @param {!CDPSession} client
*/
constructor(client) {
constructor(client: CDPSession) {
this._client = client;
this._emulatingMobile = false;
this._hasTouch = false;
}

/**
* @param {!Puppeteer.Viewport} viewport
* @return {Promise<boolean>}
*/
async emulateViewport(viewport) {
async emulateViewport(viewport: Puppeteer.Viewport): Promise<boolean> {
const mobile = viewport.isMobile || false;
const width = viewport.width;
const height = viewport.height;
const deviceScaleFactor = viewport.deviceScaleFactor || 1;
/** @type {Protocol.Emulation.ScreenOrientation} */
const screenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
const screenOrientation: Protocol.Emulation.ScreenOrientation = viewport.isLandscape ? {angle: 90, type: 'landscapePrimary'} : {angle: 0, type: 'portraitPrimary'};
const hasTouch = viewport.hasTouch || false;

await Promise.all([
Expand All @@ -54,5 +45,3 @@ class EmulationManager {
return reloadNeeded;
}
}

module.exports = {EmulationManager};