ListenTogether V2.2 API

ListenTogether is a .NET 9.0 library for synchronized listening parties. This document covers all public APIs.

ListenTogetherClient

The core class for communicating with the Central Server.

Constructor

public ListenTogetherClient()

Creates a new client instance connected to the ListenTogether Central Server.

Properties

Property Type Description
IsConnected bool Whether currently connected to server
IsHost bool Whether current user is party host
IsHostOnlyMode bool Whether party is in host-only control mode
CanControl bool Whether user can control playback
Reconnection ReconnectionOptions Settings for automatic reconnection

Party Management Methods

SetUserProfile

public void SetUserProfile(string nickname)

Sets and saves the user's nickname (1-50 characters).

CreatePartyAsync

public Task<string> CreatePartyAsync(bool isHostOnlyMode)

Creates a new party session. Returns the generated PIN (e.g., "ABCD-1234").

JoinPartyAsync

public Task JoinPartyAsync(string pin)

Requests to join a party. Wait for OnJoinApproved event.

ApproveUserAsync

public Task ApproveUserAsync(string socketId, bool approved)

(Host only) Approves or rejects a join request.

DisbandPartyAsync

public Task DisbandPartyAsync()

(Host only) Ends the party for everyone.

Playback Control Methods

Note: Throws InvalidOperationException in host-only mode when called by non-host.

UpdateStateAsync

public Task UpdateStateAsync(PartyState state)

Broadcasts playback state update.

SeekToAsync

public Task SeekToAsync(TimeSpan position)

Seeks to a specific position. Broadcasts to all clients.

SendHeartbeatAsync

public Task SendHeartbeatAsync(double positionMs, bool isPlaying)

Sends current position for sync correction.

SignalTrackFinishedAsync

public Task SignalTrackFinishedAsync()

Notifies server that current track finished.

Queue Management Methods

UpdateQueueAsync

public Task UpdateQueueAsync(string action, Track track)

Adds or removes a track. Action: "add" or "remove".

MoveQueueItemAsync

public Task MoveQueueItemAsync(int fromIndex, int toIndex)

Moves a track within the queue.

ClearQueueAsync

public Task ClearQueueAsync()

Removes all tracks from queue.

ShuffleQueueAsync

public Task ShuffleQueueAsync()

Randomly shuffles the queue.

Playback Mode Methods

SetRepeatModeAsync

public Task SetRepeatModeAsync(RepeatMode mode)

Sets repeat mode: Off, One, or All.

SetShuffleAsync

public Task SetShuffleAsync(bool enabled)

Enables or disables shuffle mode.

Events

Party Events

Event Description
OnUserJoined User joined (includes username)
OnUserLeft User left (includes username)
OnUserRequestingJoin (Host) User wants to join
OnJoinApproved Join request approved
OnPartyDisbanded Party ended by host

ReconnectionOptions

public class ReconnectionOptions { public bool Enabled { get; set; } = true; public int MaxRetries { get; set; } = 5; public int BaseDelayMs { get; set; } = 500; public int MaxDelayMs { get; set; } = 30000; public bool AutoRejoinParty { get; set; } = true; }

Uses exponential backoff: 500ms -> 1s -> 2s -> 4s -> ... -> max 30s.

ListenTogetherViewModel

MVVM ViewModel using CommunityToolkit.Mvvm.

Observable Properties

Property Type Description
ConnectionState ConnectionState Current connection state
Nickname string User's nickname
Pin string Current party PIN
TargetPin string PIN to join
StatusMessage string Human-readable status
IsHost bool Is party host
IsHostOnlyMode bool Host-only mode enabled
CanControl bool Can control playback
CurrentTrack Track? Now playing
IsPlaying bool Playback active
CurrentPositionMs double Position in ms
RepeatMode RepeatMode Current repeat mode
IsShuffleEnabled bool Shuffle enabled

Collections

Property Type Description
Queue ObservableCollection<Track> Track queue
Users ObservableCollection<ListenTogetherUser> Party members
PendingRequests ObservableCollection<ListenTogetherUser> Join requests (host)

Models

public class Track { public string SongTitle { get; set; } public string SongId { get; set; } public string ArtistName { get; set; } public string AlbumName { get; set; } public TimeSpan SongDuration { get; set; } public string ArtworkUrl { get; set; } public string SourceType { get; set; } }

Socket.IO Protocol

The client uses standard Socket.IO events to communicate. See source for full event list.