Sha256: 5a56af3e89a4de269141ca1644dba14a8a33ed868433decdd22905f30b40f880

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

import consumer from "./consumer"

consumer.subscriptions.create("OnlineChannel", {
  initialized() {
    this.update = this.update.bind(this)
  },

  connected() {
    this.install()
    this.update()
  },

  disconnected() {
    this.uninstall()
  },

  rejected() {
    this.uninstall()
  },

  update() {
    if(this.documentIsActive) {
      this.appear()
    }
  },

  appear() {
    this.perform("appear")
  },

  install() {
    window.addEventListener("focus", this.update)
    window.addEventListener("blur", this.update)
    document.addEventListener("turbo:load", this.update)
    document.addEventListener("visibilitychange", this.update)
  },

  uninstall() {
    window.removeEventListener("focus", this.update)
    window.removeEventListener("blur", this.update)
    document.removeEventListener("turbo:load", this.update)
    document.removeEventListener("visibilitychange", this.update)
  },

  get documentIsActive() {
    return document.visibilityState === "visible" && document.hasFocus()
  },
})

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
webamm_to_rails-7.0.1 lib/webamm_to_rails/features/devise_onlineable/templates/app/javascript/channels/online_channel.js.erb
webamm_to_rails-7.0.0 lib/webamm_to_rails/features/devise_onlineable/templates/app/javascript/channels/online_channel.js.erb