@wireblob/wire 1.0.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 +21 -0
- package/README.md +293 -0
- package/lib/commonjs/wire.js +53 -0
- package/lib/commonjs/worker.js +9 -0
- package/lib/es/wire.js +48 -0
- package/lib/es/worker.js +2 -0
- package/lib/umd/wire.js +4428 -0
- package/lib/umd/wire.min.js +1 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Abdulbasit Rubeya
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
# Wireblobs JavaScript SDK (Wire JS)
|
|
2
|
+
|
|
3
|
+
A lightweight realtime SDK for connecting to the Wireblob realtime network using a Pusher-compatible protocol.
|
|
4
|
+
|
|
5
|
+
Wire is built as a wrapper around `pusher-js`, providing:
|
|
6
|
+
|
|
7
|
+
- simpler configuration
|
|
8
|
+
- Wireblob-first defaults
|
|
9
|
+
- browser support
|
|
10
|
+
- Node.js support
|
|
11
|
+
- React Native compatibility
|
|
12
|
+
- Web Worker compatibility
|
|
13
|
+
- future extensibility without breaking API compatibility
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### NPM
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @wireblob/wire
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Yarn
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @wireblob/wire
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### PNPM
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pnpm add @wireblob/wire
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
### Browser / Bundlers
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
import Wire from '@wireblob/wire';
|
|
41
|
+
|
|
42
|
+
const wire = new Wire('YOUR_APP_KEY', {
|
|
43
|
+
host: 'eu-central-1.wireblob.com',
|
|
44
|
+
secure: true
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const channel = wire.subscribe('chat');
|
|
48
|
+
|
|
49
|
+
channel.bind('message', (data) => {
|
|
50
|
+
console.log(data);
|
|
51
|
+
});
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### CDN Usage
|
|
55
|
+
|
|
56
|
+
The CDN file is a self-contained browser bundle. You do not need to load `pusher-js` separately.
|
|
57
|
+
|
|
58
|
+
```html
|
|
59
|
+
<script src="https://cdn.wireblob.com/wire/latest/wire.min.js"></script>
|
|
60
|
+
|
|
61
|
+
<script>
|
|
62
|
+
const wire = new Wire('YOUR_APP_KEY', {
|
|
63
|
+
host: 'eu-central-1.wireblob.com',
|
|
64
|
+
secure: true
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
const channel = wire.subscribe('chat');
|
|
68
|
+
|
|
69
|
+
channel.bind('message', (data) => {
|
|
70
|
+
console.log(data);
|
|
71
|
+
});
|
|
72
|
+
</script>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Constructor
|
|
77
|
+
|
|
78
|
+
```js
|
|
79
|
+
new Wire(appKey, options)
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Parameters
|
|
83
|
+
|
|
84
|
+
| Parameter | Type | Required | Description |
|
|
85
|
+
| --------- | -------- | -------- | ---------------------- |
|
|
86
|
+
| `appKey` | `string` | Yes | Application public key |
|
|
87
|
+
| `options` | `object` | No | Connection options |
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
## Configuration Options
|
|
91
|
+
|
|
92
|
+
| Option | Type | Default | Description |
|
|
93
|
+
| ------------------- | --------- | --------------- | ------------------------------- |
|
|
94
|
+
| `host` | `string` | `eu-central-1.wireblob.com` | Wireblob server hostname |
|
|
95
|
+
| `secure` | `boolean` | `true` | Use secure websocket connection |
|
|
96
|
+
| `wsPort` | `number` | `80` | WebSocket port |
|
|
97
|
+
| `wssPort` | `number` | `443` | Secure WebSocket port |
|
|
98
|
+
| `enabledTransports` | `array` | `['ws', 'wss']` | Allowed transports |
|
|
99
|
+
| `authEndpoint` | `string` | `null` | Private/presence auth endpoint |
|
|
100
|
+
| `auth` | `object` | `{}` | Additional auth configuration |
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
## Subscribing to Channels
|
|
104
|
+
|
|
105
|
+
```js
|
|
106
|
+
const channel = wire.subscribe('chat-room');
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Listening for Events
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
channel.bind('message', (data) => {
|
|
113
|
+
console.log(data);
|
|
114
|
+
});
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
## Triggering Events
|
|
118
|
+
|
|
119
|
+
Client-triggered events require private or presence channels.
|
|
120
|
+
|
|
121
|
+
```js
|
|
122
|
+
channel.trigger('client-message', {
|
|
123
|
+
text: 'Hello world'
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Unsubscribing
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
wire.unsubscribe('chat-room');
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## Connection Events
|
|
134
|
+
|
|
135
|
+
### Connected
|
|
136
|
+
|
|
137
|
+
```js
|
|
138
|
+
wire.connection.bind('connected', () => {
|
|
139
|
+
console.log('Connected');
|
|
140
|
+
});
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Error
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
wire.connection.bind('error', (error) => {
|
|
147
|
+
console.error(error);
|
|
148
|
+
});
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Disconnected
|
|
152
|
+
|
|
153
|
+
```js
|
|
154
|
+
wire.connection.bind('disconnected', () => {
|
|
155
|
+
console.log('Disconnected');
|
|
156
|
+
});
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Manual Connect / Disconnect
|
|
160
|
+
|
|
161
|
+
```js
|
|
162
|
+
wire.connect();
|
|
163
|
+
wire.disconnect();
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
## Private Channels
|
|
168
|
+
|
|
169
|
+
```js
|
|
170
|
+
const channel = wire.subscribe('private-chat');
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Server Auth Endpoint (Laravel example)
|
|
174
|
+
|
|
175
|
+
```php
|
|
176
|
+
Route::post('/broadcasting/auth', function () {
|
|
177
|
+
return Broadcast::auth(request());
|
|
178
|
+
});
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
## Presence Channels
|
|
182
|
+
|
|
183
|
+
```js
|
|
184
|
+
const channel = wire.subscribe('presence-room');
|
|
185
|
+
|
|
186
|
+
channel.bind('pusher:subscription_succeeded', (members) => {
|
|
187
|
+
console.log(members);
|
|
188
|
+
});
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
## Node.js Usage
|
|
193
|
+
|
|
194
|
+
Install websocket support:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
npm install ws
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```js
|
|
201
|
+
import Wire from '@wireblob/wire';
|
|
202
|
+
import WebSocket from 'ws';
|
|
203
|
+
|
|
204
|
+
global.WebSocket = WebSocket;
|
|
205
|
+
|
|
206
|
+
const wire = new Wire('YOUR_APP_KEY', {
|
|
207
|
+
host: 'eu-central-1.wireblob.com',
|
|
208
|
+
secure: true
|
|
209
|
+
});
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## React Native
|
|
213
|
+
|
|
214
|
+
Wire works in React Native environments supporting WebSocket.
|
|
215
|
+
|
|
216
|
+
```js
|
|
217
|
+
import Wire from '@wireblob/wire';
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Web Workers
|
|
221
|
+
|
|
222
|
+
```js
|
|
223
|
+
import Wire from '@wireblob/wire/worker';
|
|
224
|
+
|
|
225
|
+
const wire = new Wire('YOUR_APP_KEY', {
|
|
226
|
+
host: 'eu-central-1.wireblob.com'
|
|
227
|
+
});
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
## Advanced Configuration
|
|
232
|
+
|
|
233
|
+
```js
|
|
234
|
+
const wire = new Wire('YOUR_APP_KEY', {
|
|
235
|
+
host: 'eu-central-1.wireblob.com',
|
|
236
|
+
secure: true,
|
|
237
|
+
wsPort: 80,
|
|
238
|
+
wssPort: 443,
|
|
239
|
+
enabledTransports: ['ws', 'wss'],
|
|
240
|
+
authEndpoint: '/broadcasting/auth',
|
|
241
|
+
auth: {
|
|
242
|
+
headers: {
|
|
243
|
+
Authorization: 'Bearer TOKEN'
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
## Debugging
|
|
251
|
+
|
|
252
|
+
Enable internal Pusher logging:
|
|
253
|
+
|
|
254
|
+
```js
|
|
255
|
+
Wire.logToConsole = true;
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
## Architecture
|
|
260
|
+
|
|
261
|
+
Wire is:
|
|
262
|
+
|
|
263
|
+
- protocol-compatible with Pusher Channels
|
|
264
|
+
- transport-compatible with standard WebSocket infrastructure
|
|
265
|
+
- designed for Wireblob-native extensions
|
|
266
|
+
|
|
267
|
+
Current implementation:
|
|
268
|
+
|
|
269
|
+
- wraps `pusher-js`
|
|
270
|
+
- applies Wireblob defaults
|
|
271
|
+
- exposes a stable SDK surface
|
|
272
|
+
|
|
273
|
+
Future versions may introduce:
|
|
274
|
+
|
|
275
|
+
- native Wire transport
|
|
276
|
+
- SSE support
|
|
277
|
+
- QUIC/WebTransport
|
|
278
|
+
- MQTT adapters
|
|
279
|
+
- custom protocol optimizations
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
## Compatibility
|
|
283
|
+
|
|
284
|
+
| Platform | Supported |
|
|
285
|
+
| ------------ | --------- |
|
|
286
|
+
| Browser | Yes |
|
|
287
|
+
| Node.js | Yes |
|
|
288
|
+
| React Native | Yes |
|
|
289
|
+
| Web Workers | Yes |
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
## Credits
|
|
293
|
+
- [Pusher](https://pusher.com) - Protocol and transport compatibility
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _pusherJs = _interopRequireDefault(require("pusher-js"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
const DEFAULT_HOST = 'eu-central-1.wireblob.com';
|
|
10
|
+
class Wire {
|
|
11
|
+
constructor(appKey, options = {}) {
|
|
12
|
+
if (!appKey || typeof appKey !== 'string') {
|
|
13
|
+
throw new TypeError('Wire requires a valid appKey string.');
|
|
14
|
+
}
|
|
15
|
+
const secure = options.secure ?? true;
|
|
16
|
+
const host = options.host ?? DEFAULT_HOST;
|
|
17
|
+
const pusherOptions = {
|
|
18
|
+
wsHost: host,
|
|
19
|
+
forceTLS: secure,
|
|
20
|
+
wsPort: options.wsPort ?? 80,
|
|
21
|
+
wssPort: options.wssPort ?? 443,
|
|
22
|
+
enabledTransports: options.enabledTransports ?? ['ws', 'wss'],
|
|
23
|
+
cluster: ''
|
|
24
|
+
};
|
|
25
|
+
if (options.authEndpoint) {
|
|
26
|
+
pusherOptions.authEndpoint = options.authEndpoint;
|
|
27
|
+
}
|
|
28
|
+
if (options.auth) {
|
|
29
|
+
pusherOptions.auth = options.auth;
|
|
30
|
+
}
|
|
31
|
+
this.pusher = new _pusherJs.default(appKey, pusherOptions);
|
|
32
|
+
this.connection = this.pusher.connection;
|
|
33
|
+
}
|
|
34
|
+
subscribe(channelName) {
|
|
35
|
+
return this.pusher.subscribe(channelName);
|
|
36
|
+
}
|
|
37
|
+
unsubscribe(channelName) {
|
|
38
|
+
this.pusher.unsubscribe(channelName);
|
|
39
|
+
}
|
|
40
|
+
connect() {
|
|
41
|
+
this.pusher.connect();
|
|
42
|
+
}
|
|
43
|
+
disconnect() {
|
|
44
|
+
this.pusher.disconnect();
|
|
45
|
+
}
|
|
46
|
+
static get logToConsole() {
|
|
47
|
+
return _pusherJs.default.logToConsole;
|
|
48
|
+
}
|
|
49
|
+
static set logToConsole(value) {
|
|
50
|
+
_pusherJs.default.logToConsole = Boolean(value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var _default = exports.default = Wire;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _wire = _interopRequireDefault(require("./wire"));
|
|
8
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
+
var _default = exports.default = _wire.default;
|
package/lib/es/wire.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import Pusher from 'pusher-js';
|
|
2
|
+
const DEFAULT_HOST = 'eu-central-1.wireblob.com';
|
|
3
|
+
class Wire {
|
|
4
|
+
constructor(appKey) {
|
|
5
|
+
var _options$secure, _options$host, _options$wsPort, _options$wssPort, _options$enabledTrans;
|
|
6
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
7
|
+
if (!appKey || typeof appKey !== 'string') {
|
|
8
|
+
throw new TypeError('Wire requires a valid appKey string.');
|
|
9
|
+
}
|
|
10
|
+
const secure = (_options$secure = options.secure) !== null && _options$secure !== void 0 ? _options$secure : true;
|
|
11
|
+
const host = (_options$host = options.host) !== null && _options$host !== void 0 ? _options$host : DEFAULT_HOST;
|
|
12
|
+
const pusherOptions = {
|
|
13
|
+
wsHost: host,
|
|
14
|
+
forceTLS: secure,
|
|
15
|
+
wsPort: (_options$wsPort = options.wsPort) !== null && _options$wsPort !== void 0 ? _options$wsPort : 80,
|
|
16
|
+
wssPort: (_options$wssPort = options.wssPort) !== null && _options$wssPort !== void 0 ? _options$wssPort : 443,
|
|
17
|
+
enabledTransports: (_options$enabledTrans = options.enabledTransports) !== null && _options$enabledTrans !== void 0 ? _options$enabledTrans : ['ws', 'wss'],
|
|
18
|
+
cluster: ''
|
|
19
|
+
};
|
|
20
|
+
if (options.authEndpoint) {
|
|
21
|
+
pusherOptions.authEndpoint = options.authEndpoint;
|
|
22
|
+
}
|
|
23
|
+
if (options.auth) {
|
|
24
|
+
pusherOptions.auth = options.auth;
|
|
25
|
+
}
|
|
26
|
+
this.pusher = new Pusher(appKey, pusherOptions);
|
|
27
|
+
this.connection = this.pusher.connection;
|
|
28
|
+
}
|
|
29
|
+
subscribe(channelName) {
|
|
30
|
+
return this.pusher.subscribe(channelName);
|
|
31
|
+
}
|
|
32
|
+
unsubscribe(channelName) {
|
|
33
|
+
this.pusher.unsubscribe(channelName);
|
|
34
|
+
}
|
|
35
|
+
connect() {
|
|
36
|
+
this.pusher.connect();
|
|
37
|
+
}
|
|
38
|
+
disconnect() {
|
|
39
|
+
this.pusher.disconnect();
|
|
40
|
+
}
|
|
41
|
+
static get logToConsole() {
|
|
42
|
+
return Pusher.logToConsole;
|
|
43
|
+
}
|
|
44
|
+
static set logToConsole(value) {
|
|
45
|
+
Pusher.logToConsole = Boolean(value);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export default Wire;
|
package/lib/es/worker.js
ADDED