imean-inspector-sdk
Advanced tools
Comparing version
@@ -30,3 +30,3 @@ import { EventCallback } from '@imean/event'; | ||
private disconnectTimeout; | ||
private disconnectDelay; | ||
private readonly disconnectDelay; | ||
private metadata; | ||
@@ -36,4 +36,5 @@ private scrollDirection; | ||
private previousObjectURL; | ||
private resolution; | ||
version: string; | ||
constructor(url: string, viewContainer: HTMLDivElement, disconnectDelay?: number); | ||
constructor(url: string, viewContainer: HTMLDivElement, resolution?: ResolutionType); | ||
static getModifiersForEvent(event: MouseEvent): number; | ||
@@ -69,2 +70,9 @@ private detectScrollDirection; | ||
export declare const enum ResolutionType { | ||
low = "low", | ||
medium = "medium", | ||
high = "high", | ||
ultra = "ultra" | ||
} | ||
export declare interface ScreencastFrameParams { | ||
@@ -71,0 +79,0 @@ data: string; |
@@ -1,6 +0,6 @@ | ||
var f = Object.defineProperty; | ||
var g = (o, i, e) => i in o ? f(o, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[i] = e; | ||
var n = (o, i, e) => g(o, typeof i != "symbol" ? i + "" : i, e); | ||
var b = Object.defineProperty, E = (o, i, e) => i in o ? b(o, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : o[i] = e, L = (o, i, e) => (E(o, i + "", e), e), k = (o, i, e) => new Promise((s, t) => { | ||
var a = (h) => { | ||
var b = Object.defineProperty; | ||
var E = (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) => E(a, typeof i != "symbol" ? i + "" : i, e); | ||
var L = Object.defineProperty, k = (a, i, e) => i in a ? L(a, i, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[i] = e, C = (a, i, e) => (k(a, i + "", e), e), K = (a, i, e) => new Promise((s, t) => { | ||
var o = (h) => { | ||
try { | ||
@@ -17,7 +17,7 @@ r(e.next(h)); | ||
} | ||
}, r = (h) => h.done ? s(h.value) : Promise.resolve(h.value).then(a, c); | ||
r((e = e.apply(o, i)).next()); | ||
}), C = class p { | ||
}, r = (h) => h.done ? s(h.value) : Promise.resolve(h.value).then(o, c); | ||
r((e = e.apply(a, i)).next()); | ||
}), R = class f { | ||
constructor() { | ||
L(this, "callbackMap", {}); | ||
C(this, "callbackMap", {}); | ||
} | ||
@@ -28,3 +28,3 @@ /** | ||
static createEvent() { | ||
return new p(); | ||
return new f(); | ||
} | ||
@@ -68,3 +68,3 @@ /** | ||
emit(i, ...e) { | ||
return k(this, null, function* () { | ||
return K(this, null, function* () { | ||
if (!this.callbackMap[i]) | ||
@@ -76,11 +76,29 @@ return; | ||
} | ||
}, m = /* @__PURE__ */ ((o) => (o.KeyDown = "keyDown", o.KeyUp = "keyUp", o.RawKeyDown = "rawKeyDown", o.Char = "char", o))(m || {}); | ||
function R(o, i) { | ||
}, m = /* @__PURE__ */ ((a) => (a.KeyDown = "keyDown", a.KeyUp = "keyUp", a.RawKeyDown = "rawKeyDown", a.Char = "char", a))(m || {}), w = /* @__PURE__ */ ((a) => (a.low = "low", a.medium = "medium", a.high = "high", a.ultra = "ultra", a))(w || {}); | ||
function S(a, i) { | ||
let e; | ||
return function(...s) { | ||
clearTimeout(e), e = setTimeout(() => o.apply(this, s), i); | ||
clearTimeout(e), e = setTimeout(() => a.apply(this, s), i); | ||
}; | ||
} | ||
class w extends C { | ||
constructor(e, s, t) { | ||
const p = { | ||
low: { | ||
width: 640, | ||
height: 480 | ||
}, | ||
medium: { | ||
width: 800, | ||
height: 600 | ||
}, | ||
high: { | ||
width: 1280, | ||
height: 720 | ||
}, | ||
ultra: { | ||
width: 1440, | ||
height: 900 | ||
} | ||
}; | ||
class g extends R { | ||
constructor(e, s, t = w.ultra) { | ||
super(); | ||
@@ -95,3 +113,3 @@ n(this, "url"); | ||
n(this, "disconnectTimeout"); | ||
n(this, "disconnectDelay"); | ||
n(this, "disconnectDelay", 6e4 * 5); | ||
n(this, "metadata", null); | ||
@@ -101,3 +119,4 @@ n(this, "scrollDirection", 1); | ||
n(this, "previousObjectURL", null); | ||
n(this, "version", "1.2.4"); | ||
n(this, "resolution", w.ultra); | ||
n(this, "version", "1.2.5"); | ||
n(this, "detectScrollDirection", () => { | ||
@@ -120,3 +139,3 @@ const e = (s) => { | ||
this.canvas.style.display = "inline"; | ||
const a = s || this.metadata.deviceWidth, c = t || this.metadata.deviceHeight, r = this.metadata.deviceWidth, h = this.metadata.deviceHeight, l = a / r, d = c / h, u = Math.min(l, d); | ||
const o = s || this.metadata.deviceWidth, c = t || this.metadata.deviceHeight, r = this.metadata.deviceWidth, h = this.metadata.deviceHeight, l = o / r, d = c / h, u = Math.min(l, d); | ||
this.zoom = u; | ||
@@ -132,3 +151,3 @@ const v = r * u, y = h * u; | ||
t[r] = s.charCodeAt(r); | ||
const a = new Blob([t], { type: "image/png" }), c = URL.createObjectURL(a); | ||
const o = new Blob([t], { type: "image/png" }), c = URL.createObjectURL(o); | ||
this.previousObjectURL && URL.revokeObjectURL(this.previousObjectURL), this.previousObjectURL = c, this.img.onload = () => { | ||
@@ -142,3 +161,3 @@ this.canvasDrawImage(), this.emit("drawComplete", { status: !0 }); | ||
n(this, "emitMouse", (e) => { | ||
const s = { 0: "none", 1: "left", 2: "middle", 3: "right" }, t = e.type === "mousewheel" && window.event || e, a = { | ||
const s = { 0: "none", 1: "left", 2: "middle", 3: "right" }, t = e.type === "mousewheel" && window.event || e, o = { | ||
mousedown: "mousePressed", | ||
@@ -152,9 +171,9 @@ mouseup: "mouseReleased", | ||
}; | ||
if (!(t.type in a) || t.type !== "mousewheel" && s[t.which] === "none" && t.type !== "mousemove") | ||
if (!(t.type in o) || t.type !== "mousewheel" && s[t.which] === "none" && t.type !== "mousemove") | ||
return; | ||
const r = a[t.type].indexOf("wheel") !== -1, h = (r ? t.clientX : t.offsetX) * (1 / this.zoom), l = (r ? t.clientY : t.offsetY) * (1 / this.zoom), d = { | ||
type: a[t.type], | ||
const r = o[t.type].indexOf("wheel") !== -1, h = (r ? t.clientX : t.offsetX) * (1 / this.zoom), l = (r ? t.clientY : t.offsetY) * (1 / this.zoom), d = { | ||
type: o[t.type], | ||
x: h, | ||
y: l, | ||
modifiers: w.getModifiersForEvent(t), | ||
modifiers: g.getModifiersForEvent(t), | ||
button: t.type === "mousewheel" ? "none" : s[t.which], | ||
@@ -186,3 +205,3 @@ clickCount: 1 | ||
} | ||
const t = s === "char" ? String.fromCharCode(e.charCode) : void 0, a = { | ||
const t = s === "char" ? String.fromCharCode(e.charCode) : void 0, o = { | ||
type: s, | ||
@@ -205,3 +224,3 @@ text: t, | ||
method: "Input.dispatchKeyEvent", | ||
params: a | ||
params: o | ||
}) | ||
@@ -223,3 +242,3 @@ ); | ||
const e = new ResizeObserver( | ||
R(() => { | ||
S(() => { | ||
this.canvasDrawImage(), this.emit("drawComplete", { status: !0 }); | ||
@@ -231,4 +250,4 @@ }, 16.666666666666668) | ||
n(this, "removeEventListeners", () => { | ||
var e, s, t, a, c, r; | ||
(e = this.canvas) == null || e.removeEventListener("mousedown", this.emitMouse, !1), (s = this.canvas) == null || s.removeEventListener("mouseup", this.emitMouse, !1), (t = this.canvas) == null || t.removeEventListener("mousewheel", this.emitMouse, !1), (a = this.canvas) == null || a.removeEventListener("mousemove", this.emitMouse, !1), (c = this.canvas) == null || c.removeEventListener("mouseenter", this.bindKeyEvents, !1), (r = this.canvas) == null || r.removeEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
var e, s, t, o, c, r; | ||
(e = this.canvas) == null || e.removeEventListener("mousedown", this.emitMouse, !1), (s = this.canvas) == null || s.removeEventListener("mouseup", this.emitMouse, !1), (t = this.canvas) == null || t.removeEventListener("mousewheel", this.emitMouse, !1), (o = this.canvas) == null || o.removeEventListener("mousemove", this.emitMouse, !1), (c = this.canvas) == null || c.removeEventListener("mouseenter", this.bindKeyEvents, !1), (r = this.canvas) == null || r.removeEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
}); | ||
@@ -244,3 +263,5 @@ n(this, "connect", (e = !1) => (this.ws = new WebSocket(this.url), new Promise((s, t) => { | ||
quality: 80, | ||
everyNthFrame: 1 | ||
maxWidth: p[this.resolution].width, | ||
maxHeight: p[this.resolution].height, | ||
everyNthFrame: 5 | ||
} | ||
@@ -252,4 +273,4 @@ }) | ||
), s(); | ||
}, this.ws.onmessage = (a) => { | ||
const c = JSON.parse(a.data); | ||
}, this.ws.onmessage = (o) => { | ||
const c = JSON.parse(o.data); | ||
c.method === "Page.screencastFrame" && (this.handleScreencastFrame(c.params), this.ws.send( | ||
@@ -269,7 +290,7 @@ JSON.stringify({ | ||
), this.emit("close"), this.close(); | ||
}, this.ws.onerror = (a) => { | ||
console.error("WebSocket error:", a), this.emit("error", a), this.close(), t(a); | ||
}, this.ws.onerror = (o) => { | ||
console.error("WebSocket error:", o), this.emit("error", o), this.close(), t(o); | ||
}; | ||
}))); | ||
this.url = e, this.messageId = 0, this.viewContainer = s, this.disconnectTimeout = null, this.disconnectDelay = t ?? 6e4 * 5, this.detectScrollDirection(); | ||
this.url = e, this.messageId = 0, this.viewContainer = s, this.disconnectTimeout = null, this.resolution = t, this.detectScrollDirection(); | ||
} | ||
@@ -289,4 +310,4 @@ static getModifiersForEvent(e) { | ||
addEventListeners() { | ||
var e, s, t, a, c, r; | ||
(e = this.canvas) == null || e.addEventListener("mousedown", this.emitMouse, !1), (s = this.canvas) == null || s.addEventListener("mouseup", this.emitMouse, !1), (t = this.canvas) == null || t.addEventListener("mousewheel", this.emitMouse, !1), (a = this.canvas) == null || a.addEventListener("mousemove", this.emitMouse, !1), (c = this.canvas) == null || c.addEventListener("mouseenter", this.bindKeyEvents, !1), (r = this.canvas) == null || r.addEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
var e, s, t, o, c, r; | ||
(e = this.canvas) == null || e.addEventListener("mousedown", this.emitMouse, !1), (s = this.canvas) == null || s.addEventListener("mouseup", this.emitMouse, !1), (t = this.canvas) == null || t.addEventListener("mousewheel", this.emitMouse, !1), (o = this.canvas) == null || o.addEventListener("mousemove", this.emitMouse, !1), (c = this.canvas) == null || c.addEventListener("mouseenter", this.bindKeyEvents, !1), (r = this.canvas) == null || r.addEventListener("mouseleave", this.unbindKeyEvents, !1); | ||
} | ||
@@ -299,3 +320,4 @@ close() { | ||
m as DispatchKeyEventRequestType, | ||
w as default | ||
w as ResolutionType, | ||
g as default | ||
}; |
@@ -30,3 +30,3 @@ import { EventCallback } from '@imean/event'; | ||
private disconnectTimeout; | ||
private disconnectDelay; | ||
private readonly disconnectDelay; | ||
private metadata; | ||
@@ -36,4 +36,5 @@ private scrollDirection; | ||
private previousObjectURL; | ||
private resolution; | ||
version: string; | ||
constructor(url: string, viewContainer: HTMLDivElement, disconnectDelay?: number); | ||
constructor(url: string, viewContainer: HTMLDivElement, resolution?: ResolutionType); | ||
static getModifiersForEvent(event: MouseEvent): number; | ||
@@ -69,2 +70,9 @@ private detectScrollDirection; | ||
export declare const enum ResolutionType { | ||
low = "low", | ||
medium = "medium", | ||
high = "high", | ||
ultra = "ultra" | ||
} | ||
export declare interface ScreencastFrameParams { | ||
@@ -71,0 +79,0 @@ data: string; |
@@ -1,1 +0,1 @@ | ||
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.InspectorSDK={}))})(this,function(h){"use strict";var K=Object.defineProperty;var R=(h,l,m)=>l in h?K(h,l,{enumerable:!0,configurable:!0,writable:!0,value:m}):h[l]=m;var i=(h,l,m)=>R(h,typeof l!="symbol"?l+"":l,m);var l=Object.defineProperty,m=(r,n,e)=>n in r?l(r,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[n]=e,E=(r,n,e)=>(m(r,n+"",e),e),L=(r,n,e)=>new Promise((s,t)=>{var o=d=>{try{a(e.next(d))}catch(u){t(u)}},c=d=>{try{a(e.throw(d))}catch(u){t(u)}},a=d=>d.done?s(d.value):Promise.resolve(d.value).then(o,c);a((e=e.apply(r,n)).next())}),k=class g{constructor(){E(this,"callbackMap",{})}static createEvent(){return new g}on(n,e){var s;return this.callbackMap[n]||(this.callbackMap[n]=[]),(s=this.callbackMap[n])==null||s.push(e),e}off(n,e){var s;this.callbackMap[n]&&(this.callbackMap[n]=(s=this==null?void 0:this.callbackMap[n])==null?void 0:s.filter(t=>t!==e))}once(n,e){const s=(...t)=>{this.off(n,s),e(...t)};return this.on(n,s)}emit(n,...e){return L(this,null,function*(){if(!this.callbackMap[n])return;const s=this.callbackMap[n];s&&(yield Promise.all(s.map(t=>t(...e))))})}},v=(r=>(r.KeyDown="keyDown",r.KeyUp="keyUp",r.RawKeyDown="rawKeyDown",r.Char="char",r))(v||{});function C(r,n){let e;return function(...s){clearTimeout(e),e=setTimeout(()=>r.apply(this,s),n)}}class p extends k{constructor(e,s,t){super();i(this,"url");i(this,"ws");i(this,"messageId");i(this,"img",null);i(this,"canvas",null);i(this,"viewContainer");i(this,"zoom",devicePixelRatio);i(this,"disconnectTimeout");i(this,"disconnectDelay");i(this,"metadata",null);i(this,"scrollDirection",1);i(this,"context",null);i(this,"previousObjectURL",null);i(this,"version","1.2.4");i(this,"detectScrollDirection",()=>{const e=s=>{s.deltaY!==0&&(this.scrollDirection=s.deltaY>0?1:-1,window.removeEventListener("wheel",e))};window.addEventListener("wheel",e,{passive:!0,once:!0})});i(this,"handleStartScreencast",()=>{const e=document.createElement("canvas");e.id="inspectorSDK-canvas",e.style.display="none",this.context=e.getContext("2d"),this.canvas=e,this.img=new Image,this.viewContainer.appendChild(this.canvas)});i(this,"canvasDrawImage",e=>{if(!this.context||!this.metadata||!this.img||!this.canvas)return;const{width:s,height:t}=this.viewContainer.getBoundingClientRect();this.canvas.style.display="inline";const o=s||this.metadata.deviceWidth,c=t||this.metadata.deviceHeight,a=this.metadata.deviceWidth,d=this.metadata.deviceHeight,u=o/a,y=c/d,f=Math.min(u,y);this.zoom=f;const w=a*f,b=d*f;this.canvas.width=w*devicePixelRatio,this.canvas.height=b*devicePixelRatio,this.canvas.style.width=`${w}px`,this.canvas.style.height=`${b}px`,this.context.scale(devicePixelRatio,devicePixelRatio),this.context.drawImage(this.img,0,0,w,b),e&&URL.revokeObjectURL(e)});i(this,"handleScreencastFrame",e=>{if(this.metadata=e.metadata,!!this.img)try{const s=atob(e.data),t=new Uint8Array(s.length);for(let a=0;a<s.length;a++)t[a]=s.charCodeAt(a);const o=new Blob([t],{type:"image/png"}),c=URL.createObjectURL(o);this.previousObjectURL&&URL.revokeObjectURL(this.previousObjectURL),this.previousObjectURL=c,this.img.onload=()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},this.img.src=c}catch{this.emit("drawComplete",{status:!1})}});i(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 a=o[t.type].indexOf("wheel")!==-1,d=(a?t.clientX:t.offsetX)*(1/this.zoom),u=(a?t.clientY:t.offsetY)*(1/this.zoom),y={type:o[t.type],x:d,y:u,modifiers:p.getModifiersForEvent(t),button:t.type==="mousewheel"?"none":s[t.which],clickCount:1};t.type==="mousewheel"&&(y.deltaX=(t.deltaX||0)*(1/this.zoom)*this.scrollDirection,y.deltaY=(t.deltaY||t.wheelDelta||0)*(1/this.zoom)*this.scrollDirection),this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchMouseEvent",params:y}))});i(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}))});i(this,"bindKeyEvents",()=>{document.body.addEventListener("keydown",this.emitKeyEvent,!0),document.body.addEventListener("keyup",this.emitKeyEvent,!0),document.body.addEventListener("keypress",this.emitKeyEvent,!0)});i(this,"unbindKeyEvents",()=>{document.body.removeEventListener("keydown",this.emitKeyEvent,!0),document.body.removeEventListener("keyup",this.emitKeyEvent,!0),document.body.removeEventListener("keypress",this.emitKeyEvent,!0)});i(this,"handleVisibilityChange",()=>{document.visibilityState==="hidden"?this.disconnectTimeout=window.setTimeout(()=>{this.close()},this.disconnectDelay):this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null)});i(this,"onResizeViewContainer",()=>{const e=new ResizeObserver(C(()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},16.666666666666668));this.viewContainer&&e.observe(this.viewContainer)});i(this,"removeEventListeners",()=>{var e,s,t,o,c,a;(e=this.canvas)==null||e.removeEventListener("mousedown",this.emitMouse,!1),(s=this.canvas)==null||s.removeEventListener("mouseup",this.emitMouse,!1),(t=this.canvas)==null||t.removeEventListener("mousewheel",this.emitMouse,!1),(o=this.canvas)==null||o.removeEventListener("mousemove",this.emitMouse,!1),(c=this.canvas)==null||c.removeEventListener("mouseenter",this.bindKeyEvents,!1),(a=this.canvas)==null||a.removeEventListener("mouseleave",this.unbindKeyEvents,!1)});i(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 c=JSON.parse(o.data);c.method==="Page.screencastFrame"&&(this.handleScreencastFrame(c.params),this.ws.send(JSON.stringify({id:++this.messageId,method:"Page.screencastFrameAck",params:{sessionId:c.params.sessionId}})))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.emit("close"),this.close()},this.ws.onerror=o=>{console.error("WebSocket error:",o),this.emit("error",o),this.close(),t(o)}})));this.url=e,this.messageId=0,this.viewContainer=s,this.disconnectTimeout=null,this.disconnectDelay=t??6e4*5,this.detectScrollDirection()}static getModifiersForEvent(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}cleanupImage(){this.img&&(this.img.onload=null,this.img.src="",this.img=null),this.previousObjectURL&&URL.revokeObjectURL(this.previousObjectURL)}cleanupCanvas(){if(this.canvas){const e=this.canvas.parentNode;e==null||e.removeChild(this.canvas),this.canvas=null,this.context=null}}addEventListeners(){var e,s,t,o,c,a;(e=this.canvas)==null||e.addEventListener("mousedown",this.emitMouse,!1),(s=this.canvas)==null||s.addEventListener("mouseup",this.emitMouse,!1),(t=this.canvas)==null||t.addEventListener("mousewheel",this.emitMouse,!1),(o=this.canvas)==null||o.addEventListener("mousemove",this.emitMouse,!1),(c=this.canvas)==null||c.addEventListener("mouseenter",this.bindKeyEvents,!1),(a=this.canvas)==null||a.addEventListener("mouseleave",this.unbindKeyEvents,!1)}close(){this.ws.close(),this.removeEventListeners(),this.cleanupImage(),this.cleanupCanvas()}}h.DispatchKeyEventRequestType=v,h.default=p,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.InspectorSDK={}))})(this,function(h){"use strict";var S=Object.defineProperty;var M=(h,l,m)=>l in h?S(h,l,{enumerable:!0,configurable:!0,writable:!0,value:m}):h[l]=m;var i=(h,l,m)=>M(h,typeof l!="symbol"?l+"":l,m);var l=Object.defineProperty,m=(a,n,e)=>n in a?l(a,n,{enumerable:!0,configurable:!0,writable:!0,value:e}):a[n]=e,k=(a,n,e)=>(m(a,n+"",e),e),C=(a,n,e)=>new Promise((s,t)=>{var o=d=>{try{r(e.next(d))}catch(u){t(u)}},c=d=>{try{r(e.throw(d))}catch(u){t(u)}},r=d=>d.done?s(d.value):Promise.resolve(d.value).then(o,c);r((e=e.apply(a,n)).next())}),K=class L{constructor(){k(this,"callbackMap",{})}static createEvent(){return new L}on(n,e){var s;return this.callbackMap[n]||(this.callbackMap[n]=[]),(s=this.callbackMap[n])==null||s.push(e),e}off(n,e){var s;this.callbackMap[n]&&(this.callbackMap[n]=(s=this==null?void 0:this.callbackMap[n])==null?void 0:s.filter(t=>t!==e))}once(n,e){const s=(...t)=>{this.off(n,s),e(...t)};return this.on(n,s)}emit(n,...e){return C(this,null,function*(){if(!this.callbackMap[n])return;const s=this.callbackMap[n];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||{}),w=(a=>(a.low="low",a.medium="medium",a.high="high",a.ultra="ultra",a))(w||{});function R(a,n){let e;return function(...s){clearTimeout(e),e=setTimeout(()=>a.apply(this,s),n)}}const E={low:{width:640,height:480},medium:{width:800,height:600},high:{width:1280,height:720},ultra:{width:1440,height:900}};class f extends K{constructor(e,s,t=w.ultra){super();i(this,"url");i(this,"ws");i(this,"messageId");i(this,"img",null);i(this,"canvas",null);i(this,"viewContainer");i(this,"zoom",devicePixelRatio);i(this,"disconnectTimeout");i(this,"disconnectDelay",6e4*5);i(this,"metadata",null);i(this,"scrollDirection",1);i(this,"context",null);i(this,"previousObjectURL",null);i(this,"resolution",w.ultra);i(this,"version","1.2.5");i(this,"detectScrollDirection",()=>{const e=s=>{s.deltaY!==0&&(this.scrollDirection=s.deltaY>0?1:-1,window.removeEventListener("wheel",e))};window.addEventListener("wheel",e,{passive:!0,once:!0})});i(this,"handleStartScreencast",()=>{const e=document.createElement("canvas");e.id="inspectorSDK-canvas",e.style.display="none",this.context=e.getContext("2d"),this.canvas=e,this.img=new Image,this.viewContainer.appendChild(this.canvas)});i(this,"canvasDrawImage",e=>{if(!this.context||!this.metadata||!this.img||!this.canvas)return;const{width:s,height:t}=this.viewContainer.getBoundingClientRect();this.canvas.style.display="inline";const o=s||this.metadata.deviceWidth,c=t||this.metadata.deviceHeight,r=this.metadata.deviceWidth,d=this.metadata.deviceHeight,u=o/r,y=c/d,p=Math.min(u,y);this.zoom=p;const g=r*p,b=d*p;this.canvas.width=g*devicePixelRatio,this.canvas.height=b*devicePixelRatio,this.canvas.style.width=`${g}px`,this.canvas.style.height=`${b}px`,this.context.scale(devicePixelRatio,devicePixelRatio),this.context.drawImage(this.img,0,0,g,b),e&&URL.revokeObjectURL(e)});i(this,"handleScreencastFrame",e=>{if(this.metadata=e.metadata,!!this.img)try{const s=atob(e.data),t=new Uint8Array(s.length);for(let r=0;r<s.length;r++)t[r]=s.charCodeAt(r);const o=new Blob([t],{type:"image/png"}),c=URL.createObjectURL(o);this.previousObjectURL&&URL.revokeObjectURL(this.previousObjectURL),this.previousObjectURL=c,this.img.onload=()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},this.img.src=c}catch{this.emit("drawComplete",{status:!1})}});i(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 r=o[t.type].indexOf("wheel")!==-1,d=(r?t.clientX:t.offsetX)*(1/this.zoom),u=(r?t.clientY:t.offsetY)*(1/this.zoom),y={type:o[t.type],x:d,y:u,modifiers:f.getModifiersForEvent(t),button:t.type==="mousewheel"?"none":s[t.which],clickCount:1};t.type==="mousewheel"&&(y.deltaX=(t.deltaX||0)*(1/this.zoom)*this.scrollDirection,y.deltaY=(t.deltaY||t.wheelDelta||0)*(1/this.zoom)*this.scrollDirection),this.ws.send(JSON.stringify({id:++this.messageId,method:"Input.dispatchMouseEvent",params:y}))});i(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}))});i(this,"bindKeyEvents",()=>{document.body.addEventListener("keydown",this.emitKeyEvent,!0),document.body.addEventListener("keyup",this.emitKeyEvent,!0),document.body.addEventListener("keypress",this.emitKeyEvent,!0)});i(this,"unbindKeyEvents",()=>{document.body.removeEventListener("keydown",this.emitKeyEvent,!0),document.body.removeEventListener("keyup",this.emitKeyEvent,!0),document.body.removeEventListener("keypress",this.emitKeyEvent,!0)});i(this,"handleVisibilityChange",()=>{document.visibilityState==="hidden"?this.disconnectTimeout=window.setTimeout(()=>{this.close()},this.disconnectDelay):this.disconnectTimeout&&(clearTimeout(this.disconnectTimeout),this.disconnectTimeout=null)});i(this,"onResizeViewContainer",()=>{const e=new ResizeObserver(R(()=>{this.canvasDrawImage(),this.emit("drawComplete",{status:!0})},16.666666666666668));this.viewContainer&&e.observe(this.viewContainer)});i(this,"removeEventListeners",()=>{var e,s,t,o,c,r;(e=this.canvas)==null||e.removeEventListener("mousedown",this.emitMouse,!1),(s=this.canvas)==null||s.removeEventListener("mouseup",this.emitMouse,!1),(t=this.canvas)==null||t.removeEventListener("mousewheel",this.emitMouse,!1),(o=this.canvas)==null||o.removeEventListener("mousemove",this.emitMouse,!1),(c=this.canvas)==null||c.removeEventListener("mouseenter",this.bindKeyEvents,!1),(r=this.canvas)==null||r.removeEventListener("mouseleave",this.unbindKeyEvents,!1)});i(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,maxWidth:E[this.resolution].width,maxHeight:E[this.resolution].height,everyNthFrame:5}})),this.handleStartScreencast(),this.onResizeViewContainer(),e&&this.addEventListeners(),document.addEventListener("visibilitychange",this.handleVisibilityChange),s()},this.ws.onmessage=o=>{const c=JSON.parse(o.data);c.method==="Page.screencastFrame"&&(this.handleScreencastFrame(c.params),this.ws.send(JSON.stringify({id:++this.messageId,method:"Page.screencastFrameAck",params:{sessionId:c.params.sessionId}})))},this.ws.onclose=()=>{console.log("WebSocket connection closed"),document.removeEventListener("visibilitychange",this.handleVisibilityChange),this.emit("close"),this.close()},this.ws.onerror=o=>{console.error("WebSocket error:",o),this.emit("error",o),this.close(),t(o)}})));this.url=e,this.messageId=0,this.viewContainer=s,this.disconnectTimeout=null,this.resolution=t,this.detectScrollDirection()}static getModifiersForEvent(e){return(e.altKey?1:0)|(e.ctrlKey?2:0)|(e.metaKey?4:0)|(e.shiftKey?8:0)}cleanupImage(){this.img&&(this.img.onload=null,this.img.src="",this.img=null),this.previousObjectURL&&URL.revokeObjectURL(this.previousObjectURL)}cleanupCanvas(){if(this.canvas){const e=this.canvas.parentNode;e==null||e.removeChild(this.canvas),this.canvas=null,this.context=null}}addEventListeners(){var e,s,t,o,c,r;(e=this.canvas)==null||e.addEventListener("mousedown",this.emitMouse,!1),(s=this.canvas)==null||s.addEventListener("mouseup",this.emitMouse,!1),(t=this.canvas)==null||t.addEventListener("mousewheel",this.emitMouse,!1),(o=this.canvas)==null||o.addEventListener("mousemove",this.emitMouse,!1),(c=this.canvas)==null||c.addEventListener("mouseenter",this.bindKeyEvents,!1),(r=this.canvas)==null||r.addEventListener("mouseleave",this.unbindKeyEvents,!1)}close(){this.ws.close(),this.removeEventListeners(),this.cleanupImage(),this.cleanupCanvas()}}h.DispatchKeyEventRequestType=v,h.ResolutionType=w,h.default=f,Object.defineProperties(h,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); |
{ | ||
"name": "imean-inspector-sdk", | ||
"private": false, | ||
"version": "1.2.5", | ||
"version": "1.2.6", | ||
"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
40995
3.7%493
8.11%