Skip to content

Commit

Permalink
Fixes #1: Handle json encoding properly on android
Browse files Browse the repository at this point in the history
  • Loading branch information
chinloyal committed Nov 17, 2020
1 parent e378881 commit b221159
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 17 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.0.2 - November 17, 2020
* BUGFIX: Fixes issue #1, Double backslashes in the bind event breaks the JSON encoding. (This issue was only on android, iOS worked fine.)

## 1.0.1 - November 7, 2020

* BUGFIX: Fixed not being able to bind to multiple types of channels at once.
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Add to your pubspec.yaml

```yaml
dependencies:
pusher_client: ^1.0.1
pusher_client: ^1.0.2
```
## Configuration
Expand Down Expand Up @@ -113,7 +113,7 @@ Then in `android/app/proguard-rules.pro`:

## API Overview

Here's the API in nutshell.
Here's the API in a nutshell.

```dart
PusherOptions options = PusherOptions(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class PusherService : MChannel {
}

private fun init(call: MethodCall, result: Result) {
// toString works because this is json encoded in dart
val args = JSONObject(call.arguments.toString())
val initArgs: JSONObject = args.getJSONObject("initArgs")
enableLogging = initArgs.getBoolean("enableLogging")
Expand Down Expand Up @@ -135,7 +136,8 @@ class PusherService : MChannel {

private fun subscribe(call: MethodCall, result: Result) {
try {
val args = JSONObject(call.arguments.toString())
val src = call.arguments as Map<String, Any>
val args = JSONObject(src)
val channelName: String = args.getString("channelName")

when {
Expand Down Expand Up @@ -171,7 +173,8 @@ class PusherService : MChannel {

private fun unsubscribe(call: MethodCall, result: Result) {
try {
val args = JSONObject(call.arguments.toString());
val src = call.arguments as Map<String, Any>
val args = JSONObject(src);
val channelName = args.getString("channelName")

_pusherInstance?.unsubscribe(channelName)
Expand All @@ -190,7 +193,8 @@ class PusherService : MChannel {
*/
private fun bind(call: MethodCall, result: Result) {
try {
val args = JSONObject(call.arguments.toString())
val src = call.arguments as Map<String, Any>
val args = JSONObject(src)
val channelName: String = args.getString("channelName")
val eventName: String = args.getString("eventName")

Expand Down Expand Up @@ -224,7 +228,8 @@ class PusherService : MChannel {

private fun unbind(call: MethodCall, result: Result) {
try {
val args = JSONObject(call.arguments.toString())
val src = call.arguments as Map<String, Any>
val args = JSONObject(src)
val channelName: String = args.getString("channelName")
val eventName: String = args.getString("eventName")

Expand Down Expand Up @@ -258,11 +263,12 @@ class PusherService : MChannel {

private fun trigger(call: MethodCall, result: Result) {
try {
// toString works because this is json encoded in dart
val args = JSONObject(call.arguments.toString())
val eventName: String = args.getString("eventName")
val data: String = args.getString("data")
val channelName: String = args.getString("channelName")
val errorMessage = "Trigger can only be called on private and presence channels.";
val errorMessage = "Trigger can only be called on private and presence channels."
when {
channelName.startsWith(PRIVATE_ENCRYPTED_PREFIX) -> {
result.error("TRIGGER_ERROR", errorMessage, null)
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.0.1"
version: "1.0.2"
quiver:
dependency: transitive
description:
Expand Down
15 changes: 7 additions & 8 deletions lib/src/pusher/pusher_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@ class PusherClient {
bool autoConnect = true,
});

/// Creates a [PusherClient] -- returns the instance if it's already be called.
factory PusherClient(
String appKey,
PusherOptions options, {
bool enableLogging = true,
bool autoConnect = true,
}) {
if (_singleton == null) {
_singleton = PusherClient._(
appKey,
options,
enableLogging: enableLogging,
autoConnect: autoConnect,
);
}
_singleton ??= PusherClient._(
appKey,
options,
enableLogging: enableLogging,
autoConnect: autoConnect,
);

final initArgs = _InitArgs(enableLogging: enableLogging);

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: pusher_client
description: |
A Pusher Channels client plugin for Flutter targeting Android and iOS. It
wraps pusher-websocket-java v2.2.5 and pusher-websocket-swift v8.0.0.
version: 1.0.1
version: 1.0.2
homepage: https://github.com/chinloyal/pusher_client
documentation: https://github.com/chinloyal/pusher_client/blob/master/README.md

Expand Down

0 comments on commit b221159

Please sign in to comment.