搜索插件、代码仓与 APP 分类

插件详情v0.4.0

eventsource

Server-Sent Events 的客户端和服务器端实现。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
595
喜欢数
30
Pub 分数
120

安装插件

flutter pub add eventsource

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个 Dart 包,提供服务器端推送事件(SSE)的客户端和服务器端实现,支持从服务器到客户端的实时单向通信。它支持通过 HTTP 流式传输事件,非常适合用于实时更新、通知和数据流。该包兼容所有主要平台,包括 Android、iOS、Web、macOS、Windows 和 Linux。它遵循 SSE 标准,支持事件 ID、重试间隔和自定义事件类型。实现轻量且可无缝集成到 Flutter 和 Dart 应用中。

适合场景

  • 实时通知
  • 实时数据流
  • 服务器端事件广播
  • Web 应用中的状态更新
  • 交互式仪表板
  • 日志流

主要特点

  • 完整的 SSE 协议支持
  • 跨平台兼容性
  • 事件 ID 和重试处理
  • 自定义事件类型支持
  • 轻便高效
  • 与 Flutter 的轻松集成

适合对象

  • 实时应用功能
  • 需要推送功能的后端服务
  • 需要低延迟更新的应用
  • 带有实时内容的网页和移动应用
  • 使用 Dart/Flutter 开发全栈应用的开发者

使用建议

  • 不适用于双向通信
  • 需要兼容的服务器实现
  • 仅限服务器到客户端的流式传输
  • 可能需要额外的设置来完成身份验证
  • 最适合高频、低延迟的更新

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

eventsource

A library for using EventSource or Server-Sent Events (SSE). Both client and server functionality is provided.

This library implements the interface as described here.

Client usage

For more advanced usage, see the example/ directory. Creating a new EventSource client is as easy as a single call. The http package is used under the hood, so wherever this package works, this library will also work. Browser usage is slightly different.

EventSource eventSource = await EventSource.connect("http://example.com/events");
// in browsers, you need to pass a http.BrowserClient:
EventSource eventSource = await EventSource.connect("http://example.com/events", 
    client: new http.BrowserClient());

Server usage

We recommend using shelf_eventsource for serving Server-Sent Events. This library provides an EventSourcePublisher that manages subscriptions, channels, encoding. We refer to documentation in the shelf_eventsource package for more information.

This library also includes a server provider for dart:io's HttpServer in io_server.dart. However, it has some issues with data flushing that are yet to be resolved, so we recommend using shelf instead.

Licensing

This project is available under the MIT license, as can be found in the LICENSE file.

所属分类

依赖

依赖清单 5 项

源码仓库

使用此插件的项目

暂无相关数据。