imean-inspector-sdk
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -30,2 +30,3 @@ import { EventCallback } from '@imean/event'; | ||
private disconnectDelay; | ||
private metadata; | ||
version: string; | ||
@@ -35,2 +36,3 @@ constructor(url: string, viewContainer: HTMLDivElement, disconnectDelay?: number); | ||
private handleStartScreencast; | ||
private canvasDrawImage; | ||
private handleScreencastFrame; | ||
@@ -43,5 +45,6 @@ private emitMouse; | ||
private deleteCanvasElement; | ||
addListeners(): void; | ||
private onResizeViewContainer; | ||
addEventListeners(): void; | ||
removeEventListeners: () => void; | ||
connect: () => Promise<void>; | ||
connect: (listeners?: boolean) => Promise<void>; | ||
close(): void; | ||
@@ -51,13 +54,15 @@ } | ||
export declare interface MetaData { | ||
deviceHeight: number; | ||
deviceWidth: number; | ||
offsetTop: number; | ||
pageScaleFactor: number; | ||
scrollOffsetX: number; | ||
scrollOffsetY: number; | ||
timestamp: number; | ||
} | ||
export declare interface ScreencastFrameParams { | ||
data: string; | ||
metadata: { | ||
deviceHeight: number; | ||
deviceWidth: number; | ||
offsetTop: number; | ||
pageScaleFactor: number; | ||
scrollOffsetX: number; | ||
scrollOffsetY: number; | ||
timestamp: number; | ||
}; | ||
metadata: MetaData; | ||
} | ||
@@ -64,0 +69,0 @@ |
@@ -1,5 +0,5 @@ | ||
var b = Object.defineProperty; | ||
var k = (a, i, e) => i in a ? b(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e; | ||
var n = (a, i, e) => k(a, typeof i != "symbol" ? i + "" : i, e); | ||
var C = Object.defineProperty, K = (a, i, e) => i in a ? C(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e, L = (a, i, e) => (K(a, i + "", e), e), M = (a, i, e) => new Promise((s, t) => { | ||
var f = Object.defineProperty; | ||
var g = (a, i, e) => i in a ? f(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e; | ||
var n = (a, i, e) => g(a, typeof i != "symbol" ? i + "" : i, e); | ||
var b = Object.defineProperty, E = (a, i, e) => i in a ? b(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e, k = (a, i, e) => (E(a, i + "", e), e), C = (a, i, e) => new Promise((s, t) => { | ||
var o = (r) => { | ||
@@ -19,5 +19,5 @@ try { | ||
c((e = e.apply(a, i)).next()); | ||
}), S = class w { | ||
}), K = class w { | ||
constructor() { | ||
L(this, "callbackMap", {}); | ||
k(this, "callbackMap", {}); | ||
} | ||
@@ -67,3 +67,3 @@ /** | ||
emit(i, ...e) { | ||
return M(this, null, function* () { | ||
return C(this, null, function* () { | ||
if (!this.callbackMap[i]) | ||
@@ -76,3 +76,9 @@ return; | ||
}, m = /* @__PURE__ */ ((a) => (a.KeyDown = "keyDown", a.KeyUp = "keyUp", a.RawKeyDown = "rawKeyDown", a.Char = "char", a))(m || {}); | ||
class f extends S { | ||
function L(a, i) { | ||
let e; | ||
return function(...s) { | ||
clearTimeout(e), e = setTimeout(() => a.apply(this, s), i); | ||
}; | ||
} | ||
class p extends K { | ||
constructor(e, s, t) { | ||
@@ -89,3 +95,4 @@ super(); | ||
n(this, "disconnectDelay"); | ||
n(this, "version", "1.0.1"); | ||
n(this, "metadata", null); | ||
n(this, "version", "1.0.0"); | ||
n(this, "handleStartScreencast", () => { | ||
@@ -95,17 +102,22 @@ const e = document.createElement("canvas"); | ||
}); | ||
n(this, "canvasDrawImage", () => { | ||
const e = this.canvas.getContext("2d"); | ||
if (!e || !this.metadata) return; | ||
const { width: s, height: t } = this.viewContainer.getBoundingClientRect(); | ||
this.canvas.style.display = "inline"; | ||
const o = s || this.metadata.deviceWidth, d = t || this.metadata.deviceHeight, c = this.metadata.deviceWidth, r = this.metadata.deviceHeight, h = o / c, l = d / r, u = Math.min(h, l); | ||
this.zoom = u; | ||
const v = c * u, y = r * u; | ||
this.canvas.width = v * devicePixelRatio, this.canvas.height = y * devicePixelRatio, this.canvas.style.width = `${v}px`, this.canvas.style.height = `${y}px`, e.scale(devicePixelRatio, devicePixelRatio), e.drawImage(this.img, 0, 0, v, y); | ||
}); | ||
n(this, "handleScreencastFrame", (e) => { | ||
const { data: s, metadata: t } = e, o = this.canvas.getContext("2d"); | ||
if (o) | ||
try { | ||
this.img.onload = () => { | ||
const { width: d, height: c } = this.viewContainer.getBoundingClientRect(); | ||
this.canvas.style.display = "inline"; | ||
const r = d || t.deviceWidth, h = c || t.deviceHeight, l = t.deviceWidth, p = t.deviceHeight, g = r / l, E = h / p, u = Math.min(g, E); | ||
this.zoom = u; | ||
const v = l * u, y = p * u; | ||
this.canvas.width = v * devicePixelRatio, this.canvas.height = y * devicePixelRatio, this.canvas.style.width = `${v}px`, this.canvas.style.height = `${y}px`, o.scale(devicePixelRatio, devicePixelRatio), o.drawImage(this.img, 0, 0, v, y), this.emit("drawComplete", { status: !0 }); | ||
}, this.img.src = "data:image/jpeg;base64," + s; | ||
} catch { | ||
this.emit("drawComplete", { status: !1 }); | ||
} | ||
const { data: s, metadata: t } = e; | ||
this.metadata = t; | ||
try { | ||
this.img.onload = () => { | ||
this.canvasDrawImage(), this.emit("drawComplete", { status: !0 }); | ||
}, this.img.src = "data:image/jpeg;base64," + s; | ||
} catch { | ||
this.emit("drawComplete", { status: !1 }); | ||
} | ||
}); | ||
@@ -128,3 +140,3 @@ n(this, "emitMouse", (e) => { | ||
y: h, | ||
modifiers: f.getModifiersForEvent(t), | ||
modifiers: p.getModifiersForEvent(t), | ||
button: t.type === "mousewheel" ? "none" : s[t.which], | ||
@@ -194,6 +206,14 @@ clickCount: 1 | ||
}); | ||
n(this, "onResizeViewContainer", () => { | ||
const e = new ResizeObserver( | ||
L(() => { | ||
this.canvasDrawImage(), this.emit("drawComplete", { status: !0 }); | ||
}, 200) | ||
); | ||
this.viewContainer && e.observe(this.viewContainer); | ||
}); | ||
n(this, "removeEventListeners", () => { | ||
this.canvas.removeEventListener("mousedown", this.emitMouse, !1), this.canvas.removeEventListener("mouseup", this.emitMouse, !1), this.canvas.removeEventListener("mousewheel", this.emitMouse, !1), this.canvas.removeEventListener("mousemove", this.emitMouse, !1), this.canvas.removeEventListener("mouseenter", this.bindKeyEvents, !1), this.canvas.removeEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
}); | ||
n(this, "connect", () => (this.ws = new WebSocket(this.url), new Promise((e, s) => { | ||
n(this, "connect", (e = !1) => (this.ws = new WebSocket(this.url), new Promise((s, t) => { | ||
this.ws.onopen = () => { | ||
@@ -210,11 +230,11 @@ console.log("WebSocket connection opened"), this.ws.send( | ||
}) | ||
), this.handleStartScreencast(), this.addListeners(), document.addEventListener( | ||
), this.handleStartScreencast(), this.onResizeViewContainer(), e && this.addEventListeners(), document.addEventListener( | ||
"visibilitychange", | ||
this.handleVisibilityChange | ||
), e(); | ||
}, this.ws.onmessage = (t) => { | ||
const o = JSON.parse(t.data); | ||
if (o.method === "Page.screencastFrame") { | ||
const d = o.params; | ||
this.handleScreencastFrame(d), this.ws.send( | ||
), s(); | ||
}, this.ws.onmessage = (o) => { | ||
const d = JSON.parse(o.data); | ||
if (d.method === "Page.screencastFrame") { | ||
const c = d.params; | ||
this.handleScreencastFrame(c), this.ws.send( | ||
JSON.stringify({ | ||
@@ -224,3 +244,3 @@ id: ++this.messageId, | ||
params: { | ||
sessionId: o.params.sessionId | ||
sessionId: d.params.sessionId | ||
} | ||
@@ -235,4 +255,4 @@ }) | ||
), this.emit("close"); | ||
}, this.ws.onerror = (t) => { | ||
console.error("WebSocket error:", t), s(t); | ||
}, this.ws.onerror = (o) => { | ||
console.error("WebSocket error:", o), t(o); | ||
}; | ||
@@ -245,3 +265,3 @@ }))); | ||
} | ||
addListeners() { | ||
addEventListeners() { | ||
this.canvas.addEventListener("mousedown", this.emitMouse, !1), this.canvas.addEventListener("mouseup", this.emitMouse, !1), this.canvas.addEventListener("mousewheel", this.emitMouse, !1), this.canvas.addEventListener("mousemove", this.emitMouse, !1), this.canvas.addEventListener("mouseenter", this.bindKeyEvents, !1), this.canvas.addEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
@@ -255,3 +275,3 @@ } | ||
m as DispatchKeyEventRequestType, | ||
f as default | ||
p as default | ||
}; |
@@ -30,2 +30,3 @@ import { EventCallback } from '@imean/event'; | ||
private disconnectDelay; | ||
private metadata; | ||
version: string; | ||
@@ -35,2 +36,3 @@ constructor(url: string, viewContainer: HTMLDivElement, disconnectDelay?: number); | ||
private handleStartScreencast; | ||
private canvasDrawImage; | ||
private handleScreencastFrame; | ||
@@ -43,5 +45,6 @@ private emitMouse; | ||
private deleteCanvasElement; | ||
addListeners(): void; | ||
private onResizeViewContainer; | ||
addEventListeners(): void; | ||
removeEventListeners: () => void; | ||
connect: () => Promise<void>; | ||
connect: (listeners?: boolean) => Promise<void>; | ||
close(): void; | ||
@@ -51,13 +54,15 @@ } | ||
export declare interface MetaData { | ||
deviceHeight: number; | ||
deviceWidth: number; | ||
offsetTop: number; | ||
pageScaleFactor: number; | ||
scrollOffsetX: number; | ||
scrollOffsetY: number; | ||
timestamp: number; | ||
} | ||
export declare interface ScreencastFrameParams { | ||
data: string; | ||
metadata: { | ||
deviceHeight: number; | ||
deviceWidth: number; | ||
offsetTop: number; | ||
pageScaleFactor: number; | ||
scrollOffsetX: number; | ||
scrollOffsetY: number; | ||
timestamp: number; | ||
}; | ||
metadata: MetaData; | ||
} | ||
@@ -64,0 +69,0 @@ |
@@ -1,1 +0,1 @@ | ||
(function(a,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(a=typeof globalThis<"u"?globalThis:a||self,c(a.InspectorSDK={}))})(this,function(a){"use strict";var M=Object.defineProperty;var P=(a,c,u)=>c in a?M(a,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):a[c]=u;var n=(a,c,u)=>P(a,typeof c!="symbol"?c+"":c,u);var c=Object.defineProperty,u=(r,i,e)=>i in r?c(r,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[i]=e,k=(r,i,e)=>(u(r,i+"",e),e),K=(r,i,e)=>new Promise((s,t)=>{var o=d=>{try{h(e.next(d))}catch(m){t(m)}},l=d=>{try{h(e.throw(d))}catch(m){t(m)}},h=d=>d.done?s(d.value):Promise.resolve(d.value).then(o,l);h((e=e.apply(r,i)).next())}),C=class E{constructor(){k(this,"callbackMap",{})}static createEvent(){return new E}on(i,e){var s;return this.callbackMap[i]||(this.callbackMap[i]=[]),(s=this.callbackMap[i])==null||s.push(e),e}off(i,e){var s;this.callbackMap[i]&&(this.callbackMap[i]=(s=this==null?void 0:this.callbackMap[i])==null?void 0:s.filter(t=>t!==e))}once(i,e){const s=(...t)=>{this.off(i,s),e(...t)};return this.on(i,s)}emit(i,...e){return K(this,null,function*(){if(!this.callbackMap[i])return;const s=this.callbackMap[i];s&&(yield Promise.all(s.map(t=>t(...e))))})}},y=(r=>(r.KeyDown="keyDown",r.KeyUp="keyUp",r.RawKeyDown="rawKeyDown",r.Char="char",r))(y||{});class p extends C{constructor(e,s,t){super();n(this,"url");n(this,"ws");n(this,"messageId");n(this,"img");n(this,"canvas");n(this,"viewContainer");n(this,"zoom",devicePixelRatio);n(this,"disconnectTimeout");n(this,"disconnectDelay");n(this,"version","1.0.1");n(this,"handleStartScreencast",()=>{const e=document.createElement("canvas");e.id="inspectorSDK-canvas",this.canvas=e,this.img=new Image,this.canvas.style.display="none",this.viewContainer.appendChild(this.canvas)});n(this,"handleScreencastFrame",e=>{const{data:s,metadata:t}=e,o=this.canvas.getContext("2d");if(o)try{this.img.onload=()=>{const{width:l,height:h}=this.viewContainer.getBoundingClientRect();this.canvas.style.display="inline";const d=l||t.deviceWidth,m=h||t.deviceHeight,v=t.deviceWidth,b=t.deviceHeight,S=d/v,L=m/b,f=Math.min(S,L);this.zoom=f;const w=v*f,g=b*f;this.canvas.width=w*devicePixelRatio,this.canvas.height=g*devicePixelRatio,this.canvas.style.width=`${w}px`,this.canvas.style.height=`${g}px`,o.scale(devicePixelRatio,devicePixelRatio),o.drawImage(this.img,0,0,w,g),this.emit("drawComplete",{status:!0})},this.img.src="data:image/jpeg;base64,"+s}catch{this.emit("drawComplete",{status:!1})}});n(this,"emitMouse",e=>{const s={0:"none",1:"left",2:"middle",3:"right"},t=e.type==="mousewheel"&&window.event||e,o={mousedown:"mousePressed",mouseup:"mouseReleased",mousewheel:"mouseWheel",touchstart:"mousePressed",touchend:"mouseReleased",touchmove:"mouseWheel",mousemove:"mouseMoved"};if(!(t.type in o)||t.type!=="mousewheel"&&s[t.which]==="none"&&t.type!=="mousemove")return;const h=o[t.type].indexOf("wheel")!==-1,d=(h?t.clientX:t.offsetX)*(1/this.zoom),m=(h?t.clientY:t.offsetY)*(1/this.zoom),v={type:o[t.type],x:d,y:m,modifiers:p.getModifiersForEvent(t),button:t.type==="mousewheel"?"none":s[t.which],clickCount:1};t.type==="mousewheel"&&(v.deltaX=(t.wheelDeltaX||0)*(1/this.zoom),v.deltaY=(t.wheelDeltaY||t.wheelDelta)*(1/this.zoom)),this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchMouseEvent",params:v}))});n(this,"emitKeyEvent",e=>{let s;switch(e.keyCode===8&&e.preventDefault(),e.type){case"keydown":s=y.KeyDown;break;case"keyup":s=y.KeyUp;break;case"keypress":s=y.Char;break;default:return}const t=s==="char"?String.fromCharCode(e.charCode):void 0,o={type:s,text:t,unmodifiedText:t?t.toLowerCase():void 0,keyIdentifier:e.keyIdentifier,code:e.code,key:e.key,windowsVirtualKeyCode:e.keyCode,nativeVirtualKeyCode:e.keyCode,autoRepeat:!1,isKeypad:!1,isSystemKey:!1};this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchKeyEvent",params:o}))});n(this,"bindKeyEvents",()=>{document.body.addEventListener("keydown",this.emitKeyEvent,!0),document.body.addEventListener("keyup",this.emitKeyEvent,!0),document.body.addEventListener("keypress",this.emitKeyEvent,!0)});n(this,"unbindKeyEvents",()=>{document.body.removeEventListener("keydown",this.emitKeyEvent,!0),document.body.removeEventListener("keyup",this.emitKeyEvent,!0),document.body.removeEventListener("keypress",this.emitKeyEvent,!0)});n(this,"handleVisibilityChange",()=>{document.visibilityState==="hidden"?this.disconnectTimeout=window.setTimeout(()=>{this.close()},this.disconnectDelay):this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null)});n(this,"deleteCanvasElement",()=>{var s;const e=document.querySelector("#inspectorSDK-canvas");(s=e==null?void 0:e.parentElement)==null||s.removeChild(e)});n(this,"removeEventListeners",()=>{this.canvas.removeEventListener("mousedown",this.emitMouse,!1),this.canvas.removeEventListener("mouseup",this.emitMouse,!1),this.canvas.removeEventListener("mousewheel",this.emitMouse,!1),this.canvas.removeEventListener("mousemove",this.emitMouse,!1),this.canvas.removeEventListener("mouseenter",this.bindKeyEvents,!1),this.canvas.removeEventListener("mouseleave",this.unbindKeyEvents,!1)});n(this,"connect",()=>(this.ws=new WebSocket(this.url),new Promise((e,s)=>{this.ws.onopen=()=>{console.log("WebSocket connection opened"),this.ws.send(JSON.stringify({id:1,method:"Page.startScreencast",params:{format:"jpeg",quality:80,everyNthFrame:1}})),this.handleStartScreencast(),this.addListeners(),document.addEventListener("visibilitychange",this.handleVisibilityChange),e()},this.ws.onmessage=t=>{const o=JSON.parse(t.data);if(o.method==="Page.screencastFrame"){const l=o.params;this.handleScreencastFrame(l),this.ws.send(JSON.stringify({id:++this.messageId,method:"Page.screencastFrameAck",params:{sessionId:o.params.sessionId}}))}},this.ws.onclose=()=>{console.log("WebSocket connection closed"),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.emit("close")},this.ws.onerror=t=>{console.error("WebSocket error:",t),s(t)}})));this.url=e,this.messageId=0,this.viewContainer=s,this.disconnectTimeout=null,this.disconnectDelay=t??6e4*5}static getModifiersForEvent(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}addListeners(){this.canvas.addEventListener("mousedown",this.emitMouse,!1),this.canvas.addEventListener("mouseup",this.emitMouse,!1),this.canvas.addEventListener("mousewheel",this.emitMouse,!1),this.canvas.addEventListener("mousemove",this.emitMouse,!1),this.canvas.addEventListener("mouseenter",this.bindKeyEvents,!1),this.canvas.addEventListener("mouseleave",this.unbindKeyEvents,!1)}close(){this.ws.close(),this.removeEventListeners(),this.deleteCanvasElement()}}a.DispatchKeyEventRequestType=y,a.default=p,Object.defineProperties(a,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(r,c){typeof exports=="object"&&typeof module<"u"?c(exports):typeof define=="function"&&define.amd?define(["exports"],c):(r=typeof globalThis<"u"?globalThis:r||self,c(r.InspectorSDK={}))})(this,function(r){"use strict";var S=Object.defineProperty;var L=(r,c,u)=>c in r?S(r,c,{enumerable:!0,configurable:!0,writable:!0,value:u}):r[c]=u;var n=(r,c,u)=>L(r,typeof c!="symbol"?c+"":c,u);var c=Object.defineProperty,u=(a,i,e)=>i in a?c(a,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[i]=e,E=(a,i,e)=>(u(a,i+"",e),e),k=(a,i,e)=>new Promise((s,t)=>{var o=d=>{try{h(e.next(d))}catch(m){t(m)}},l=d=>{try{h(e.throw(d))}catch(m){t(m)}},h=d=>d.done?s(d.value):Promise.resolve(d.value).then(o,l);h((e=e.apply(a,i)).next())}),C=class b{constructor(){E(this,"callbackMap",{})}static createEvent(){return new b}on(i,e){var s;return this.callbackMap[i]||(this.callbackMap[i]=[]),(s=this.callbackMap[i])==null||s.push(e),e}off(i,e){var s;this.callbackMap[i]&&(this.callbackMap[i]=(s=this==null?void 0:this.callbackMap[i])==null?void 0:s.filter(t=>t!==e))}once(i,e){const s=(...t)=>{this.off(i,s),e(...t)};return this.on(i,s)}emit(i,...e){return k(this,null,function*(){if(!this.callbackMap[i])return;const s=this.callbackMap[i];s&&(yield Promise.all(s.map(t=>t(...e))))})}},v=(a=>(a.KeyDown="keyDown",a.KeyUp="keyUp",a.RawKeyDown="rawKeyDown",a.Char="char",a))(v||{});function K(a,i){let e;return function(...s){clearTimeout(e),e=setTimeout(()=>a.apply(this,s),i)}}class p extends C{constructor(e,s,t){super();n(this,"url");n(this,"ws");n(this,"messageId");n(this,"img");n(this,"canvas");n(this,"viewContainer");n(this,"zoom",devicePixelRatio);n(this,"disconnectTimeout");n(this,"disconnectDelay");n(this,"metadata",null);n(this,"version","1.0.0");n(this,"handleStartScreencast",()=>{const e=document.createElement("canvas");e.id="inspectorSDK-canvas",this.canvas=e,this.img=new Image,this.canvas.style.display="none",this.viewContainer.appendChild(this.canvas)});n(this,"canvasDrawImage",()=>{const e=this.canvas.getContext("2d");if(!e||!this.metadata)return;const{width:s,height:t}=this.viewContainer.getBoundingClientRect();this.canvas.style.display="inline";const o=s||this.metadata.deviceWidth,l=t||this.metadata.deviceHeight,h=this.metadata.deviceWidth,d=this.metadata.deviceHeight,m=o/h,y=l/d,f=Math.min(m,y);this.zoom=f;const w=h*f,g=d*f;this.canvas.width=w*devicePixelRatio,this.canvas.height=g*devicePixelRatio,this.canvas.style.width=`${w}px`,this.canvas.style.height=`${g}px`,e.scale(devicePixelRatio,devicePixelRatio),e.drawImage(this.img,0,0,w,g)});n(this,"handleScreencastFrame",e=>{const{data:s,metadata:t}=e;this.metadata=t;try{this.img.onload=()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},this.img.src="data:image/jpeg;base64,"+s}catch{this.emit("drawComplete",{status:!1})}});n(this,"emitMouse",e=>{const s={0:"none",1:"left",2:"middle",3:"right"},t=e.type==="mousewheel"&&window.event||e,o={mousedown:"mousePressed",mouseup:"mouseReleased",mousewheel:"mouseWheel",touchstart:"mousePressed",touchend:"mouseReleased",touchmove:"mouseWheel",mousemove:"mouseMoved"};if(!(t.type in o)||t.type!=="mousewheel"&&s[t.which]==="none"&&t.type!=="mousemove")return;const h=o[t.type].indexOf("wheel")!==-1,d=(h?t.clientX:t.offsetX)*(1/this.zoom),m=(h?t.clientY:t.offsetY)*(1/this.zoom),y={type:o[t.type],x:d,y:m,modifiers:p.getModifiersForEvent(t),button:t.type==="mousewheel"?"none":s[t.which],clickCount:1};t.type==="mousewheel"&&(y.deltaX=(t.wheelDeltaX||0)*(1/this.zoom),y.deltaY=(t.wheelDeltaY||t.wheelDelta)*(1/this.zoom)),this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchMouseEvent",params:y}))});n(this,"emitKeyEvent",e=>{let s;switch(e.keyCode===8&&e.preventDefault(),e.type){case"keydown":s=v.KeyDown;break;case"keyup":s=v.KeyUp;break;case"keypress":s=v.Char;break;default:return}const t=s==="char"?String.fromCharCode(e.charCode):void 0,o={type:s,text:t,unmodifiedText:t?t.toLowerCase():void 0,keyIdentifier:e.keyIdentifier,code:e.code,key:e.key,windowsVirtualKeyCode:e.keyCode,nativeVirtualKeyCode:e.keyCode,autoRepeat:!1,isKeypad:!1,isSystemKey:!1};this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchKeyEvent",params:o}))});n(this,"bindKeyEvents",()=>{document.body.addEventListener("keydown",this.emitKeyEvent,!0),document.body.addEventListener("keyup",this.emitKeyEvent,!0),document.body.addEventListener("keypress",this.emitKeyEvent,!0)});n(this,"unbindKeyEvents",()=>{document.body.removeEventListener("keydown",this.emitKeyEvent,!0),document.body.removeEventListener("keyup",this.emitKeyEvent,!0),document.body.removeEventListener("keypress",this.emitKeyEvent,!0)});n(this,"handleVisibilityChange",()=>{document.visibilityState==="hidden"?this.disconnectTimeout=window.setTimeout(()=>{this.close()},this.disconnectDelay):this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null)});n(this,"deleteCanvasElement",()=>{var s;const e=document.querySelector("#inspectorSDK-canvas");(s=e==null?void 0:e.parentElement)==null||s.removeChild(e)});n(this,"onResizeViewContainer",()=>{const e=new ResizeObserver(K(()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},200));this.viewContainer&&e.observe(this.viewContainer)});n(this,"removeEventListeners",()=>{this.canvas.removeEventListener("mousedown",this.emitMouse,!1),this.canvas.removeEventListener("mouseup",this.emitMouse,!1),this.canvas.removeEventListener("mousewheel",this.emitMouse,!1),this.canvas.removeEventListener("mousemove",this.emitMouse,!1),this.canvas.removeEventListener("mouseenter",this.bindKeyEvents,!1),this.canvas.removeEventListener("mouseleave",this.unbindKeyEvents,!1)});n(this,"connect",(e=!1)=>(this.ws=new WebSocket(this.url),new Promise((s,t)=>{this.ws.onopen=()=>{console.log("WebSocket connection opened"),this.ws.send(JSON.stringify({id:1,method:"Page.startScreencast",params:{format:"jpeg",quality:80,everyNthFrame:1}})),this.handleStartScreencast(),this.onResizeViewContainer(),e&&this.addEventListeners(),document.addEventListener("visibilitychange",this.handleVisibilityChange),s()},this.ws.onmessage=o=>{const l=JSON.parse(o.data);if(l.method==="Page.screencastFrame"){const h=l.params;this.handleScreencastFrame(h),this.ws.send(JSON.stringify({id:++this.messageId,method:"Page.screencastFrameAck",params:{sessionId:l.params.sessionId}}))}},this.ws.onclose=()=>{console.log("WebSocket connection closed"),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.emit("close")},this.ws.onerror=o=>{console.error("WebSocket error:",o),t(o)}})));this.url=e,this.messageId=0,this.viewContainer=s,this.disconnectTimeout=null,this.disconnectDelay=t??6e4*5}static getModifiersForEvent(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}addEventListeners(){this.canvas.addEventListener("mousedown",this.emitMouse,!1),this.canvas.addEventListener("mouseup",this.emitMouse,!1),this.canvas.addEventListener("mousewheel",this.emitMouse,!1),this.canvas.addEventListener("mousemove",this.emitMouse,!1),this.canvas.addEventListener("mouseenter",this.bindKeyEvents,!1),this.canvas.addEventListener("mouseleave",this.unbindKeyEvents,!1)}close(){this.ws.close(),this.removeEventListeners(),this.deleteCanvasElement()}}r.DispatchKeyEventRequestType=v,r.default=p,Object.defineProperties(r,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "imean-inspector-sdk", | ||
"private": false, | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "iMean inspector sdk", | ||
@@ -6,0 +6,0 @@ "repository": "https://git.imean.tech/imean/inspector-sdk.git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
36099
422