Table of Contents

Class StreamingSession

Namespace
Twikit.Streaming
Assembly
Twikit.dll

ストリーミングセッション。await foreach で (Topic, Payload) を受け取ります。

public sealed class StreamingSession : IAsyncEnumerable<(string? Topic, Payload Payload)>
Inheritance
StreamingSession
Implements
Inherited Members

Examples

var topics = new HashSet<string> { Topic.DmUpdate($"{myId}-{userId}") };
var session = await client.GetStreamingSessionAsync(topics);
await foreach (var (topic, payload) in session)
{
    if (payload.DmUpdate is { } dm) Console.WriteLine($"{dm.ConversationId}: {dm.UserId} sent a message");
}

Constructors

StreamingSession(Client, string, IAsyncEnumerator<(string? Topic, Payload Payload)>, IEnumerable<string>, bool)

public StreamingSession(Client client, string sessionId, IAsyncEnumerator<(string? Topic, Payload Payload)> stream, IEnumerable<string> topics, bool autoReconnect)

Parameters

client Client
sessionId string
stream IAsyncEnumerator<(string Topic, Payload Payload)>
topics IEnumerable<string>
autoReconnect bool

Properties

AutoReconnect

切断時に自動で再接続するか。

public bool AutoReconnect { get; set; }

Property Value

bool

Id

セッションの ID。

public string Id { get; }

Property Value

string

Topics

ストリーム中のトピック。

public HashSet<string> Topics { get; }

Property Value

HashSet<string>

Methods

GetAsyncEnumerator(CancellationToken)

Returns an enumerator that iterates asynchronously through the collection.

public IAsyncEnumerator<(string? Topic, Payload Payload)> GetAsyncEnumerator(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A CancellationToken that may be used to cancel the asynchronous iteration.

Returns

IAsyncEnumerator<(string Topic, Payload Payload)>

An enumerator that can be used to iterate asynchronously through the collection.

ReconnectAsync()

セッションを再接続します。最初に受け取った config イベントを返します。

public Task<(string? Topic, Payload Payload)> ReconnectAsync()

Returns

Task<(string Topic, Payload Payload)>

ToString()

Returns a string that represents the current object.

public override string ToString()

Returns

string

A string that represents the current object.

UpdateSubscriptionsAsync(ISet<string>?, ISet<string>?)

トピックの購読を更新します。

public Task<Payload> UpdateSubscriptionsAsync(ISet<string>? subscribe = null, ISet<string>? unsubscribe = null)

Parameters

subscribe ISet<string>

購読を開始するトピック。

unsubscribe ISet<string>

購読を解除するトピック。

Returns

Task<Payload>