hotsock-turbo 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 855667dd61bba20964a93972d108e1ae299df990c157670b6005f979ac736c2a
4
- data.tar.gz: cde85dbe0e22fa654230f283efcbfa460541daa87f6efa0992cf6c94063df7b2
3
+ metadata.gz: b67599699f411cccd916179d8160bd4275620bfb291c192387a15911c7a5c953
4
+ data.tar.gz: cfaec3f98b3c30eb7d2b9b5c2f67a5e29c2fc7d7e112730f718f106f912b7c3a
5
5
  SHA512:
6
- metadata.gz: 61e34a6b641bb36ea43fab13fadde47c034b9080dd9ebaec35686742526c8115e0cde07cfe5569333b6759e25473e88b83580d139590ac5dc65acf36cf0faf50
7
- data.tar.gz: efcd9736e449b9043f96449918f4145040bd9c8649117881c5f5ae4ab025e8d050e9590bb5e870e4af7506830fb9c930b9e189be76a6b73719c7e2902ce4e9a4
6
+ metadata.gz: 9a7940056a3bc984e7ffd12efa3d44d1d5145e407b3fef4ff8379fd1169b741a3661c81fa334648710992ddcd1bcf166c2a76529afff568695b806a6cbb6dab6
7
+ data.tar.gz: b4c9f15c8662985b588e7f92950fb5bd00caffa3ba24d8d3487576b47c3685d8aee772e750455bf0400c956140179f23b25ab10579544c04f47f8f13397f7e58
@@ -8,11 +8,11 @@ function createHotsockClient() {
8
8
  {
9
9
  connectTokenFn: async () => {
10
10
  const connectTokenPath = document.querySelector(
11
- 'meta[name="hotsock:connect-token-path"]'
12
- ).content
11
+ 'meta[name="hotsock:connect-token-path"]',
12
+ )?.content
13
13
  const csrfToken = document.querySelector(
14
- 'meta[name="csrf-token"]'
15
- ).content
14
+ 'meta[name="csrf-token"]',
15
+ )?.content
16
16
  const response = await fetch(connectTokenPath, {
17
17
  method: "POST",
18
18
  headers: {
@@ -25,12 +25,15 @@ function createHotsockClient() {
25
25
  lazyConnection: true,
26
26
  logLevel: document.querySelector('meta[name="hotsock:log-level"]')
27
27
  ?.content,
28
- }
28
+ },
29
29
  )
30
30
  }
31
31
 
32
- const hotsockClient = window.Hotsock || createHotsockClient()
33
- window.Hotsock = hotsockClient
32
+ let hotsockClient = window.Hotsock
33
+ if (!hotsockClient && document.querySelector('meta[name="hotsock:wss-url"]')) {
34
+ hotsockClient = createHotsockClient()
35
+ window.Hotsock = hotsockClient
36
+ }
34
37
 
35
38
  const subscriptions = new Map() // channel -> { binding, elements: Set, unsubscribeTimer }
36
39
  const lastMessageIds = new Map() // channel -> lastMessageId (ULID)
@@ -101,7 +104,7 @@ class HotsockTurboStreamSourceElement extends HTMLElement {
101
104
  console.error("Failed to render Turbo Stream message:", error)
102
105
  }
103
106
  },
104
- { channel, subscribeTokenFn: () => token }
107
+ { channel, subscribeTokenFn: () => token },
105
108
  )
106
109
 
107
110
  sub = { binding, elements: new Set([this]), unsubscribeTimer: null }
@@ -154,7 +157,7 @@ class HotsockTurboStreamSourceElement extends HTMLElement {
154
157
  if (customElements.get("hotsock-turbo-stream-source") === undefined) {
155
158
  customElements.define(
156
159
  "hotsock-turbo-stream-source",
157
- HotsockTurboStreamSourceElement
160
+ HotsockTurboStreamSourceElement,
158
161
  )
159
162
  }
160
163
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Hotsock
4
4
  module Turbo
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotsock-turbo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Miller