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 "HostApis.h"
|
||||
|
||||
@interface FlutterCastFrameworkPlugin : NSObject<FlutterPlugin>
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -29,15 +29,9 @@ class MessageCastingChannel : GCKCastChannel {
|
|||
channel.invokeMethod(MethodNames.onMessageReceived.rawValue, arguments: argsMap)
|
||||
}
|
||||
|
||||
public static func sendMessage(allCastingChannels: Dictionary<String, MessageCastingChannel>, arguments: Any?) {
|
||||
let argsMap = arguments as? NSDictionary
|
||||
if (argsMap == nil) {
|
||||
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
|
||||
public static func sendMessage(allCastingChannels: Dictionary<String, MessageCastingChannel>, castMessage: CastMessage) {
|
||||
let namespaceRaw = castMessage.namespace
|
||||
let messageRaw = castMessage.message
|
||||
|
||||
if (namespaceRaw == nil) {
|
||||
print("Namespace not valid: can't send message")
|
||||
|
|
|
|||
|
|
@ -25,5 +25,4 @@ enum MethodNames : String {
|
|||
|
||||
case getSessionMessageNamespaces = "CastSession.getSessionMessageNamespaces"
|
||||
case onMessageReceived = "CastSession.onMessageReceived"
|
||||
case sendMessage = "CastSession.sendMessage"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,11 +2,15 @@ import Flutter
|
|||
import UIKit
|
||||
import GoogleCast
|
||||
|
||||
public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessionManagerListener {
|
||||
public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessionManagerListener, CastApi {
|
||||
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)
|
||||
registrar.addMethodCallDelegate(instance, channel: channel)
|
||||
|
||||
let api : CastApi & NSObjectProtocol = instance
|
||||
CastApiSetup(messenger, api)
|
||||
}
|
||||
|
||||
private let castContext: GCKCastContext
|
||||
|
|
@ -110,8 +114,6 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
|
|||
switch call.method {
|
||||
case MethodNames.showCastDialog.rawValue:
|
||||
castContext.presentCastDialog()
|
||||
case MethodNames.sendMessage.rawValue:
|
||||
MessageCastingChannel.sendMessage(allCastingChannels: self.castingChannels, arguments: call.arguments)
|
||||
default:
|
||||
print("Method [\(call.method)] is not implemented.")
|
||||
}
|
||||
|
|
@ -122,6 +124,11 @@ public class SwiftFlutterCastFrameworkPlugin: NSObject, FlutterPlugin, GCKSessio
|
|||
castStateObserver = nil
|
||||
}
|
||||
|
||||
public func sendMessageMessage(_ message: CastMessage, error: AutoreleasingUnsafeMutablePointer<FlutterError?>) {
|
||||
|
||||
MessageCastingChannel.sendMessage(allCastingChannels: self.castingChannels, castMessage: message)
|
||||
}
|
||||
|
||||
// MARK: - GCKSessionManagerListener
|
||||
|
||||
// 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