Skip to content
This repository was archived by the owner on Aug 19, 2026. It is now read-only.

Repository files navigation

Warning

Deprecated / 非推奨

Misskey Streaming support has been integrated into misskey_client since 1.0.0-beta.7.

Streaming機能は misskey_client 1.0.0-beta.7 に統合されました。 新規利用では本パッケージではなく misskey_client を使用してください。

Existing releases will remain available and will not be retracted. See the migration guide.

Misskey Streaming

Demo

License

Language: 🇺🇸 English | 🇯🇵 日本語


English

A Flutter/Dart library for Misskey Streaming API (WebSocket). Subscribe/unsubscribe by channel name, receive events routed by subscription id, with automatic reconnect, exponential backoff, and periodic ping.

Features

  • Subscribe by channel name (string) with optional parameters
  • Per-subscription stream routed by id (returns a handle with id/stream/unsubscribe())
  • Unsubscribe by id or by channel name (bulk)
  • Automatic reconnect with exponential backoff + jitter and max attempts
  • Periodic ping (configurable, can be disabled)
  • Connection state stream (status) and global message stream (messages)

Installation

For new projects, use the integrated Streaming API in misskey_client:

Add to your pubspec.yaml:

dependencies:
  misskey_client: ^1.0.0-beta.7

Existing projects can continue to resolve the final standalone release while they migrate:

dependencies:
  misskey_streaming: ^0.0.2-beta

See Migrating to misskey_client.

Legacy quick start

The following example is retained for existing users. New code should use the integrated API described in the migration guide.

import 'package:misskey_streaming/misskey_streaming.dart';

Future<void> main() async {
  final client = MisskeyStreaming.create(
    origin: Uri.parse('https://misskey.io'),
    token: 'YOUR_ACCESS_TOKEN',
    debugLog: true,
  );
  await client.connect();

  // Subscribe by channel name (auto-generate UUID if id is omitted)
  final handle = await client.subscribeChannelStream(channel: 'homeTimeline');

  // Receive only events routed to the subscription id
  final sub = handle.stream.listen((msg) {
    if (msg.type == 'note') {
      // Parse msg.body as needed
    }
  });

  // Unsubscribe individually
  handle.unsubscribe();

  // Or unsubscribe all subscriptions for a channel
  client.unsubscribeChannel('homeTimeline');

  await sub.cancel();
  await client.dispose();
}

Note Capture Example

To receive real-time updates (reactions, deletions, etc.) for notes, you need to capture them:

import 'package:misskey_streaming/misskey_streaming.dart';

Future<void> main() async {
  final client = MisskeyStreaming.create(
    origin: Uri.parse('https://misskey.io'),
    token: 'YOUR_ACCESS_TOKEN',
  );
  await client.connect();

  final handle = await client.subscribeChannelStream(channel: 'homeTimeline');

  handle.stream.listen((msg) {
    if (msg.type == 'note') {
      // When a new note is received, capture it
      final noteId = msg.body['id'] as String;
      client.captureNote(handle.id, noteId);
    } else if (msg.type == 'reacted') {
      // Reaction added event
      final reaction = msg.body['reaction'];
      final userId = msg.body['userId'];
      print('Reacted: $reaction by $userId');
    } else if (msg.type == 'unreacted') {
      // Reaction removed event
      final reaction = msg.body['reaction'];
      print('Unreacted: $reaction');
    } else if (msg.type == 'deleted') {
      // Note deleted event
      final noteId = msg.body['id'];
      print('Note deleted: $noteId');
    }
  });
}

API Reference

  • Connection

    • Future<void> connect() / Future<void> dispose()
    • Stream<MisskeyConnectionState> get status
  • Subscribe (high-level)

    • Future<MisskeySubscriptionHandle> subscribeChannelStream({required String channel, String? id, Map<String, dynamic> params = const {}})
      • MisskeySubscriptionHandle.id
      • MisskeySubscriptionHandle.stream
      • MisskeySubscriptionHandle.unsubscribe()
  • Unsubscribe

    • void unsubscribeById(String id)
    • int unsubscribeChannel(String channel)
  • Low-level API

    • Future<String> subscribe({required String channel, String? id, Map<String, dynamic> params = const {}})
    • void unsubscribe(String id)
    • Stream<MisskeyMessage> get messages / Stream<MisskeyMessage> messagesFor(String id)
    • void sendToChannel(String subscriptionId, String eventType, [Map<String, dynamic>? payload])
  • Note Capture (for real-time updates)

    • void captureNote(String subscriptionId, String noteId) - Capture a note to receive real-time events (reactions, deletions, etc.)
    • void uncaptureNote(String subscriptionId, String noteId) - Stop capturing a note
  • Configuration (MisskeyStreamConfig)

    • origin, token or tokenProvider
    • enableAutoReconnect (default: true)
    • pingInterval (default: 30s, null to disable)
    • connectTimeout, reconnectInitialDelay, reconnectMaxDelay, maxReconnectAttempts

License

This project is published by 司書 (LibraryLibrarian) under the 3-Clause BSD License. For details, please see the LICENSE file.


Japanese

