Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@kesha-antonov/react-native-action-cable

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@kesha-antonov/react-native-action-cable - npm Package Compare versions

Comparing version 1.1.4 to 1.1.5

2

dist/action_cable/action_cable.js

@@ -1,1 +0,1 @@

var ActionCable,Consumer;Consumer=require("./consumer").default,ActionCable={INTERNAL:require("./internal"),WebSocket:window.WebSocket,logger:window.console,createConsumer:function(e){return new Consumer(e,this.log,this.WebSocket)},startDebugging:function(){return this.debugging=!0},stopDebugging:function(){return this.debugging=null},log:function(...e){if(ActionCable.debugging)return e.push(Date.now()),ActionCable.logger.log("[ActionCable]",...e)}};export default ActionCable;
var ActionCable,Consumer;Consumer=require("./consumer").default,ActionCable={INTERNAL:require("./internal"),WebSocket:window.WebSocket,logger:window.console,createConsumer:function(e,n={}){return new Consumer(e,this.log,this.WebSocket,n)},startDebugging:function(){return this.debugging=!0},stopDebugging:function(){return this.debugging=null},log:function(...e){if(ActionCable.debugging)return e.push(Date.now()),ActionCable.logger.log("[ActionCable]",...e)}};export default ActionCable;

@@ -1,1 +0,1 @@

