-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #7 Binding to channel events cancels calls to onConnectionState…
…Change Added Stream Handler to allow multiple classes to listen to event channel stream
- Loading branch information
Showing
4 changed files
with
42 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,3 +39,4 @@ app.*.symbols | |
|
||
# Obfuscation related | ||
app.*.map.json | ||
testdata.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
|
||
abstract class StreamHandler { | ||
static const EventChannel _eventStream = | ||
const EventChannel('com.github.chinloyal/pusher_client_stream'); | ||
StreamSubscription _eventStreamSubscription; | ||
|
||
static Map<String, dynamic Function(dynamic)> _listeners = {}; | ||
|
||
/// Add a listener to the event channel stream for pusher, | ||
/// any class that extends [StreamHandler] should use this method. | ||
void registerListener(String classId, dynamic Function(dynamic) method) { | ||
StreamHandler._listeners[classId] = method; | ||
|
||
_eventStreamSubscription = | ||
_eventStream.receiveBroadcastStream().listen(_eventHandler); | ||
} | ||
|
||
/// This method will close the entire event channel stream | ||
/// which is why it should only be used by [PusherClient] | ||
void cancelEventChannelStream() { | ||
_eventStreamSubscription.cancel(); | ||
} | ||
|
||
void _eventHandler(event) { | ||
_listeners.values.forEach((method) { | ||
method(event); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters