react-native-action-cable 3.0.1

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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +125 -0
  3. package/index.ts +4 -0
  4. package/package.json +46 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Zach Schneider
4
+ Copyright (c) 2016-present Innokentii Antonov
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
7
+ this software and associated documentation files (the "Software"), to deal in
8
+ the Software without restriction, including without limitation the rights to
9
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
10
+ the Software, and to permit persons to whom the Software is furnished to do so,
11
+ subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ <p align="center">
2
+ <a href="https://github.com/kesha-antonov/react-native-action-cable/actions/workflows/ci.yml"><img src="https://github.com/kesha-antonov/react-native-action-cable/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
3
+ <a href="https://www.npmjs.com/package/react-native-action-cable"><img src="https://badge.fury.io/js/react-native-action-cable.svg" alt="npm version"></a>
4
+ <a href="https://npm-stat.com/charts.html?package=%40kesha-antonov%2Freact-native-action-cable&from=2015-01-01"><img src="https://img.shields.io/badge/total%20downloads-580k-blue.svg" alt="total npm downloads"></a>
5
+ <a href="https://github.com/kesha-antonov/react-native-action-cable/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="license"></a>
6
+ <img src="https://img.shields.io/badge/platforms-iOS%20%7C%20Android%20%7C%20Web-lightgrey.svg" alt="platforms">
7
+ <img src="https://img.shields.io/badge/TypeScript-supported-blue.svg" alt="TypeScript">
8
+ </p>
9
+
10
+ <h1 align="center">React Native ActionCable</h1>
11
+
12
+ <p align="center">
13
+ Use Rails ActionCable channels with React Native for real-time WebSocket communication.
14
+ </p>
15
+
16
+ <p align="center">
17
+ <sub>Maintained by <a href="https://github.com/kesha-antonov">Kesha Antonov</a>, who also builds <a href="https://cryptoc-app.web.app/"><strong>cryptoc</strong></a> - a crypto portfolio app with home screen and Watch widgets.</sub>
18
+ </p>
19
+
20
+ ---
21
+
22
+ > **Note**
23
+ > This package is an alias for
24
+ > [`@kesha-antonov/react-native-action-cable`](https://www.npmjs.com/package/@kesha-antonov/react-native-action-cable)
25
+ > and re-exports it in full. Both names give you the same library, the same
26
+ > version, and the same API - install whichever you prefer.
27
+
28
+ ---
29
+
30
+ ## ✨ Features
31
+
32
+ - 🔌 **WebSocket Connection** - Automatic connection management with reconnection support
33
+ - 📡 **Channel Subscriptions** - Subscribe to multiple ActionCable channels
34
+ - 🔄 **Auto-Reconnect** - Automatically reconnects when connection is lost
35
+ - 🔐 **Custom Headers** - Support for authentication and dynamic headers
36
+ - 📱 **React Native Ready** - Works without `window` object polyfills, on the New Architecture (pure JS, no native module)
37
+ - 🛡️ **Connection Reuse** - Prevent duplicate connections during hot reloads
38
+ - ⚡ **TypeScript** - Full TypeScript support included
39
+
40
+ ---
41
+
42
+ ## 📦 Installation
43
+
44
+ **Yarn**
45
+
46
+ ```bash
47
+ yarn add react-native-action-cable
48
+ ```
49
+
50
+ **npm**
51
+
52
+ ```bash
53
+ npm install react-native-action-cable
54
+ ```
55
+
56
+ No native module, no pod install, no config plugin - it is pure JavaScript and
57
+ runs in Expo Go as well as bare React Native.
58
+
59
+ ---
60
+
61
+ ## 🚀 Quick Start
62
+
63
+ ```typescript
64
+ import { ActionCable, Cable } from 'react-native-action-cable'
65
+
66
+ const actionCable = ActionCable.createConsumer('ws://localhost:3000/cable')
67
+ const cable = new Cable({})
68
+
69
+ const channel = cable.setChannel(
70
+ 'ChatChannel',
71
+ actionCable.subscriptions.create({
72
+ channel: 'ChatChannel',
73
+ roomId: 1
74
+ })
75
+ )
76
+
77
+ channel
78
+ .on('received', (data) => console.log('Received:', data))
79
+ .on('connected', () => console.log('Connected!'))
80
+ .on('disconnected', () => console.log('Disconnected'))
81
+
82
+ channel.perform('send_message', { text: 'Hello!' })
83
+
84
+ // later
85
+ channel.unsubscribe()
86
+ ```
87
+
88
+ ---
89
+
90
+ ## 📚 Documentation
91
+
92
+ Full API reference, advanced usage, testing patterns, and runnable examples live
93
+ in the main repository:
94
+
95
+ **[github.com/kesha-antonov/react-native-action-cable](https://github.com/kesha-antonov/react-native-action-cable#readme)**
96
+
97
+ | | |
98
+ |---|---|
99
+ | [API Reference](https://github.com/kesha-antonov/react-native-action-cable#-api-reference) | `ActionCable`, `Consumer`, `Cable`, `Channel` |
100
+ | [Custom Headers & Auth](https://github.com/kesha-antonov/react-native-action-cable#%EF%B8%8F-advanced-usage) | Static and dynamic auth headers |
101
+ | [Rails style channel mixins](https://github.com/kesha-antonov/react-native-action-cable#%EF%B8%8F-advanced-usage) | Port existing Rails channel code as-is |
102
+ | [Testing](https://github.com/kesha-antonov/react-native-action-cable#-testing) | Jest mocks and patterns |
103
+ | [Examples](https://github.com/kesha-antonov/react-native-action-cable/tree/master/examples) | Chat app, Apollo GraphQL, testing |
104
+
105
+ ---
106
+
107
+ ## 🤝 Contributing
108
+
109
+ Issues and pull requests belong in the
110
+ [main repository](https://github.com/kesha-antonov/react-native-action-cable).
111
+
112
+ ---
113
+
114
+ ## 👏 Credits
115
+
116
+ Based on [action-cable-react](https://github.com/schneidmaster/action-cable-react).
117
+ Code in `lib/action_cable` is adapted from [Rails ActionCable](https://github.com/rails/rails/tree/main/actioncable/app/javascript/action_cable).
118
+
119
+ > Please note that this project is maintained in free time. If you find it helpful, please consider [becoming a sponsor](https://github.com/sponsors/kesha-antonov).
120
+
121
+ ---
122
+
123
+ ## 📄 License
124
+
125
+ [MIT](https://github.com/kesha-antonov/react-native-action-cable/blob/master/LICENSE)
package/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ // `react-native-action-cable` is an alias for
2
+ // `@kesha-antonov/react-native-action-cable`. Both names resolve to the same
3
+ // implementation - this package only re-exports it so the unscoped name works.
4
+ export * from '@kesha-antonov/react-native-action-cable'
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "react-native-action-cable",
3
+ "version": "3.0.1",
4
+ "description": "Use Rails ActionCable channels with React Native for real-time WebSocket communication.",
5
+ "main": "index.ts",
6
+ "types": "index.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/kesha-antonov/react-native-action-cable.git"
10
+ },
11
+ "keywords": [
12
+ "react-native",
13
+ "expo",
14
+ "actioncable",
15
+ "action-cable",
16
+ "rails",
17
+ "ruby-on-rails",
18
+ "websocket",
19
+ "websockets",
20
+ "realtime",
21
+ "real-time",
22
+ "channels",
23
+ "subscriptions",
24
+ "chat",
25
+ "new-architecture",
26
+ "typescript"
27
+ ],
28
+ "author": "Kesha Antonov <innokenty.longway@gmail.com>",
29
+ "contributors": [
30
+ "Zach Schneider <zach@schneid.io>"
31
+ ],
32
+ "license": "MIT",
33
+ "files": [
34
+ "index.ts",
35
+ "README.md",
36
+ "LICENSE"
37
+ ],
38
+ "bugs": {
39
+ "url": "https://github.com/kesha-antonov/react-native-action-cable/issues"
40
+ },
41
+ "homepage": "https://github.com/kesha-antonov/react-native-action-cable#readme",
42
+ "dependencies": {
43
+ "@kesha-antonov/react-native-action-cable": "^3.0.1"
44
+ },
45
+ "type": "commonjs"
46
+ }