TalkSession

View as Markdown

This is the entry point to the TalkJS Flutter Data API.

getTalkSession

Future<TalkSession> getTalkSession({required appId, required userId, token})

Returns a TalkSession option for the specified App ID and User ID.

Backed by a registry, so calling this function twice with the same app and user returns the same session object both times. A new session will be created if the old one encountered an error or got garbage collected.

The token and tokenFetcher properties are ignored if there is already a session for that user in the registry.

Parameters

required appId (named)
: String

Your app's unique TalkJS ID. Get it from the **Settings** page of the dashboard.

required userId (named)
: String

The id of the user you want to connect and act as. Any messages you send will be sent as this user.

token (named)
: String?

A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId.

Returns

Future<TalkSession>

class TalkSession

Method Overview

conversation

Get a reference to a conversation

onError

Attaches a handler that will be called when the session encounters an error

Returns a callback which detaches your handler

subscribeConversations

Subscribes to the most recently active conversations for the current user

uploadAudio

Upload an audio file with audio-specific metadata.

uploadFile

Upload a generic file without any additional metadata.

uploadImage

Upload an image with image-specific metadata.

uploadVideo

Upload a video with video-specific metadata.

uploadVoice

Upload a voice recording with voice-specific metadata.

user

Get a reference to a user

Properties

appId
: String

The unique TalkJS ID that you passed when calling getTalkSession

currentUser
: UserRef

A reference to the user this session is connected as

This is immutable. If you want to connect as a different user, call getTalkSession again to get a new session.

Equivalent to calling TalkSession.user with the current user's ID.

conversation

Future<ConversationRef> talkSession.conversation(id)

Get a reference to a conversation

Parameters

id
: String

The ID of the conversation that you want to reference

Returns

Future<ConversationRef>

A ConversationRef for the conversation with that ID

onError

ErrorSubscription talkSession.onError(handler)

Attaches a handler that will be called when the session encounters an error

Returns a callback which detaches your handler

Parameters

handler
: void Function(Exception error)

Returns

ErrorSubscription

subscribeConversations

ConversationListSubscription talkSession.subscribeConversations(onSnapshot)

Subscribes to the most recently active conversations for the current user

Parameters

onSnapshot
: void Function(List<ConversationSnapshot> snapshot, bool loadedAll)

Returns

ConversationListSubscription

uploadAudio

Future<String> talkSession.uploadAudio(data, metadata)

Upload an audio file with audio-specific metadata.

This is a variant of TalkSession.uploadFile used for audio files.

Parameters

data
: Uint8List

The binary audio data. Usually a File.

Information about the audio file.

Returns

Future<String>

A file token that can be used to send the audio file in a message.

uploadFile

Future<String> talkSession.uploadFile(data, metadata)

Upload a generic file without any additional metadata.

This function does not send any message, it only uploads the file and returns a file token. To send the file in a message, pass the file token in a SendFileBlock when calling ConversationRef.send.

See the documentation for more information about sending files in messages.

If the file is a video, image, audio file, or voice recording, use one of the other functions like instead.

Parameters

data
: Uint8List

The binary file data. Usually a File.

Information about the file

Returns

Future<String>

A file token that can be used to send the file in a message.

uploadImage

Future<String> talkSession.uploadImage(data, metadata)

Upload an image with image-specific metadata.

This is a variant of TalkSession.uploadFile used for images.

Parameters

data
: Uint8List

The binary image data. Usually a File.

Information about the image.

Returns

Future<String>

A file token that can be used to send the image in a message.

uploadVideo

Future<String> talkSession.uploadVideo(data, metadata)

Upload a video with video-specific metadata.

This is a variant of TalkSession.uploadFile used for videos.

Parameters

data
: Uint8List

The binary video data. Usually a File.

Information about the video.

Returns

Future<String>

A file token that can be used to send the video in a message.

uploadVoice

Future<String> talkSession.uploadVoice(data, metadata)

Upload a voice recording with voice-specific metadata.

This is a variant of TalkSession.uploadFile used for voice recordings.

Parameters

data
: Uint8List

The binary audio data. Usually a File.

Information about the voice recording.

Returns

Future<String>

A file token that can be used to send the audio file in a message.

user

Future<UserRef> talkSession.user(id)

Get a reference to a user

Parameters

id
: String

The ID of the user that you want to reference

Returns

Future<UserRef>

A UserRef for the user with that ID

class ErrorSubscription

Method Overview

unsubscribe

Future<void> errorSubscription.unsubscribe()

Returns

Future<void>

class GenericFileMetadata

Method Overview

Properties

filename
: String

The name of the file including extension.

constructor

GenericFileMetadata({required filename})

Parameters

required filename (named)
: String

class ImageFileMetadata

Method Overview

Properties

filename
: String

The name of the file including extension.

height (optional)
: int?

The height of the image in pixels, if known.

width (optional)
: int?

The width of the image in pixels, if known.

constructor

ImageFileMetadata({required filename, width, height})

Parameters

required filename (named)
: String
width (named)
: int?
height (named)
: int?

class VideoFileMetadata

Method Overview

Properties

duration (optional)
: double?

The duration of the video in seconds, if known.

filename
: String

The name of the file including extension.

height (optional)
: int?

The height of the video in pixels, if known.

width (optional)
: int?

The width of the video in pixels, if known.

constructor

VideoFileMetadata({required filename, width, height, duration})

Parameters

required filename (named)
: String
width (named)
: int?
height (named)
: int?
duration (named)
: double?

class AudioFileMetadata

Method Overview

Properties

duration (optional)
: double?

The duration of the audio file in seconds, if known.

filename
: String

The name of the file including extension.

constructor

AudioFileMetadata({required filename, duration})

Parameters

required filename (named)
: String
duration (named)
: double?

class VoiceRecordingFileMetadata

Method Overview

Properties

duration (optional)
: double?

The duration of the recording in seconds, if known.

filename
: String

The name of the file including extension.

constructor

VoiceRecordingFileMetadata({required filename, duration})

Parameters

required filename (named)
: String
duration (named)
: double?