itty-sockets 0.3.4 → 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.
- package/LICENSE +1 -1
- package/README.md +7 -6
- package/connect.d.ts +1 -0
- package/connect.js +1 -1
- package/connect.mjs +1 -1
- package/index.js +1 -1
- package/index.mjs +1 -1
- package/package.json +14 -23
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Tiny realtime messaging client in under 500 bytes. **No backend needed.**
|
|
|
22
22
|
|
|
23
23
|
Itty Sockets simplifies sending/receiving realtime data.
|
|
24
24
|
|
|
25
|
-
By pairing an ultra-tiny client (this) with the public **[ittysockets.io](https://ittysockets.io)** backend, you
|
|
25
|
+
By pairing an ultra-tiny client (this) with the public **[ittysockets.io](https://ittysockets.io)** backend, you
|
|
26
26
|
can focus on sending/receiving messages, instead of building a transport layer.
|
|
27
27
|
|
|
28
28
|
The idea is simple:
|
|
@@ -50,7 +50,7 @@ foo
|
|
|
50
50
|
|
|
51
51
|
### Important Considerations
|
|
52
52
|
|
|
53
|
-
1. **There is no history/replay/storage.** It's a live stream only.
|
|
53
|
+
1. **There is no history/replay/storage.** It's a live stream only.
|
|
54
54
|
2. **We don't authenticate.** [ittysockets.io](https://ittysockets.io) leverages security through obfuscation (a near-infinite number of channel names). Choose a more unique channel for more privacy. Need more? Consider encrypting/decrypting your payloads before transmission (this is easy).
|
|
55
55
|
3. **There are no guarantees of delivery.** While [ittysockets.io](https://ittysockets.io) is *extremely* stable, it's a free public service that is provided without any guarantees of delivery or uptime. Manage risk accordingly.
|
|
56
56
|
|
|
@@ -66,7 +66,7 @@ import { connect } from 'itty-sockets'
|
|
|
66
66
|
...or simply paste this into your environment/console:
|
|
67
67
|
<!-- BEGIN SNIPPET -->
|
|
68
68
|
```ts
|
|
69
|
-
let connect=(e,
|
|
69
|
+
let connect=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(`${s.base??"wss://ittysockets.io/r"}/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};
|
|
70
70
|
```
|
|
71
71
|
<!-- END SNIPPET -->
|
|
72
72
|
|
|
@@ -91,11 +91,12 @@ const channel = connect('my-channels/my-super-secret-channel', {
|
|
|
91
91
|
|
|
92
92
|
#### Connection Options
|
|
93
93
|
|
|
94
|
-
| option | default value | description |
|
|
94
|
+
| option | default value | description |
|
|
95
95
|
| --- | --- | --- |
|
|
96
96
|
| `{ alias: 'any-string' }` | `undefined` | An optional display name to be included in your messages. |
|
|
97
|
-
| `{ as: 'any-string' }` | `undefined` | An optional display name to be included in your message (same as alias). |
|
|
98
|
-
| `{ announce: true }` | `false` | Shares your uid/alias when joining/leaving. |
|
|
97
|
+
| `{ as: 'any-string' }` | `undefined` | An optional display name to be included in your message (same as alias). |
|
|
98
|
+
| `{ announce: true }` | `false` | Shares your uid/alias when joining/leaving. |
|
|
99
|
+
| `{ base: string }` | `undefined` | Define your own server url (requires API compatibility). |
|
|
99
100
|
| `{ echo: true }` | `false` | Echos messages back to original sender (good for testing). |
|
|
100
101
|
|
|
101
102
|
<br />
|
package/connect.d.ts
CHANGED
package/connect.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.connect=(e,s={})=>{let o,t=[],n=0,r={},a=()=>(o||(o=new WebSocket(
|
|
1
|
+
"use strict";exports.connect=(e,s={})=>{let o,t=[],n=0,r={},a=()=>(o||(o=new WebSocket(`${s.base??"wss://ittysockets.io/r"}/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of r.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of r.close??[])e()}),c);const c=new Proxy(a,{get:(e,s)=>({open:a,close:()=>(1==o?.readyState?o.close():n=1,c),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),c):(t.push(e),a())),push:(e,s)=>(n=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,o=r[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),a())}[s])});return c};
|
package/connect.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,
|
|
1
|
+
const e=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(`${s.base??"wss://ittysockets.io/r"}/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
|
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.connect=(e,s={})=>{let o,t=[],n=0,r={},a=()=>(o||(o=new WebSocket(
|
|
1
|
+
"use strict";exports.connect=(e,s={})=>{let o,t=[],n=0,r={},a=()=>(o||(o=new WebSocket(`${s.base??"wss://ittysockets.io/r"}/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of r.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of r[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of r.close??[])e()}),c);const c=new Proxy(a,{get:(e,s)=>({open:a,close:()=>(1==o?.readyState?o.close():n=1,c),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),c):(t.push(e),a())),push:(e,s)=>(n=1,c.send(e,s)),on:(e,s)=>((r[e]??=[]).push(s),a()),remove:(e,s,o=r[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),a())}[s])});return c};
|
package/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=(e,
|
|
1
|
+
const e=(e,s={})=>{let o,t=[],n=0,a={},r=()=>(o||(o=new WebSocket(`${s.base??"wss://ittysockets.io/r"}/${e}?${new URLSearchParams(s)}`),o.onopen=()=>{for(;t.length;)o?.send(t.shift());for(let e of a.open??[])e();n&&o?.close()},o.onmessage=(e,s=JSON.parse(e.data))=>{for(let e of a[s.type??"message"]??[])e({...s,date:new Date(s.date)})},o.onclose=()=>{n=0,o=null;for(let e of a.close??[])e()}),l);const l=new Proxy(r,{get:(e,s)=>({open:r,close:()=>(1==o?.readyState?o.close():n=1,l),send:(e,s)=>(e=JSON.stringify(e),e=s?`@@${s}@@${e}`:e,1==o?.readyState?(o.send(e),l):(t.push(e),r())),push:(e,s)=>(n=1,l.send(e,s)),on:(e,s)=>((a[e]??=[]).push(s),r()),remove:(e,s,o=a[e],t=o?.indexOf(s)??-1)=>(~t&&o?.splice(t,1),r())}[s])});return l};export{e as connect};
|
package/package.json
CHANGED
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-sockets",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Tiny realtime messaging client in under 450 bytes. No backend needed.",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./index.mjs",
|
|
9
|
+
"require": "./index.js",
|
|
10
|
+
"types": "./index.d.ts"
|
|
11
|
+
},
|
|
12
|
+
"./connect": {
|
|
13
|
+
"import": "./connect.mjs",
|
|
14
|
+
"require": "./connect.js",
|
|
15
|
+
"types": "./connect.d.ts"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
6
18
|
"scripts": {
|
|
7
19
|
"dev": "bun test --watch",
|
|
8
20
|
"lint": "bun eslint src",
|
|
@@ -46,26 +58,5 @@
|
|
|
46
58
|
"rollup-plugin-copy": "^3.5.0",
|
|
47
59
|
"typescript": "^5.7.2",
|
|
48
60
|
"yarn-release": "^1.10.6"
|
|
49
|
-
}
|
|
50
|
-
"exports": {
|
|
51
|
-
".": {
|
|
52
|
-
"import": "./index.mjs",
|
|
53
|
-
"require": "./index.js",
|
|
54
|
-
"types": "./index.d.ts"
|
|
55
|
-
},
|
|
56
|
-
"./connect": {
|
|
57
|
-
"import": "./connect.mjs",
|
|
58
|
-
"require": "./connect.js",
|
|
59
|
-
"types": "./connect.d.ts"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"files": [
|
|
63
|
-
"LICENSE",
|
|
64
|
-
"index.mjs",
|
|
65
|
-
"index.js",
|
|
66
|
-
"index.d.ts",
|
|
67
|
-
"connect.mjs",
|
|
68
|
-
"connect.js",
|
|
69
|
-
"connect.d.ts"
|
|
70
|
-
]
|
|
61
|
+
}
|
|
71
62
|
}
|