{"id":24264598,"url":"https://github.com/pusher/pusher-channels-flutter","last_synced_at":"2025-04-12T14:55:20.342Z","repository":{"id":37669508,"uuid":"408385868","full_name":"pusher/pusher-channels-flutter","owner":"pusher","description":"Pusher Channels client library for Flutter targeting IOS, Android, and WEB","archived":false,"fork":false,"pushed_at":"2024-12-30T11:48:31.000Z","size":541,"stargazers_count":76,"open_issues_count":39,"forks_count":143,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-04-12T03:52:51.632Z","etag":null,"topics":["android","dart","flutter","flutter-package","flutter-plugin","ios","pusher","pusher-channels"],"latest_commit_sha":null,"homepage":"","language":"Dart","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/pusher.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2021-09-20T09:40:12.000Z","updated_at":"2025-04-04T20:18:11.000Z","dependencies_parsed_at":"2024-02-08T16:59:33.983Z","dependency_job_id":"ca3e5a29-5488-4aa2-8f62-23648039f37f","html_url":"https://github.com/pusher/pusher-channels-flutter","commit_stats":{"total_commits":134,"total_committers":15,"mean_commits":8.933333333333334,"dds":0.6716417910447761,"last_synced_commit":"201e4de4b6e5de078d87ddc67026b8884635322b"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pusher%2Fpusher-channels-flutter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pusher%2Fpusher-channels-flutter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pusher%2Fpusher-channels-flutter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pusher%2Fpusher-channels-flutter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pusher","download_url":"https://codeload.github.com/pusher/pusher-channels-flutter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248586244,"owners_count":21128995,"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":["android","dart","flutter","flutter-package","flutter-plugin","ios","pusher","pusher-channels"],"created_at":"2025-01-15T09:32:25.597Z","updated_at":"2025-04-12T14:55:20.324Z","avatar_url":"https://github.com/pusher.png","language":"Dart","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pusher Channels Flutter Client\n\n[![Latest Release](https://img.shields.io/github/v/release/pusher/pusher-channels-flutter)](https://github.com/pusher/pusher-channels-flutter/releases)\n[![Twitter](https://img.shields.io/badge/twitter-@Pusher-blue.svg?style=flat)](http://twitter.com/Pusher)\n[![GitHub license](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/pusher/pusher-channels-flutter/master/LICENSE)\n[![likes](https://badges.bar/pusher_channels_flutter/likes)](https://pub.dev/packages/pusher_channels_flutter/score)\n[![popularity](https://badges.bar/pusher_channels_flutter/popularity)](https://pub.dev/packages/pusher_channels_flutter/score)\n[![pub points](https://badges.bar/pusher_channels_flutter/pub%20points)](https://pub.dev/packages/pusher_channels_flutter/score)\n\nThis is the [Pusher Channels](https://pusher.com/channels) Flutter client.\n\nFor tutorials and more in-depth information about Pusher Channels, visit our [official docs](https://pusher.com/docs/channels).\n\n## Supported Flutter platforms\n\n- Android through [pusher-websocket-java](https://github.com/pusher/pusher-websocket-java)\n- iOS through [pusher-websocket-swift](https://github.com/pusher/pusher-websocket-swift)\n- Web through [pusher-js](https://github.com/pusher/pusher-js)\n\n### Deployment targets\n\n- iOS 13.0 and above\n- Android 6.0 and above\n- Web Chrome/Edge/Firefox/Safari.\n\n## Example Application\n\nBy cloning this repository you can check the Flutter example application,\na minimal application to connect to a channel and send events.\n\n- https://github.com/pusher/pusher-channels-flutter/tree/master/example\n\n## Table of Contents\n\n- [Pusher Channels Flutter Client](#pusher-channels-flutter-client)\n  - [Supported Flutter platforms](#supported-flutter-platforms)\n    - [Deployment targets](#deployment-targets)\n  - [Example Application](#example-application)\n  - [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n    - [iOS specific installation](#ios-specific-installation)\n    - [Android specific installation](#android-specific-installation)\n    - [Web specific installation](#web-specific-installation)\n  - [Initialization](#initialization)\n  - [Configuration](#configuration)\n      - [`activityTimeout (double)`](#activitytimeout-double)\n      - [`apiKey (String)`](#apikey-string)\n      - [`authParams (Map)`](#authparams-map)\n      - [`authEndpoint (String)`](#authendpoint-string)\n      - [`cluster (String)`](#cluster-string)\n      - [`useTLS (bool)`](#usetls-bool)\n  - [Event Callback parameters](#event-callback-parameters)\n      - [`onEvent`](#onevent)\n      - [`onSubscriptionSucceeded`](#onsubscriptionsucceeded)\n      - [`onSubscriptionError`](#onsubscriptionerror)\n      - [`onDecryptionFailure`](#ondecryptionfailure)\n      - [`onMemberAdded`](#onmemberadded)\n      - [`onMemberRemoved`](#onmemberremoved)\n      - [`onAuthorizer`](#onauthorizer)\n      - [`onConnectionStateChange`](#onconnectionstatechange)\n      - [`onError`](#onerror)\n  - [Connection handling](#connection-handling)\n    - [Connecting](#connecting)\n    - [Disconnecting](#disconnecting)\n    - [Reconnection](#reconnection)\n  - [Subscribing](#subscribing)\n    - [Public channels](#public-channels)\n    - [Private channels](#private-channels)\n    - [Private encrypted channels](#private-encrypted-channels)\n      - [Limitations](#limitations)\n    - [Presence channels](#presence-channels)\n    - [Unsubscribing](#unsubscribing)\n  - [Binding to events](#binding-to-events)\n    - [Per-channel events](#per-channel-events)\n    - [Global events](#global-events)\n    - [PusherEvent](#pusherevent)\n      - [Parsing event data](#parsing-event-data)\n    - [Receiving errors](#receiving-errors)\n  - [Triggering events](#triggering-events)\n  - [Get a channel by name](#get-a-channel-by-name)\n  - [Socket information](#socket-information)\n  - [Communication](#communication)\n  - [Credits](#credits)\n  - [License](#license)\n\n## Installation\n\nTo integrate the plugin in your Flutter App, you need\nto add the plugin to your `pubspec.yaml`:\n\n```yaml\ndependencies:\n  pusher_channels_flutter: '^1.0.1'\n```\n\n### iOS specific installation\n\nThe Pusher Channels Flutter plugin adds the\npusher-websocket-swift cocoapod to your project.\nYou probably need to run a\n\n```bash\n$ pod install\n```\n\nin the ios directory.\n\n### Android specific installation\n\nGradle should automatically include the\npusher-websocket-java dependency.\n\n### Web specific installation\n\nFor web this plugin uses pusher-js, you can load it from the Pusher CDN, or add it locally. You\nprobably want to include it in the head of your\nindex.html page:\n\n```html\n\u003chead\u003e\n  \u003cscript\n    charset=\"utf-8\"\n    src=\"https://js.pusher.com/8.3.0/pusher.min.js\"\n  \u003e\u003c/script\u003e\n  ...\n\u003c/head\u003e\n```\n\n## Initialization\n\nThe PusherChannelFlutter class is a singleton, that\ncan be instantiated with `getInstance()`. Then you need to initialize the client with a number of configuration options, here is a quick example with a number of callbacks options:\n\n```dart\nPusherChannelsFlutter pusher = PusherChannelsFlutter.getInstance();\ntry {\n  await pusher.init(\n    apiKey: API_KEY,\n    cluster: API_CLUSTER,\n    onConnectionStateChange: onConnectionStateChange,\n    onError: onError,\n    onSubscriptionSucceeded: onSubscriptionSucceeded,\n    onEvent: onEvent,\n    onSubscriptionError: onSubscriptionError,\n    onDecryptionFailure: onDecryptionFailure,\n    onMemberAdded: onMemberAdded,\n    onMemberRemoved: onMemberRemoved,\n    // authEndpoint: \"\u003cYour Authendpoint\u003e\",\n    // onAuthorizer: onAuthorizer\n  );\n  await pusher.subscribe(channelName: 'presence-chatbox');\n  await pusher.connect();\n} catch (e) {\n  print(\"ERROR: $e\");\n}\n```\n\nAfter calling `init(...)` you can connect to the Pusher servers.\nYou can subscribe to channels before calling `connect()`\n\n## Configuration\n\nThere are a number of configuration parameters which can be set for the Pusher client. The following table\ndescribes for which platform the parameter is available:\n\n| parameter                | Android | iOS | Web |\n| ------------------------ | ------- | --- | --- |\n| activityTimeout          | ✅      | ✅  | ✅  |\n| apiKey                   | ✅      | ✅  | ✅  |\n| authParam                | ⬜️      | ⬜️ | ✅  |\n| authEndpoint             | ✅      | ✅  | ✅  |\n| authTransport            | ⬜️      | ⬜️ | ✅  |\n| cluster                  | ✅      | ✅  | ✅  |\n| disabledTransports       | ⬜️     | ⬜️ | ✅  |\n| enabledTransports        | ⬜️     | ⬜️ | ✅  |\n| enableStats              | ⬜️     | ⬜️ | ✅  |\n| ignoreNullOrigin         | ⬜️     | ⬜️ | ✅  |\n| logToConsole             | ⬜️     | ⬜️ | ✅  |\n| maxReconnectGapInSeconds | ✅      | ✅  | ⬜️ |\n| maxReconnectionAttempts  | ✅      | ✅  | ⬜️ |\n| pongTimeout              | ✅      | ✅  | ✅  |\n| proxy                    | ✅      | ⬜️ | ⬜️ |\n| useTLS                   | ✅      | ✅  | ⬜️ |\n\n#### `activityTimeout (double)`\n\nAfter this time (in seconds) without any messages received from the server, a ping message will be sent to check if the connection is still working; the default value is supplied by the server, low values will result in unnecessary traffic.\n\n#### `apiKey (String)`\n\nYou can get your `API_KEY` and `API_CLUSTER` from the [Pusher Channels dashboard](https://dashboard.pusher.com/).\n\n#### `authParams (Map)`\n\nAllows passing additional data to authorizers. Supports query string params and headers (AJAX only). For example, following will pass `foo=bar` via the query string and `baz: boo` via headers:\n\n```dart\nfinal pusher = PusherChannelsFlutter.getInstance()\nawait pusher.init(\n  apiKey: API_KEY,\n  cluster: API_CLUSTER,\n  authParams: {\n    'params': { 'foo': 'bar' },\n    'headers': { 'baz': 'boo' }\n  }\n});\n```\n\nAdditional parameters to be sent when the channel authentication endpoint is called. When using [ajax authentication](https://pusher.com/docs/authenticating_users#ajax_authentication) the parameters are passed as additional `POST` parameters. When using [jsonp authentication](http://pusher.com/docs/authenticating_users#jsonp_authentication) the parameters are passed as `GET` parameters. This can be useful with web application frameworks that guard against [CSRF (Cross-site request forgery)](http://en.wikipedia.org/wiki/Cross-site_request_forgery).\n\nCSRF\n\nIf you require a CSRF header for incoming requests to the private channel authentication endpoint on your server, you should add a CSRF token to the `auth` hash under `headers`. This is applicable to frameworks which apply CSRF protection by default.\n\n```dart\nfinal pusher = await pusher.init(\n  apiKey: API_KEY,\n  cluster: API_CLUSTER,\n  authParams: {\n    'params': { 'foo': 'bar' },\n    'headers': { 'X-CSRF-Token': 'SOME_CSRF_TOKEN' }\n  }\n);\n```\n\n#### `authEndpoint (String)`\n\nThe authEndpoint provides a URL that the\nPusher client will call to authorize users\nfor a presence channel. On how to implement\nan authorization service please check here:\n\nhttps://pusher.com/docs/channels/server_api/authenticating-users/\n\n#### `cluster (String)`\n\nSpecifies the cluster that pusher-js should connect to. [If you'd like to see a full list of our clusters, click here](https://pusher.com/docs/clusters). If you do not specify a cluster, `mt1` will be used by default.\n\n#### `useTLS (bool)`\n\nWhether or not you'd like to use TLS encrypted transport or not, default is `true`\n\n## Event Callback parameters\n\nThe following functions are callbacks that can be passed to the `init()` method. All are optional.\n\n#### `onEvent`\n\n```dart\nvoid onEvent(PusherEvent event) {\n  print(\"onEvent: $event\");\n}\n```\n\nCalled when a event is received by the client.\nThe global event handler will trigger on events from any channel.\n\n#### `onSubscriptionSucceeded`\n\n```dart\nvoid onSubscriptionSucceeded(String channelName, dynamic data) {\n  print(\"onSubscriptionSucceeded: $channelName data: $data\");\n}\n```\n\nuse this if you want to be informed of when a channel has successfully been subscribed to, which is useful if you want to perform actions that are only relevant after a subscription has succeeded. For example querying the members for presence channel.\n\n#### `onSubscriptionError`\n\n```dart\nvoid onSubscriptionError(String message, dynamic e) {\n  print(\"onSubscriptionError: $message Exception: $e\");\n}\n```\n\nuse this if you want to be informed of a failed subscription attempt, which you could use, for example, to then attempt another subscription or make a call to a service you use to track errors.\n\n#### `onDecryptionFailure`\n\n```dart\nvoid onDecryptionFailure(String event, String reason) {\n  print(\"onDecryptionFailure: $event reason: $reason\");\n}\n```\n\nonly used with private encrypted channels - use this if you want to be notified if any messages fail to decrypt.\n\n#### `onMemberAdded`\n\n```dart\nvoid onMemberAdded(String channelName, PusherMember member) {\n  print(\"onMemberAdded: $channelName member: $member\");\n}\n```\n\nCalled when a member is added to the presence channel.\n\n#### `onMemberRemoved`\n\n```dart\nvoid onMemberRemoved(String channelName, PusherMember member) {\n  print(\"onMemberRemoved: $channelName member: $member\");\n}\n```\n\nCalled when a member is removed to the presence channel.\n\n#### `onAuthorizer`\n\nWhen passing the `onAuthorizer()` callback to the `init()` method, this callback is called to request auth information. For more information on how\nto generate the correct information, please look here:\nhttps://pusher.com/docs/channels/library_auth_reference/auth-signatures/\n\n```dart\ndynamic onAuthorizer(String channelName, String socketId, dynamic options) async {\n  return {\n    \"auth\": \"foo:bar\",\n    \"channel_data\": '{\"user_id\": 1}',\n    \"shared_secret\": \"foobar\"\n  };\n}\n```\n\n#### `onConnectionStateChange`\n\n```dart\nvoid onConnectionStateChange(dynamic currentState, dynamic previousState) {\n  print(\"Connection: $currentState\");\n}\n```\n\nuse this if you want to use connection state changes to perform different actions / UI updates\nThe different states that the connection can be in are:\n\n- `CONNECTING` - the connection is about to attempt to be made\n- `CONNECTED` - the connection has been successfully made\n- `DISCONNECTING` - the connection has been instructed to disconnect and it is just about to do so\n- `DISCONNECTED` - the connection has disconnected and no attempt will be made to reconnect automatically\n- `RECONNECTING` - an attempt is going to be made to try and re-establish the connection\n\n#### `onError`\n\n```dart\nvoid onError(String message, int? code, dynamic e) {\n  print(\"onError: $message code: $code exception: $e\");\n}\n```\n\nuse this if you want to be informed of errors received from Pusher Channels e.g. `Application is over connection quota`. You can find some of the possible errors listed [here](https://pusher.com/docs/channels/library_auth_reference/pusher-websockets-protocol#error-codes).\n\n## Connection handling\n\n### Connecting\n\nTo connect to the Pusher network, just call the `connect()` method.\n\n```dart\nawait pusher.connect();\n```\n\n### Disconnecting\n\nTo disconnect to the Pusher network, just call the `disconnect()` method.\n\n```dart\nawait pusher.disconnect();\n```\n\n### Reconnection\n\nThere are three main ways in which a disconnection can occur:\n\n- The client explicitly calls disconnect and a close frame is sent over the websocket connection\n- The client experiences some form of network degradation which leads to a heartbeat (ping/pong) message being missed and thus the client disconnects\n- The Pusher server closes the websocket connection; typically this will only occur during a restart of the Pusher socket servers and an almost immediate reconnection should occur\n\nIn the case of the first type of disconnection the library will (as you'd hope) not attempt a reconnection.\n\n## Subscribing\n\n### Public channels\n\nThe default method for subscribing to a channel involves invoking the `subscribe` method of your client object:\n\n```dart\nfinal myChannel = await pusher.subscribe(channelName: \"my-channel\");\n```\n\n### Private channels\n\nPrivate channels are created in exactly the same way as public channels, except that they reside in the 'private-' namespace. This means prefixing the channel name:\n\n```dart\nfinal myPrivateChannel = await pusher.subscribe(channelName: \"private-my-channel\")\n```\n\nSubscribing to private channels involves the client being authenticated. See the [Configuration](#configuration) section for the authenticated channel example for more information.\n\n### Private encrypted channels\n\nSimilar to Private channels, you can also subscribe to a [private encrypted channel](https://pusher.com/docs/channels/using_channels/encrypted-channels). This library now fully supports end-to-end encryption. This means that only you and your connected clients will be able to read your messages. Pusher cannot decrypt them.\n\nLike with private channels, you must provide an authentication endpoint. That endpoint must be using a [server client that supports end-to-end encryption](https://pusher.com/docs/channels/using_channels/encrypted-channels#server). There is a [demonstration endpoint to look at using nodejs](https://github.com/pusher/pusher-channels-auth-example#using-e2e-encryption).\n\nThe shared secret used to decrypt events is loaded from the same auth endpoint request that is used to authorize your subscription. There is also a mechanism for reloading the shared secret if your encryption master key changes. If an event is encountered that cannot be decrypted, a request is made to your auth endpoint to attempt to load the new shared secret. If that request fails or if the returned secret still cannot decrypt the event then that event will be skipped, the `onDecryptionFailure` callback function will be called, and the next received event will be processed.\n\n#### Limitations\n\n- Client events are not supported on encrypted channels\n\n```dart\nfinal privateEncryptedChannel = await pusher.subscribe(channelName: \"private-encrypted-my-channel\")\n```\n\nThere is also an optional callback in the connection delegate when you can listen for\nany failed decryption events:\n\n```dart\noptional func void onDecryptionFailure(String event, String reason)\n```\n\n### Presence channels\n\nPresence channels are channels whose names are prefixed by `presence-`.\n\nThe resulting channel object has a member: `members` that contains the active members of the channel.\n\n```dart\nfinal myPresenceChannel = await pusher.subscribe(channelName: \"presence-my-channel\")\n```\n\nYou can also provide functions that will be called when members are either added to or removed from the channel. These are available as parameters to `init()` globally, or to `subscribe()` per channel.\n\n```dart\nvoid onMemberAdded(String channelName, PusherMember member) {\n  print(\"onMemberAdded: $channelName user: $member\");\n}\n```\n\n```dart\nvoid onMemberRemoved(String channelName, PusherMember member) {\n  print(\"onMemberRemoved: $channelName user: $member\");\n}\n```\n\n**Note**: The `members` property of `PusherChannel` objects will only be set once subscription to the channel has succeeded.\n\nThe easiest way to find out when a channel has been successfully subscribed to is to bind to the callback named `onSubscriptionSucceeded` on the channel you're interested in. It would look something like this:\n\n```dart\nfinal pusher = PusherChannelsFlutter.getInstance();\nfinal channels = {};\nawait pusher.init(\n  apiKey: API_KEY,\n  cluster: API_CLUSTER,\n  authEndPoint: \"https://your-server.com/pusher/auth\"\n);\nfinal myChannel = await pusher.subscribe(\n  channelName:'presence-my-channel',\n  onSubscriptionSucceeded: (channelName, data) {\n    print(\"Subscribed to $channelName\");\n    print(\"I can now access me: ${myChannel.me}\")\n    print(\"And here are the channel members: ${myChannel.members}\")\n  },\n  onMemberAdded: (member) {\n    print(\"Member added: $member\");\n  },\n  onMemberRemoved: (member) {\n    print(\"Member removed: $member\");\n  },\n  onEvent: (event) {\n    print(\"Event received: $event\");\n  },\n);\n```\n\nNote that both private and presence channels require the user to be authenticated in order to subscribe to the channel. This authentication can either happen inside the library, if you configured your Pusher object with your app's secret, or an authentication request is made to an authentication endpoint that you provide, again when initializing your Pusher object.\n\nWe recommend that you use an authentication endpoint over including your app's secret in your app in the vast majority of use cases. If you are completely certain that there's no risk to you including your app's secret in your app, for example if your app is just for internal use at your company, then it can make things easier than setting up an authentication endpoint.\n\n### Unsubscribing\n\nTo unsubscribe from a channel, call the `unsubscribe()` method:\n\n```dart\nawait pusher.unsubscribe(\"my-channel\");\n```\n\n## Binding to events\n\nEvents can be bound to at 2 levels; globally and per channel. There is an example of this below.\n\n### Per-channel events\n\nThese are bound to a specific channel, and mean that you can reuse event names in different parts of your client application.\n\n```dart\nfinal pusher = PusherChannelsFlutter.getInstance();\nawait pusher.init(\n  apiKey: API_KEY,\n  cluster: API_CLUSTER\n);\nfinal myChannel = await pusher.subscribe(\n  channelName: \"my-channel\",\n  onEvent: (event) {\n    print(\"Got channel event: $event\");\n  }\n);\nawait pusher.connect();\n```\n\n### Global events\n\nYou can attach behavior to these events regardless of the channel the event is broadcast to.\n\n```dart\nfinal pusher = PusherChannelsFlutter.getInstance();\nawait pusher.init(\n  apiKey: API_KEY,\n  cluster: API_CLUSTER,\n  onEvent: (event) {\n    print(\"Got event: $event\");\n  }\n);\nfinal myChannel = await pusher.subscribe(\n  channelName: \"my-channel\"\n);\n```\n\n### PusherEvent\n\nThe callbacks you bind receive a `PusherEvent`:\n\n```dart\nclass PusherEvent {\n  String channelName; // Name of the channel.\n  String eventName; // Name of the event.\n  dynamic data; // Data, usually JSON string. See [parsing event data](#parsing-event-data).\n  String? userId; // UserId of the sending event, only for client events on presence channels.\n}\n```\n\n#### Parsing event data\n\nThe `data` property of [`PusherEvent`](#pusherevent) contains the string representation of the data that you passed when you triggered the event. If you passed an object then that object will have been serialized to JSON. You can parse that JSON as appropriate.\n\n### Receiving errors\n\nErrors received from Pusher Channels can be accessed via the `onError` callback.\n\n```dart\nvoid onError(String message, int? code, dynamic e) {\n  print(\"onError: $message code: $code exception: $e\");\n}\n```\n\n## Triggering events\n\nOnce a [private](https://pusher.com/docs/channels/using_channels/private-channels) or [presence](https://pusher.com/docs/channels/using_channels/presence-channels) subscription has been authorized (see [authenticating users](https://pusher.com/docs/channels/server_api/authenticating-users)) and the subscription has succeeded, it is possible to trigger events on those channels. You can do this per channel, or\non the global `PusherChannelsFlutter` instance.\n\n```dart\nawait myChannel.trigger(eventName: \"client-my-event\", data: [\"myName\": \"Bob\"]);\n```\n\nOr on the global pusher instance:\n\n```dart\nawait pusher.trigger(channelName: \"my-channel\", eventName: \"client-my-event\", data: [\"myName\": \"Bob\"]);\n```\n\nEvents triggered by clients are called [client events](https://pusher.com/docs/channels/using_channels/events#triggering-client-events). Because they are being triggered from a client which may not be trusted there are a number of enforced rules when using them. Some of these rules include:\n\n- Event names must have a `client-` prefix\n- Rate limits\n- You can only trigger an event when the subscription has succeeded\n\nFor full details see the [client events documentation](https://pusher.com/docs/channels/using_channels/events#triggering-client-events).\n\n## Get a channel by name\n\nTo get the `PusherChannel` instance from the `Pusher` instance you can use the `getChannel(\u003cchannelName\u003e)` method:\n\n```dart\nfinal channel = pusher.getChannel(\"presence-channel\");\n```\n\n## Socket information\n\nTo get information from the current socket call the `getSocketId()` method:\n\n```dart\nfinal socketId = await pusher.getSocketId();\n```\n\n## Communication\n\n- If you have found a bug, please open an issue.\n- If you have a feature request, please open an issue.\n- If you want to contribute, please submit a pull request.\n- If you do not receive a timely response, feel free to check our [support portal](https://docs.bird.com/pusher).\n\n## Credits\n\nPusherChannelsFlutter is owned and maintained by [Pusher](https://pusher.com).\n\n## License\n\nPusherChannelsFlutter is released under the MIT license. See [LICENSE](https://github.com/pusher/pusher-channels-flutter/blob/master/LICENSE) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpusher%2Fpusher-channels-flutter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpusher%2Fpusher-channels-flutter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpusher%2Fpusher-channels-flutter/lists"}