Pigeon: Integrated sendMessage API in Dart
This commit is contained in:
parent
503d4a7735
commit
82c16ccd8c
4 changed files with 14 additions and 8 deletions
|
|
@ -14,5 +14,4 @@ class PlatformMethodNames {
|
|||
|
||||
static const getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces";
|
||||
static const onMessageReceived = "CastSession.onMessageReceived";
|
||||
static const sendMessage = "CastSession.sendMessage";
|
||||
}
|
||||
|
|
@ -1,13 +1,15 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../HostApis.dart';
|
||||
import '../MethodNames.dart';
|
||||
import 'SessionManager.dart';
|
||||
|
||||
class CastContext {
|
||||
final ValueNotifier<CastState> state = ValueNotifier(CastState.unavailable);
|
||||
final MethodChannel _channel;
|
||||
final CastApi castApi;
|
||||
|
||||
CastContext(this._channel);
|
||||
CastContext(this._channel, this.castApi);
|
||||
|
||||
void showCastChooserDialog() {
|
||||
_channel.invokeMethod(PlatformMethodNames.showCastDialog);
|
||||
|
|
@ -22,7 +24,7 @@ class CastContext {
|
|||
SessionManager get sessionManager {
|
||||
var result = _sessionManager;
|
||||
if (result == null) {
|
||||
_sessionManager = result = SessionManager(_channel);
|
||||
_sessionManager = result = SessionManager(castApi);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import '../HostApis.dart';
|
||||
import '../MethodNames.dart';
|
||||
|
||||
class SessionManager {
|
||||
final MethodChannel _channel;
|
||||
final CastApi castApi;
|
||||
|
||||
SessionManager(this._channel);
|
||||
SessionManager(this.castApi);
|
||||
|
||||
final ValueNotifier<SessionState> state = ValueNotifier(SessionState.idle);
|
||||
|
||||
|
|
@ -54,8 +55,10 @@ class SessionManager {
|
|||
}
|
||||
|
||||
void sendMessage(String namespace, String message) {
|
||||
final argsMap = {'namespace': namespace, 'message': message};
|
||||
_channel.invokeMethod(PlatformMethodNames.sendMessage, argsMap);
|
||||
final castMessage = CastMessage();
|
||||
castMessage.namespace = namespace;
|
||||
castMessage.message = message;
|
||||
castApi.sendMessage(castMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'HostApis.dart';
|
||||
import 'MethodNames.dart';
|
||||
import 'cast/CastContext.dart';
|
||||
|
||||
class FlutterCastFramework {
|
||||
static const MethodChannel _channel =
|
||||
const MethodChannel('flutter_cast_framework');
|
||||
static final castApi = CastApi();
|
||||
|
||||
/// List of namespaces to listen for custom messages
|
||||
static List<String> namespaces = [];
|
||||
|
|
@ -58,7 +60,7 @@ class FlutterCastFramework {
|
|||
static CastContext get castContext {
|
||||
var castContext = _castContext;
|
||||
if (!_isInitiated || castContext == null) {
|
||||
_castContext = castContext = CastContext(_channel);
|
||||
_castContext = castContext = CastContext(_channel, castApi);
|
||||
// TODO: find a better way to init the plugin
|
||||
_isInitiated = true;
|
||||
_init();
|
||||
|
|
|
|||
Loading…
Reference in a new issue