resumeSession method
Resumes an existing live session with the server.
This closes the current WebSocket connection and establishes a new one using the same configuration (URI, headers, model, system instruction, tools, etc.) as the original session.
sessionResumption (optional): The configuration for session resumption,
such as the handle to the previous session state to restore.
Implementation
Future<void> resumeSession(
{SessionResumptionConfig? sessionResumption}) async {
try {
await _wsSubscription.cancel().timeout(const Duration(seconds: 2),
onTimeout: () {
log('live_session.resumeSession: WebSocket subscription cancel timed out.',
error: TimeoutException('Cancel timed out'));
});
await _ws.sink.close().timeout(const Duration(seconds: 2), onTimeout: () {
log('live_session.resumeSession: WebSocket close timed out.',
error: TimeoutException('Close timed out'));
});
_ws = await _performWebSocketSetup(
uri: _uri,
headers: _headers,
modelString: _modelString,
systemInstruction: _systemInstruction,
tools: _tools,
sessionResumption: sessionResumption,
liveGenerationConfig: _liveGenerationConfig,
);
} catch (e) {
log('live_session.resumeSession: WebSocket setup failed', error: e);
rethrow;
}
_listenToWebSocket();
}