itty-sockets 0.2.1 → 0.2.3
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/README.md +4 -4
- package/connect.d.ts +3 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
|
|
17
17
|
---
|
|
18
18
|
|
|
19
|
-
Tiny messaging client in under 450 bytes. No backend needed.
|
|
19
|
+
Tiny realtime messaging client in under 450 bytes. No backend needed.
|
|
20
20
|
|
|
21
|
-
## Example (using ittysockets.io public channels)
|
|
21
|
+
## Example (using [ittysockets.io](https://ittysockets.io) public channels)
|
|
22
22
|
```ts
|
|
23
23
|
import { connect } from 'itty-sockets' // ~422 bytes
|
|
24
24
|
|
|
@@ -86,9 +86,9 @@ connect('foo').push('hello world!')
|
|
|
86
86
|
| **connect(id, options)** | Creates a new channel connection | `connect('foo')` |
|
|
87
87
|
| **.open()** | Opens/re-opens the connection (manually, usually not needed) | `channel.open()` |
|
|
88
88
|
| **.close()** | Closes the connection | `channel.close()` |
|
|
89
|
-
| **.send(message)** | Sends a message to the
|
|
89
|
+
| **.send(message)** | Sends a message to the channel | `channel.send({ type: 'chat', text: 'hello' })` |
|
|
90
90
|
| **.push(message)** | Sends a message and closes the connection | `channel.push({ type: 'goodbye' })` |
|
|
91
|
-
| **.on('message', listener)** | Adds a message listener (multiple allowed) | `channel.on('message', event => console.log(event))` |
|
|
91
|
+
| **.on<MessageType = any>('message', listener)** | Adds a message listener (multiple allowed) | `channel.on('message', event => console.log(event))` |
|
|
92
92
|
| **.on('open', listener)** | Executes a listener on channel open (one allowed) | `channel.on('open', () => console.log('channel opened'))` |
|
|
93
93
|
| **.on('close', listener)** | Executes a listener on channel close (one allowed) | `channel.on('close', () => console.log('channel closed'))` |
|
|
94
94
|
|
package/connect.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export type AllowedProperty = 'open' | 'close' | 'send' | 'push' | 'on';
|
|
2
|
+
export type IttySocketEvent = 'open' | 'close' | 'message';
|
|
2
3
|
export type MessageEvent<MessageType = any> = {
|
|
3
4
|
date: Date;
|
|
4
5
|
uid?: string;
|
|
@@ -12,7 +13,8 @@ export type IttySocket = {
|
|
|
12
13
|
connected: boolean;
|
|
13
14
|
send: SendMessage;
|
|
14
15
|
push: SendMessage;
|
|
15
|
-
on
|
|
16
|
+
on<MessageFormat = any>(type: 'message', listener: (event: MessageEvent<MessageFormat>) => any): IttySocket;
|
|
17
|
+
on(type: Exclude<IttySocketEvent, 'message'>, listener: () => any): IttySocket;
|
|
16
18
|
};
|
|
17
19
|
export type IttySocketOptions = {
|
|
18
20
|
as?: string;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "itty-sockets",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Tiny realtime messaging client in under 450 bytes. No backend needed.",
|
|
5
5
|
"main": "./sockets.js",
|
|
6
6
|
"module": "./sockets.mjs",
|
|
7
7
|
"types": "./sockets.d.ts",
|
|
@@ -19,6 +19,9 @@
|
|
|
19
19
|
"keywords": [
|
|
20
20
|
"websockets",
|
|
21
21
|
"realtime",
|
|
22
|
+
"public",
|
|
23
|
+
"messages",
|
|
24
|
+
"tiny",
|
|
22
25
|
"free",
|
|
23
26
|
"p2p"
|
|
24
27
|
],
|