Skip to content

Commit

Permalink
Fix TouchEvent on Safari #545
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Aug 24, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 5e26a2e commit fb18cc0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/webrtc/www/digital-ptz.js
Original file line number Diff line number Diff line change
@@ -179,11 +179,12 @@ function startGesturePan({ containerEl, transform, render }, type) {
type === "mouse"
? ["mousedown", "mousemove", "mouseup"]
: ["touchstart", "touchmove", "touchend"];
const isTouchEvent = ev => 'TouchEvent' in window && ev instanceof TouchEvent;
const onDown = (downEvt) => {
let last = downEvt instanceof TouchEvent ? downEvt.touches[0] : downEvt;
let last = isTouchEvent(downEvt) ? downEvt.touches[0] : downEvt;
const onMove = (moveEvt) => {
if (moveEvt instanceof TouchEvent && moveEvt.touches.length !== 1) return;
const curr = moveEvt instanceof TouchEvent ? moveEvt.touches[0] : moveEvt;
if (isTouchEvent(moveEvt) && moveEvt.touches.length !== 1) return;
const curr = isTouchEvent(moveEvt) ? moveEvt.touches[0] : moveEvt;
transform.move(curr.pageX - last.pageX, curr.pageY - last.pageY);
last = curr;
render();

1 comment on commit fb18cc0

@dbuezas
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Please sign in to comment.