Misskey Streaming API(WebSocket)用のFlutter/Dartライブラリです。チャンネル名(文字列)で購読・解除し、受信イベントは購読ID(id)でルーティングされます。自動再接続・指数バックオフ・定期Pingに対応しています。

機能

  • 任意のチャンネル名で購読(パラメータ指定可)
  • id 単位のルーティング済みストリーム(idstreamunsubscribe() を持つハンドルを返却)
  • id 指定解除/チャンネル名一致の一括解除
  • 自動再接続(指数バックオフ+ジッター、最大試行回数設定)
  • 定期Ping(設定可能、無効化可)
  • 接続状態ストリーム(status)・全件受信ストリーム(messages

インストール

新規プロジェクトでは misskey_client に統合されたStreaming APIを利用して ください。

pubspec.yaml に以下を追加してください:

dependencies:
  misskey_client: ^1.0.0-beta.7

既存プロジェクトは、移行が完了するまで単独パッケージの最終版を引き続き 解決できます。

dependencies:
  misskey_streaming: ^0.0.2-beta

詳細は misskey_clientへの移行ガイドを 参照してください。

既存利用者向けクイックスタート

以下の例は既存利用者向けに残しています。新規コードでは移行ガイドに記載した 統合APIを利用してください。

import 'package:misskey_streaming/misskey_streaming.dart';

Future<void> main() async {
  final client = MisskeyStreaming.create(
    origin: Uri.parse('https://misskey.io'),
    token: 'YOUR_ACCESS_TOKEN',
    debugLog: true,
  );
  await client.connect();

  // 任意チャンネル購読(id未指定はUUID自動採番)
  final handle = await client.subscribeChannelStream(channel: 'homeTimeline');

  // 当該購読idにルーティングされたイベントのみ
  final sub = handle.stream.listen((msg) {
    if (msg.type == 'note') {
      // msg.body を用途に応じてパース
    }
  });

  // 個別解除
  handle.unsubscribe();

  // チャンネル名で一括解除
  client.unsubscribeChannel('homeTimeline');

  await sub.cancel();
  await client.dispose();
}

ノートキャプチャの使用例

ノートのリアルタイム更新(リアクション、削除等)を受信するには、ノートをキャプチャする必要があります:

import 'package:misskey_streaming/misskey_streaming.dart';

Future<void> main() async {
  final client = MisskeyStreaming.create(
    origin: Uri.parse('https://misskey.io'),
    token: 'YOUR_ACCESS_TOKEN',
  );
  await client.connect();

  final handle = await client.subscribeChannelStream(channel: 'homeTimeline');

  handle.stream.listen((msg) {
    if (msg.type == 'note') {
      // 新しいノートを受信したら、キャプチャする
      final noteId = msg.body['id'] as String;
      client.captureNote(handle.id, noteId);
    } else if (msg.type == 'reacted') {
      // リアクション追加イベント
      final reaction = msg.body['reaction'];
      final userId = msg.body['userId'];
      print('リアクション追加: $reaction by $userId');
    } else if (msg.type == 'unreacted') {
      // リアクション削除イベント
      final reaction = msg.body['reaction'];
      print('リアクション削除: $reaction');
    } else if (msg.type == 'deleted') {
      // ノート削除イベント
      final noteId = msg.body['id'];
      print('ノート削除: $noteId');
    }
  });
}

API リファレンス

  • 接続

    • Future<void> connect() / Future<void> dispose()
    • Stream<MisskeyConnectionState> get status
  • 購読(高レベル)

    • Future<MisskeySubscriptionHandle> subscribeChannelStream({required String channel, String? id, Map<String, dynamic> params = const {}})
      • id(サーバーの type: channel メッセージ id と一致)
      • stream(当該 id 宛てイベント)
      • unsubscribe()(個別解除)
  • 解除

    • void unsubscribeById(String id)(ID指定解除)
    • int unsubscribeChannel(String channel)(チャンネル名一致で一括解除)
  • 低レベルAPI

    • Future<String> subscribe({required String channel, String? id, Map<String, dynamic> params = const {}})
    • void unsubscribe(String id)
    • Stream<MisskeyMessage> messages(全件)/ Stream<MisskeyMessage> messagesFor(String id)(個別)
    • void sendToChannel(String subscriptionId, String eventType, [Map<String, dynamic>? payload])
  • ノートキャプチャ(リアルタイム更新用)

    • void captureNote(String subscriptionId, String noteId) - ノートをキャプチャしてリアルタイムイベント(リアクション、削除等)を受信
    • void uncaptureNote(String subscriptionId, String noteId) - ノートのキャプチャを解除
  • 設定(MisskeyStreamConfig

    • origintoken または tokenProvider
    • enableAutoReconnect(既定: true)
    • pingInterval(既定: 30秒、nullで無効)
    • connectTimeoutreconnectInitialDelayreconnectMaxDelaymaxReconnectAttempts

ライセンス

このプロジェクトは司書(LibraryLibrarian)によって、3-Clause BSD Licenseの下で公開されています。詳細は LICENSE をご覧ください。

About

A Flutter wrapper library that makes it easier to use Misskey's streaming API.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Used by

Contributors

Languages