搜尋套件、儲存庫與 APP 分類

套件詳情v1.1.0

deeplink_rpc

一個以 Dart 編寫的透過深層連結進行 RPC 通訊的程式庫。專為 Flutter 移動應用程式(iOS / Android)設計。

AndroidiOSmacOSWindowsLinux
近 30 天下載
142
喜歡數
4
Pub 分數
130

安裝套件

flutter pub add deeplink_rpc

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個基於 Dart 的程式庫,透過深度連結在 Flutter 應用程式中實現 RPC(遠端程序呼叫)通訊,適用於 iOS 與 Android。它利用深度連結 URL 在應用程式之間或單一應用程式元件內呼叫方法與交換資料,實現安全、跨平台的跨應用通訊。此程式庫專為無縫整合行動環境而設計,支援結構化訊息傳遞,非常適合需要應用程式間互動但不依賴傳統網路呼叫的場景。該程式庫為開源,由 Archethic Foundation 維護。

適用情境

  • 應用間通訊
  • Flutter 應用中的模組間訊息傳遞
  • 安全的遠端方法呼叫
  • 透過深度連結處理外部動作
  • 簡化導航與資料傳輸

主要特色

  • 基於深度連結的 RPC
  • 跨平台支援(iOS/Android)
  • 安全的消息序列化
  • 與 Flutter 的輕鬆整合
  • 開源且積極維護

適合對象

  • 使用 Flutter 的移動應用開發者
  • 需要應用間通訊的應用
  • 開發人員實現安全的深度連結工作流程
  • 需要輕量級 RPC 替代方案的專案
  • 構建模組化或微前端架構的團隊

使用建議

  • 目標平台需要正確的深度連結設定
  • 僅限行動和桌面平台(無網頁)
  • 依賴於正確的URL方案設定
  • 可能需要為敏感資料採取額外的安全措施
  • 不適用於高頻率或低延遲通訊

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

Deeplink RPC

A RPC-via-deeplink communication library coded in Dart. This is dedicated to Flutter mobile applications (iOS / Android).

Protocol

Deeplink codec

Deeplink messages are appended to the deeplink URI. Because of that, there are limitations in the available formatting.

To get it working, the message is encoded that way :

                     +--------------+   +------+   +-----------+
method_payload :     | Json Message |-> | gzip |-> | base64Url |
                     +--------------+   +------+   +-----------+


Deeplink Url : `<scheme>://<host>/<method_name>/<method_payload>`

Example :

                     +--------------------------+      +----------------------------------------------------------------+
method_payload :     | { "param1" : "a_value" } |----> | "H4sIAAAAAAAAA6tWUCpILErMNVRSsFJQSowvS8wpTVVSqAUAhIgKchgAAAA=" |
                     +--------------------------+      +----------------------------------------------------------------+


Deeplink Url : `scheme://host/a_method/H4sIAAAAAAAAA6tWUCpILErMNVRSsFJQSowvS8wpTVVSqAUAhIgKchgAAAA=`

Request formatting

Requests payload are encapsulated in a JSON-RPC 2.0 message.

{
  "id": Number,                     // An unique client-generated integer identifying the request
  "replyUrl": String,               // Deeplink URL to which send the invokation result. This should be a Deeplink URL handled by the DApp.
  "params": {
    "origin": {
      "name": String,               // Human readable identifier of the DApp
      "url": String | undefined,    // URL of the DApp
      "logo": Base64 | undefined,   // Logo of the DApp 
    },
    "version": 2,                   // Version of the DApp API
    "payload": Object,              // Method parameters
  }
}
Success Response formatting
{
  "id": Number,                     // The request identifier
  "result":  Object,                // Result payload
}
Failure Response formatting
{
  "id": Number,                     // The request identifier
  "failure": {
    "code": Number,                 // Error code
    "message": String | undefined,  // Error description
    "data": Object | undefined,     // Error data
  },
}

Usage

Server - listening to incoming requests
/// 1. Enable deeplinking for your application (https://docs.flutter.dev/development/ui/navigation/deep-linking)

/// 2. Declare the deeplink-rpc receiver
/// When a RPC call <scheme>://a_rpc_command/<payload> is received, the payload is decoded
/// and transmitted to the `handle` method.
final _deeplinkRpcServer = DeeplinkRpcServer()
    ..registerHandler(
      DeeplinkRpcRequestHandler(
        route: const DeeplinkRpcRoute('a_rpc_command'),
        handle: (request) {
            log('Command received');
        }
      ),
    );


class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeeplinkRPC Demo',
      home: const SendForm(),
      onGenerateRoute: (settings) {
        /// 3. Listen to incoming deeplink requests
        if (_deeplinkRpcServer.handleRoute(settings.name)) return;

        // ... do other route generation stuffs here.
        return null;
      },
    );
  }
}
Client - Sending requests and listening for responses
/// 1. Enable deeplinking for your application (https://docs.flutter.dev/development/ui/navigation/deep-linking)
/// It is necessary to receive responses.

/// 2. Declare the deeplink-rpc client
/// When a RPC call <scheme>://a_rpc_command/<payload> is received, the payload is decoded
/// and transmitted to the `handle` method.
final _deeplinkRpcClient = DeeplinkRpcClient();

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'DeeplinkRPC Demo',
      onGenerateRoute: (settings) {
        /// 3. Listen to incoming deeplink requests
        if (_deeplinkRpcClient.handleRoute(settings.name)) return;

        // ... do other route generation stuffs here.
        return null;
      },
      home: Scaffold(
        floatingActionButton: FloatingActionButton(
          child: const Icon(Icons.send),
          onPressed: () async {
            final response = await _deeplinkRpcClient.send(
              timeout: const Duration(seconds: 5),
              request: DeeplinkRpcRequest(
                requestUrl: 'serverapp://server.app/request_endpoint',
                replyUrl: 'clientapp://client.app/reply_endpoint',
                params: {
                  'param1': 'value1',
                  'param2': 'value2',
                },
              ),
            );

            response.map(
              failure: (failure) {
                log(
                  'RPC request failed',
                  error: failure,
                );
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(
                      content: Text(failure.message ?? "An error occured")),
                );
              },
              success: (result) {
                log(
                  'RPC request succeed : ${json.encode(result)}',
                );
                ScaffoldMessenger.of(context).showSnackBar(
                  SnackBar(content: Text(json.encode(result))),
                );
              },
            );
          },
        ),
        body: const SafeArea(
          child: Padding(
            padding: EdgeInsets.all(8.0),
            child: Center(
              child: Text('Client example'),
            ),
          ),
        ),
      ),
    );
  }
}

所屬分類

依賴

依賴清單 6 項

原始碼儲存庫

使用此套件的專案