97 lines
3.0 KiB
C++
97 lines
3.0 KiB
C++
// Copyright 2024 LiveKit, Inc.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include "include/livekit_client/live_kit_plugin.h"
|
|
|
|
// This must be included before many other Windows headers.
|
|
#include <windows.h>
|
|
|
|
// For getPlatformVersion; remove unless needed for your plugin implementation.
|
|
#include <VersionHelpers.h>
|
|
|
|
#include <flutter/method_channel.h>
|
|
#include <flutter/plugin_registrar_windows.h>
|
|
#include <flutter/standard_method_codec.h>
|
|
|
|
#include <map>
|
|
#include <memory>
|
|
#include <sstream>
|
|
|
|
namespace {
|
|
|
|
class LiveKitPlugin : public flutter::Plugin {
|
|
public:
|
|
static void RegisterWithRegistrar(flutter::PluginRegistrarWindows *registrar);
|
|
|
|
LiveKitPlugin();
|
|
|
|
virtual ~LiveKitPlugin();
|
|
|
|
private:
|
|
// Called when a method is called on this plugin's channel from Dart.
|
|
void HandleMethodCall(
|
|
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result);
|
|
};
|
|
|
|
// static
|
|
void LiveKitPlugin::RegisterWithRegistrar(
|
|
flutter::PluginRegistrarWindows *registrar) {
|
|
auto channel =
|
|
std::make_unique<flutter::MethodChannel<flutter::EncodableValue>>(
|
|
registrar->messenger(), "livekit_client",
|
|
&flutter::StandardMethodCodec::GetInstance());
|
|
|
|
auto plugin = std::make_unique<LiveKitPlugin>();
|
|
|
|
channel->SetMethodCallHandler(
|
|
[plugin_pointer = plugin.get()](const auto &call, auto result) {
|
|
plugin_pointer->HandleMethodCall(call, std::move(result));
|
|
});
|
|
|
|
registrar->AddPlugin(std::move(plugin));
|
|
}
|
|
|
|
LiveKitPlugin::LiveKitPlugin() {}
|
|
|
|
LiveKitPlugin::~LiveKitPlugin() {}
|
|
|
|
void LiveKitPlugin::HandleMethodCall(
|
|
const flutter::MethodCall<flutter::EncodableValue> &method_call,
|
|
std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>> result) {
|
|
if (method_call.method_name().compare("getPlatformVersion") == 0) {
|
|
std::ostringstream version_stream;
|
|
version_stream << "Windows ";
|
|
if (IsWindows10OrGreater()) {
|
|
version_stream << "10+";
|
|
} else if (IsWindows8OrGreater()) {
|
|
version_stream << "8";
|
|
} else if (IsWindows7OrGreater()) {
|
|
version_stream << "7";
|
|
}
|
|
result->Success(flutter::EncodableValue(version_stream.str()));
|
|
} else {
|
|
result->NotImplemented();
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void LiveKitPluginRegisterWithRegistrar(
|
|
FlutterDesktopPluginRegistrarRef registrar) {
|
|
LiveKitPlugin::RegisterWithRegistrar(
|
|
flutter::PluginRegistrarManager::GetInstance()
|
|
->GetRegistrar<flutter::PluginRegistrarWindows>(registrar));
|
|
}
|