Git Product home page Git Product logo

event-replay-helpers's Introduction

Event Serialisation / Rehydration Helpers

Ever needed to save JavaScript (mouse/touch) events to the server to be replayed later? I did once, so now you have this shitty library.

yarn add event-replay-helpers

alt Demo GIF

Currently only works for mousemove, mousedown, mouseup, mouseover, click, touchstart, touchmove, and touchend for potential security reasons - I will deal with this soon (maybe)

import { rehydrateSerialisedEvent, serialiseEvent } from 'event-replay-helpers'

// the serialiseEvent function also accepts an optional startTimeStamp (number) - useful for recording a bunch of events with offsets to play them back at

document.addEventListener('click', (e) => {
  // serialise it, this can be sent to the server and stored in a database if you like
  const serialisedEvent = serialiseEvent(e)

  // wait a second and play it again
  setTimeout(() => {
    // this actually a function that dispatches the event when we call it, then returns the event as it's result
    const dispatchEvent = rehydrateSerialisedEvent(e)
    const rehydratedEvent = dispatchEvent()
  }, 1000)
})

To better understand how it works and how to use it, just have a look at the index.ts - it's only ~130 lines of code.

event-replay-helpers's People

Contributors

zensavona avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.