{"id":14955559,"url":"https://github.com/hosopy/actioncable-client-java","last_synced_at":"2025-10-01T18:31:38.235Z","repository":{"id":69249893,"uuid":"46917471","full_name":"hosopy/actioncable-client-java","owner":"hosopy","description":"Actioncable client library for Java","archived":false,"fork":false,"pushed_at":"2024-06-12T11:06:44.000Z","size":170,"stargazers_count":72,"open_issues_count":3,"forks_count":26,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-01-13T11:11:14.899Z","etag":null,"topics":["actioncable","java","rails5"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hosopy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-11-26T09:40:48.000Z","updated_at":"2024-10-18T09:22:25.000Z","dependencies_parsed_at":"2024-06-12T12:24:11.286Z","dependency_job_id":null,"html_url":"https://github.com/hosopy/actioncable-client-java","commit_stats":{"total_commits":46,"total_committers":6,"mean_commits":7.666666666666667,"dds":0.5434782608695652,"last_synced_commit":"7081784a876d13812d496d04fe6369044ddbdcbd"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hosopy%2Factioncable-client-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hosopy","download_url":"https://codeload.github.com/hosopy/actioncable-client-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234724146,"owners_count":18877146,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["actioncable","java","rails5"],"created_at":"2024-09-24T13:11:22.099Z","updated_at":"2025-10-01T18:31:32.951Z","avatar_url":"https://github.com/hosopy.png","language":"Java","readme":"# actioncable-client-java\n\n[![Build Status](https://travis-ci.org/hosopy/actioncable-client-java.svg)](https://travis-ci.org/hosopy/actioncable-client-java)\n[![Release](https://jitpack.io/v/hosopy/actioncable-client-java.svg)](https://jitpack.io/#hosopy/actioncable-client-java)\n\nThis is the actioncable client library for Java.\nPlease see [Action Cable Overview](http://guides.rubyonrails.org/action_cable_overview.html) to understand actioncable itself.\n\n## Usage\n\nGradle\n\n```groovy\nrepositories {\n    jcenter()\n    maven { url \"https://jitpack.io\" }\n}\n\ndependencies {\n    implementation 'com.github.hosopy:actioncable-client-java:0.1.2'\n}\n```\n\nThis Library uses [google/gson](https://github.com/google/gson) to parse and compose JSON strings.\n\nPlease see [user guide](https://sites.google.com/site/gson/gson-user-guide) to know about GSON API.\n\n### Basic\n\n```java\n// 1. Setup\nURI uri = new URI(\"ws://cable.example.com\");\nConsumer consumer = ActionCable.createConsumer(uri);\n\n// or specify some options\nURI uri = new URI(\"ws://cable.example.com\");\nConsumer.Options options = new Consumer.Options();\noptions.reconnection = true;\noptions.pingInterval = 30l;\noptions.pingTimeUnit = TimeUnit.SECONDS;\nConsumer consumer = ActionCable.createConsumer(uri, options);\n\n// 2. Create subscription\nChannel appearanceChannel = new Channel(\"AppearanceChannel\");\nSubscription subscription = consumer.getSubscriptions().create(appearanceChannel);\n\nsubscription\n    .onConnected(new Subscription.ConnectedCallback() {\n        @Override\n        public void call() {\n            // Called when the subscription has been successfully completed\n        }\n    }).onRejected(new Subscription.RejectedCallback() {\n        @Override\n        public void call() {\n            // Called when the subscription is rejected by the server\n        }\n    }).onReceived(new Subscription.ReceivedCallback() {\n        @Override\n        public void call(JsonElement data) {\n            // Called when the subscription receives data from the server\n        }\n    }).onDisconnected(new Subscription.DisconnectedCallback() {\n        @Override\n        public void call() {\n            // Called when the subscription has been closed\n        }\n    }).onFailed(new Subscription.FailedCallback() {\n        @Override\n        public void call(ActionCableException e) {\n            // Called when the subscription encounters any error\n        }\n    });\n\n// 3. Establish connection\nconsumer.connect();\n\nif(consumer.isConnected()) {\n    System.out.println(\"Consumer connected!\");\n}\n\n// 4. Perform any action\nsubscription.perform(\"away\");\n\n// 5. Perform any action using JsonObject(GSON)\nJsonObject params = new JsonObject();\nparams.addProperty(\"foo\", \"bar\");\nsubscription.perform(\"appear\", params);\n\n// 6. Unsubscribe \u0026 close connection\nconsumer.unsubscribeAndDisconnect();\n```\n\n### Passing Parameters to Channel\n\n```java\nChannel chatChannel = new Channel(\"ChatChannel\");\nchatChannel.addParam(\"room\", \"Best Room\");\nSubscription subscription = consumer.getSubscriptions().create(chatChannel);\n```\n\nSupported parameter type is `Number`, `String`, `Boolean` and `JsonElement(GSON)`.\n\n```java\nchatChannel.addParam(\"room_id\", 1);\nchatChannel.addParam(\"room\", \"Best Room\");\nchatChannel.addParam(\"private\", true);\nchatChannel.addParam(\"params\", new JsonObject());\n```\n\n### Custom Subscription Interface\n\nYou can perform any action by calling `Subscription#perform()`, but you can define custom interfaces having methods.\n\n```java\npublic interface ChatSubscription extends Subscription {\n    /*\n     * Equivalent:\n     *   perform(\"join\")\n     */\n    @Perform(\"join\")\n    void join();\n\n    /*\n     * Equivalent:\n     *   perform(\"send_message\", JsonObjectFactory.fromJson(\"{body: \\\"...\\\", private: true}\"))\n     */\n    @Perform(\"send_message\")\n    void sendMessage(@Data(\"body\") String body, @Data(\"private\") boolean isPrivate);\n}\n```\n\nSupported parameter type is `Number`, `String`, `Boolean` and `JsonElement(GSON)`.\n\nTo instantiate the custom subscription, pass the interface when you create a subscription.\n\n```java\nChannel chatChannel = new Channel(\"ChatChannel\");\nChatSubscription subscription = consumer.getSubscriptions().create(appearanceChannel, ChatSubscription.class);\n\nconsumer.open();\n\nsubscription.join();\nsubscription.sendMessage(\"Hello\", true);\n```\n\n### Options\n\n```java\nURI uri = new URI(\"ws://cable.example.com\");\n\nConsumer.Options options = new Consumer.Options();\noptions.reconnection = true;\n\nConsumer consumer = ActionCable.createConsumer(uri, options);\n```\n\nBelow is a list of available options.\n\n* sslContext\n    \n    ```java\n    options.sslContext = yourSSLContextInstance;\n    ```\n    \n* hostnameVerifier\n    \n    ```java\n    options.hostnameVerifier = yourHostnameVerifier;\n    ```\n    \n* cookieHandler\n    \n    ```java\n    options.cookieHandler = yourCookieManagerInstance;\n    ```\n    \n* query\n    \n    ```java\n    Map\u003cString, String\u003e query = new HashMap();\n    query.put(\"foo\", \"bar\");\n    options.query = query;\n    ```\n    \n* headers\n    \n    ```java\n    Map\u003cString, String\u003e headers = new HashMap();\n    headers.put(\"X-FOO\", \"bar\");\n    headers.put(\"Origin\", \"https://your-origin.tld\");\n    options.headers = headers;\n    ```\n    \n* reconnection\n    * If reconnection is true, the client attempts to reconnect to the server when underlying connection is stale.\n    * Default is `false`.\n    \n    ```java\n    options.reconnection = false;\n    ```\n    \n* reconnectionMaxAttempts\n    * The maximum number of attempts to reconnect.\n    * Default is `30`.\n    \n    ```java\n    options.reconnectionMaxAttempts = 30;\n    ```\n\n* okHttpClientFactory\n    * Factory instance to create your own OkHttpClient.\n    * If `okHttpClientFactory` is not set, just create OkHttpClient by `new OkHttpClient()`.\n    \n    ```java\n    options.okHttpClientFactory = new Connection.Options.OkHttpClientFactory() {\n        @Override\n        public OkHttpClient createOkHttpClient() {\n            final OkHttpClient client = new OkHttpClient();\n            client.networkInterceptors().add(new StethoInterceptor());\n            return client;\n        }\n    };\n    ```\n\n### Authentication\n\nHow to authenticate a request depends on the architecture you choose.\n\n#### Authenticate by HTTP Header\n\n```java\nConsumer.Options options = new Consumer.Options();\n\nMap\u003cString, String\u003e headers = new HashMap();\nheaders.put(\"Authorization\", \"Bearer xxxxxxxxxxx\");\noptions.headers = headers;\n\nConsumer consumer = ActionCable.createConsumer(uri, options);\n```\n\n#### Authenticate by Query Params\n\n```java\nConsumer.Options options = new Consumer.Options();\n\nMap\u003cString, String\u003e query = new HashMap();\nquery.put(\"access_token\", \"xxxxxxxxxx\");\noptions.query = query;\n\nConsumer consumer = ActionCable.createConsumer(uri, options);\n```\n\n#### Authenticate by Cookie\n\n```java\nCookieManager cookieManager = new CookieManager();\n// Some setup\n...\noptions.cookieHandler = cookieManager;\n\nConsumer consumer = ActionCable.createConsumer(uri, options);\n```\n\n### Proguard Rules\n\n```java\n-keep class com.hosopy.actioncable.** { *; }\n-keep interface com.hosopy.actioncable._* { *; }\n```\n\n## License\n\nMIT\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosopy%2Factioncable-client-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhosopy%2Factioncable-client-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhosopy%2Factioncable-client-java/lists"}