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