Pigeon: Integrated sendMessage API in Swift
This commit is contained in:
parent
258cf8d607
commit
1b689bc8d6
5 changed files with 27 additions and 14 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#import <Flutter/Flutter.h>
|
#import <Flutter/Flutter.h>
|
||||||
|
#import "HostApis.h"
|
||||||
|
|
||||||
@interface FlutterCastFrameworkPlugin : NSObject<FlutterPlugin>
|
@interface FlutterCastFrameworkPlugin : NSObject<FlutterPlugin>
|
||||||
@end
|
@end
|
||||||
|
|
|
||||||
|
|
@ -29,15 +29,9 @@ class MessageCastingChannel : GCKCastChannel {
|
||||||
channel.invokeMethod(MethodNames.onMessageReceived.rawValue, arguments: argsMap)
|
channel.invokeMethod(MethodNames.onMessageReceived.rawValue, arguments: argsMap)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func sendMessage(allCastingChannels: Dictionary<String, MessageCastingChannel>, arguments: Any?) {
|
public static func sendMessage(allCastingChannels: Dictionary<String, MessageCastingChannel>, castMessage: CastMessage) {
|
||||||
let argsMap = arguments as? NSDictionary
|
let namespaceRaw = castMessage.namespace
|
||||||
if (argsMap == nil) {
|
let messageRaw = castMessage.message
|
||||||
print("Arguments not valid: can't send message")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let namespaceRaw = argsMap?.value(forKey: "namespace") as? String
|
|
||||||
let messageRaw = argsMap?.value(forKey: "message") as? String
|
|
||||||
|
|
||||||
if (namespaceRaw == nil) {
|
if (namespaceRaw == nil) {
|
||||||
print("Namespace not valid: can't send message")
|
print("Namespace not valid: can't send message")
|
||||||
|
|
|
||||||
|
|
@ -25,5 +25,4 @@ enum MethodNames : String {
|
||||||
|
|
||||||
case getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces"
|
case getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces"
|
||||||
case onMessageReceived = "CastSession.onMessageReceived"
|
case onMessageReceived = "CastSession.onMessageReceived"
|
||||||
case sendMessage = "CastSession.sendMessage"
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,15 @@ import Flutter
|
||||||
import UIKit
|
import UIKit
|
||||||
import GoogleCast
|
import GoogleCast
|
||||||
|
|
||||||
public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessionManagerListener {
|
public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessionManagerListener, CastApi {
|
||||||
public static func register(with registrar: FlutterPluginRegistrar) {
|
public static func register(with registrar: FlutterPluginRegistrar) {
|
||||||
let channel = FlutterMethodChannel(name: "flutter_cast_framework", binaryMessenger: registrar.messenger())
|
let messenger : FlutterBinaryMessenger = registrar.messenger()
|
||||||
|
let channel = FlutterMethodChannel(name: "flutter_cast_framework", binaryMessenger: messenger)
|
||||||
let instance = SwiftFlutterCastFrameworkPlugin(channel: channel)
|
let instance = SwiftFlutterCastFrameworkPlugin(channel: channel)
|
||||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||||
|
|
||||||
|
let api : CastApi & NSObjectProtocol = instance
|
||||||
|
CastApiSetup(messenger, api)
|
||||||
}
|
}
|
||||||
|
|
||||||
private let castContext: GCKCastContext
|
private let castContext: GCKCastContext
|
||||||
|
|
@ -110,8 +114,6 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
|
||||||
switch call.method {
|
switch call.method {
|
||||||
case MethodNames.showCastDialog.rawValue:
|
case MethodNames.showCastDialog.rawValue:
|
||||||
castContext.presentCastDialog()
|
castContext.presentCastDialog()
|
||||||
case MethodNames.sendMessage.rawValue:
|
|
||||||
MessageCastingChannel.sendMessage(allCastingChannels: self.castingChannels, arguments: call.arguments)
|
|
||||||
default:
|
default:
|
||||||
print("Method [\(call.method)] is not implemented.")
|
print("Method [\(call.method)] is not implemented.")
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +124,11 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
|
||||||
castStateObserver = nil
|
castStateObserver = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func sendMessageMessage(_ message: CastMessage, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||||
|
|
||||||
|
MessageCastingChannel.sendMessage(allCastingChannels: self.castingChannels, castMessage: message)
|
||||||
|
}
|
||||||
|
|
||||||
// MARK: - GCKSessionManagerListener
|
// MARK: - GCKSessionManagerListener
|
||||||
|
|
||||||
// onSessionSuspended
|
// onSessionSuspended
|
||||||
|
|
|
||||||
12
ios/Classes/flutter_cast_framework.h
Normal file
12
ios/Classes/flutter_cast_framework.h
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
//
|
||||||
|
// flutter_cast_framework.h
|
||||||
|
// flutter_cast_framework
|
||||||
|
//
|
||||||
|
// Created by Gianluca Paradiso on 01/11/21.
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifndef flutter_cast_framework_h
|
||||||
|
#define flutter_cast_framework_h
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* flutter_cast_framework_h */
|
||||||
Loading…
Reference in a new issue