var Connection,ConnectionMonitor,message_types,protocols,supportedProtocols,unsupportedProtocol,splice=[].splice,indexOf=[].indexOf;({message_types:message_types,protocols:protocols}=require("./internal").default),ConnectionMonitor=require("./connection_monitor").default,[...supportedProtocols]=protocols,[unsupportedProtocol]=splice.call(supportedProtocols,-1),Connection=function(){class t{constructor(t,e,s){this.send=this.send.bind(this),this.open=this.open.bind(this),this.close=this.close.bind(this),this.reopen=this.reopen.bind(this),this.getProtocol=this.getProtocol.bind(this),this.isOpen=this.isOpen.bind(this),this.isActive=this.isActive.bind(this),this.isProtocolSupported=this.isProtocolSupported.bind(this),this.isState=this.isState.bind(this),this.getState=this.getState.bind(this),this.installEventHandlers=this.installEventHandlers.bind(this),this.uninstallEventHandlers=this.uninstallEventHandlers.bind(this),this.consumer=t,this.log=e,this.WebSocket=s,({subscriptions:this.subscriptions}=this.consumer),this.monitor=new ConnectionMonitor(this,this.log),this.disconnected=!0}send(t){return!!this.isOpen()&&(this.webSocket.send(JSON.stringify(t)),!0)}open(){return this.isActive()?(this.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1):(this.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`),null!=this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new this.WebSocket(this.consumer.url,protocols),this.installEventHandlers(),this.monitor.start(),!0)}close({allowReconnect:t}={allowReconnect:!0}){var e;if(t||this.monitor.stop(),this.isActive())return null!=(e=this.webSocket)?e.close():void 0}reopen(){var t;if(this.log(`Reopening WebSocket, current state is ${this.getState()}`),!this.isActive())return this.open();try{return this.close()}catch(e){return t=e,this.log("Failed to reopen WebSocket",t)}finally{this.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}}getProtocol(){var t;return null!=(t=this.webSocket)?t.protocol:void 0}isOpen(){return this.isState("open")}isActive(){return this.isState("open","connecting")}isProtocolSupported(){var t;return t=this.getProtocol(),indexOf.call(supportedProtocols,t)>=0}isState(...t){var e;return e=this.getState(),indexOf.call(t,e)>=0}getState(){var t,e;for(e in WebSocket)if(WebSocket[e]===(null!=(t=this.webSocket)?t.readyState:void 0))return e.toLowerCase();return null}installEventHandlers(){var t,e;for(t in this.events)e=this.events[t].bind(this),this.webSocket[`on${t}`]=e}uninstallEventHandlers(){var t;for(t in this.events)this.webSocket[`on${t}`]=()=>{}}}return t.reopenDelay=500,t.prototype.events={message:function(t){var e,s,o;if(this.isProtocolSupported())switch(({identifier:e,message:s,type:o}=JSON.parse(t.data)),null!=t.data.close&&t.data.close(),o){case message_types.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case message_types.ping:return this.monitor.recordPing();case message_types.confirmation:return this.subscriptions.notify(e,"connected");case message_types.rejection:return this.subscriptions.reject(e);default:return this.subscriptions.notify(e,"received",s)}else null!=t.data.close&&t.data.close()},open:function(){if(this.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return this.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close:function(t){if(this.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error:function(){return this.log("WebSocket onerror event")}},t}.call(this);export default Connection;
var Connection,ConnectionMonitor,message_types,protocols,supportedProtocols,unsupportedProtocol,splice=[].splice,indexOf=[].indexOf;({message_types:message_types,protocols:protocols}=require("./internal").default),ConnectionMonitor=require("./connection_monitor").default,[...supportedProtocols]=protocols,[unsupportedProtocol]=splice.call(supportedProtocols,-1),Connection=function(){class t{constructor(t,e,s){this.send=this.send.bind(this),this.open=this.open.bind(this),this.close=this.close.bind(this),this.reopen=this.reopen.bind(this),this.getProtocol=this.getProtocol.bind(this),this.isOpen=this.isOpen.bind(this),this.isActive=this.isActive.bind(this),this.isProtocolSupported=this.isProtocolSupported.bind(this),this.isState=this.isState.bind(this),this.getState=this.getState.bind(this),this.installEventHandlers=this.installEventHandlers.bind(this),this.uninstallEventHandlers=this.uninstallEventHandlers.bind(this),this.consumer=t,this.log=e,this.WebSocket=s,({subscriptions:this.subscriptions}=this.consumer),this.monitor=new ConnectionMonitor(this,this.log),this.disconnected=!0}send(t){return!!this.isOpen()&&(this.webSocket.send(JSON.stringify(t)),!0)}open(){return this.isActive()?(this.log(`Attempted to open WebSocket, but existing socket is ${this.getState()}`),!1):(this.log(`Opening WebSocket, current state is ${this.getState()}, subprotocols: ${protocols}`),null!=this.webSocket&&this.uninstallEventHandlers(),this.webSocket=new this.WebSocket(this.consumer.url,protocols,{headers:this.consumer.headers}),this.installEventHandlers(),this.monitor.start(),!0)}close({allowReconnect:t}={allowReconnect:!0}){var e;if(t||this.monitor.stop(),this.isActive())return null!=(e=this.webSocket)?e.close():void 0}reopen(){var t;if(this.log(`Reopening WebSocket, current state is ${this.getState()}`),!this.isActive())return this.open();try{return this.close()}catch(e){return t=e,this.log("Failed to reopen WebSocket",t)}finally{this.log(`Reopening WebSocket in ${this.constructor.reopenDelay}ms`),setTimeout(this.open,this.constructor.reopenDelay)}}getProtocol(){var t;return null!=(t=this.webSocket)?t.protocol:void 0}isOpen(){return this.isState("open")}isActive(){return this.isState("open","connecting")}isProtocolSupported(){var t;return t=this.getProtocol(),indexOf.call(supportedProtocols,t)>=0}isState(...t){var e;return e=this.getState(),indexOf.call(t,e)>=0}getState(){var t,e;for(e in WebSocket)if(WebSocket[e]===(null!=(t=this.webSocket)?t.readyState:void 0))return e.toLowerCase();return null}installEventHandlers(){var t,e;for(t in this.events)e=this.events[t].bind(this),this.webSocket[`on${t}`]=e}uninstallEventHandlers(){var t;for(t in this.events)this.webSocket[`on${t}`]=()=>{}}}return t.reopenDelay=500,t.prototype.events={message:function(t){var e,s,o;if(this.isProtocolSupported())switch(({identifier:e,message:s,type:o}=JSON.parse(t.data)),null!=t.data.close&&t.data.close(),o){case message_types.welcome:return this.monitor.recordConnect(),this.subscriptions.reload();case message_types.ping:return this.monitor.recordPing();case message_types.confirmation:return this.subscriptions.notify(e,"connected");case message_types.rejection:return this.subscriptions.reject(e);default:return this.subscriptions.notify(e,"received",s)}else null!=t.data.close&&t.data.close()},open:function(){if(this.log(`WebSocket onopen event, using '${this.getProtocol()}' subprotocol`),this.disconnected=!1,!this.isProtocolSupported())return this.log("Protocol is unsupported. Stopping monitor and disconnecting."),this.close({allowReconnect:!1})},close:function(t){if(this.log("WebSocket onclose event"),!this.disconnected)return this.disconnected=!0,this.monitor.recordDisconnect(),this.subscriptions.notifyAll("disconnected",{willAttemptReconnect:this.monitor.isRunning()})},error:function(){return this.log("WebSocket onerror event")}},t}.call(this);export default Connection;

@@ -1,1 +0,1 @@

var Connection,Consumer,Subscriptions;Connection=require("./connection").default,Subscriptions=require("./subscriptions").default,Consumer=class{constructor(n,t,e){this.send=this.send.bind(this),this.connect=this.connect.bind(this),this.disconnect=this.disconnect.bind(this),this.ensureActiveConnection=this.ensureActiveConnection.bind(this),this.log=t,this.WebSocket=e,this.subscriptions=new Subscriptions(this),this.connection=new Connection(this,this.log,this.WebSocket),Object.defineProperty(this,"url",{get:function(){return this.createWebSocketURL(n)},configurable:!0})}send(n){return this.connection.send(n)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}createWebSocketURL(n){var t;return(n=null!=(t="function"==typeof n?n():void 0)?t:n)&&!/^wss?:/i.test(n)&&(n=n.replace("http","ws")),n}};export default Consumer;
var Connection,Consumer,Subscriptions;Connection=require("./connection").default,Subscriptions=require("./subscriptions").default,Consumer=class{constructor(n,e,t,i={}){this.send=this.send.bind(this),this.connect=this.connect.bind(this),this.disconnect=this.disconnect.bind(this),this.ensureActiveConnection=this.ensureActiveConnection.bind(this),this.log=e,this.WebSocket=t,this.subscriptions=new Subscriptions(this),this.connection=new Connection(this,this.log,this.WebSocket),Object.defineProperty(this,"url",{get:function(){return this.createWebSocketURL(n)},configurable:!0}),Object.defineProperty(this,"headers",{value:i,configurable:!0})}send(n){return this.connection.send(n)}connect(){return this.connection.open()}disconnect(){return this.connection.close({allowReconnect:!1})}ensureActiveConnection(){if(!this.connection.isActive())return this.connection.open()}createWebSocketURL(n){var e;return(n=null!=(e="function"==typeof n?n():void 0)?e:n)&&!/^wss?:/i.test(n)&&(n=n.replace("http","ws")),n}};export default Consumer;
{
"name": "@kesha-antonov/react-native-action-cable",
"version": "1.1.4",
"version": "1.1.5",
"description": "Use Rails 5+ ActionCable channels with React Native for realtime magic.",

@@ -29,13 +29,13 @@ "main": "index.js",

"devDependencies": {
"coffee-loader": "^4.0.0",
"coffee-script": "^1.12.7",
"del": "^7.0.0",
"coffee-loader": "^5.0.0",
"coffeescript": "^2.7.0",
"del": "^7.1.0",
"gulp": "^4.0.2",
"gulp-coffee": "^3.0.3",
"gulp-uglify-es": "^3.0.0",
"webpack": "^5.75.0",
"webpack": "^5.90.3",
"webpack-stream": "^7.0.0"
},
"dependencies": {
"eventemitter3": "4.0.7"
"eventemitter3": "5.0.1"
},

@@ -42,0 +42,0 @@ "directories": {

@@ -175,3 +175,5 @@ [![npm version](https://badge.fury.io/js/action-cable-react.svg)](https://badge.fury.io/js/action-cable-react)

- **`.createConsumer(websocketUrl)`** - create actionCable consumer and start connecting
- **`.createConsumer(websocketUrl, headers = {})`** - create actionCable consumer and start connecting.
- `websocketUrl` - url to your Rails app's `cable` endpoint
- `headers` - headers to send with connection request
- **`.startDebugging()`** - start logging

@@ -197,6 +199,15 @@ - **`.stopDebugging()`** - stop logging

- **`.perform(action, data)`** - send message to channel. action - `string`, data - `json`
- **`.on(eventName, eventListener)`** - subscribe to events. eventName can be `received`, `connected`, `rejected`, `disconnected`
- **`.removeListener(eventName, eventListener)`** - unsubscribe from event
- **`.unsubscribe()`** - unsubscribe from channel
- **`.on(eventName, eventListener)`** - subscribe to events. eventName can be `received`, `connected`, `rejected`, `disconnected` or value of `data.action` attribute from channel message payload.
Custom action example:
```rb
{
"identifier": "{\"channel\":\"ChatChannel\",\"id\":42}",
"command": "message",
"data": "{\"action\":\"speak\",\"text\":\"hello!\"}"
}
```
Above message will be emited with `eventName = 'speak'`

@@ -203,0 +214,0 @@ ## Contributing

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc