TalkSession
This is the entry point to the TalkJS Flutter Data API.
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
Your app's unique TalkJS ID. Get it from the **Settings** page of the dashboard.
The id of the user you want to connect and act as. Any messages you send will be sent as this user.
A token to authenticate the session with. Ignored if a TalkSession object already exists for this appId + userId.
Returns
| 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 |
The unique TalkJS ID that you passed when calling getTalkSession
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.
Future<ConversationRef> talkSession.conversation(id)
Get a reference to a conversation
Returns
A ConversationRef for the conversation with that ID
ErrorSubscription talkSession.onError(handler)
Attaches a handler that will be called when the session encounters an error
Returns a callback which detaches your handler
Returns
ConversationListSubscription talkSession.subscribeConversations(onSnapshot)
Subscribes to the most recently active conversations for the current user
Parameters
Returns
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
The binary audio data. Usually a File.
Information about the audio file.
Returns
A file token that can be used to send the audio file in a message.
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.
Returns
A file token that can be used to send the file in a message.
Future<String> talkSession.uploadImage(data, metadata)
Upload an image with image-specific metadata.
This is a variant of TalkSession.uploadFile used for images.
Returns
A file token that can be used to send the image in a message.
Future<String> talkSession.uploadVideo(data, metadata)
Upload a video with video-specific metadata.
This is a variant of TalkSession.uploadFile used for videos.
Returns
A file token that can be used to send the video in a message.
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
The binary audio data. Usually a File.
Information about the voice recording.
Returns
A file token that can be used to send the audio file in a message.
Future<void> errorSubscription.unsubscribe()
Returns
The name of the file including extension.
The name of the file including extension.
The height of the image in pixels, if known.
The width of the image in pixels, if known.
The duration of the video in seconds, if known.
The name of the file including extension.
The height of the video in pixels, if known.
The width of the video in pixels, if known.
The duration of the audio file in seconds, if known.
The name of the file including extension.
The duration of the recording in seconds, if known.
The name of the file including extension.