startStreamSession method
- required String applicationIdentifier,
- required String identifier,
- required Protocol protocol,
- required String signalRequest,
- Map<
String, String> ? additionalEnvironmentVariables, - List<
String> ? additionalLaunchArgs, - String? clientToken,
- int? connectionTimeoutSeconds,
- String? description,
- List<
String> ? locations, - PerformanceStatsConfiguration? performanceStatsConfiguration,
- int? sessionLengthSeconds,
- String? userId,
This action initiates a new stream session and outputs connection information that clients can use to access the stream. A stream session refers to an instance of a stream that Amazon GameLift Streams transmits from the server to the end-user. A stream session runs on a compute resource that a stream group has allocated. The start stream session process works as follows:
-
Prerequisites:
-
You must have a stream group in
ACTIVEstatus - You must have idle or on-demand capacity in a stream group in the location you want to stream from
- You must have at least one application associated to the stream group (use AssociateApplications if needed)
-
You must have a stream group in
-
Start stream request:
- Your backend server calls StartStreamSession to initiate connection
- Amazon GameLift Streams creates the stream session resource, assigns an Amazon Resource Name (ARN) value, and begins searching for available stream capacity to run the stream
-
Session transitions to
ACTIVATINGstatus
-
Placement completion:
-
If Amazon GameLift Streams is successful in finding capacity for the
stream, the stream session status changes to
ACTIVEstatus and StartStreamSession returns stream connection information -
If Amazon GameLift Streams was not successful in finding capacity within
the placement timeout period (defined according to the capacity type and
platform type), the stream session status changes to
ERRORstatus and StartStreamSession returns aStatusReasonofplacementTimeout
-
If Amazon GameLift Streams is successful in finding capacity for the
stream, the stream session status changes to
-
Connection completion:
- Provide the new connection information to the requesting client
-
Client must establish connection within
ConnectionTimeoutSeconds(specified in StartStreamSession parameters) - Session terminates automatically if client fails to connect in time
Timeouts to be aware of that affect a stream session:
-
Placement timeout: The amount of time that Amazon GameLift Streams
has to find capacity for a stream request. Placement timeout varies based
on the capacity type used to fulfill your stream request:
- Always-on capacity: 75 seconds
-
On-demand capacity:
- Linux/Proton runtimes: 90 seconds
- Windows runtime: 10 minutes
-
Connection timeout: The amount of time that Amazon GameLift Streams
waits for a client to connect to a stream session in
ACTIVEstatus, or reconnect to a stream session inPENDING_CLIENT_RECONNECTIONstatus, the latter of which occurs when a client disconnects or loses connection from a stream session. If no client connects before the timeout, Amazon GameLift Streams terminates the stream session. This value is specified byConnectionTimeoutSecondsin theStartStreamSessionparameters. -
Maximum session length: A stream session will be terminated after
this amount of time has elapsed since it started, regardless of any
existing client connections. This value is specified by
SessionLengthSecondsin theStartStreamSessionparameters.
For stream groups that have multiple locations, provide a set of locations
ordered by priority using a Locations parameter. Amazon
GameLift Streams will start a single stream session in the next available
location. An application must be finished replicating to a remote location
before the remote location can host a stream.
To reconnect to a stream session after a client disconnects or loses connection, use CreateStreamSessionConnection.
May throw AccessDeniedException.
May throw ConflictException.
May throw InternalServerException.
May throw ResourceNotFoundException.
May throw ThrottlingException.
May throw ValidationException.
Parameter applicationIdentifier :
An Amazon
Resource Name (ARN) or ID that uniquely identifies the application
resource. Example ARN:
arn:aws:gameliftstreams:us-west-2:111122223333:application/a-9ZY8X7Wv6.
Example ID: a-9ZY8X7Wv6.
Parameter identifier :
The stream group to run this stream session with.
This value is an Amazon
Resource Name (ARN) or ID that uniquely identifies the stream group
resource. Example ARN:
arn:aws:gameliftstreams:us-west-2:111122223333:streamgroup/sg-1AB2C3De4.
Example ID: sg-1AB2C3De4.
Parameter protocol :
The data transport protocol to use for the stream session.
Parameter signalRequest :
A WebRTC ICE offer string to use when initializing a WebRTC connection.
Typically, the offer is a very long JSON string. Provide the string as a
text value in quotes.
Amazon GameLift Streams also supports setting the field to "NO_CLIENT_CONNECTION". This will create a session without needing any browser request or Web SDK integration. The session starts up as usual and waits for a reconnection from a browser, which is accomplished using CreateStreamSessionConnection.
Parameter additionalEnvironmentVariables :
A set of options that you can use to control the stream session runtime
environment, expressed as a set of key-value pairs. You can use this to
configure the application or stream session details. You can also provide
custom environment variables that Amazon GameLift Streams passes to your
game client.
AdditionalEnvironmentVariables and
AdditionalLaunchArgs have similar purposes.
AdditionalEnvironmentVariables passes data using environment
variables; while AdditionalLaunchArgs passes data using
command-line arguments.
Parameter additionalLaunchArgs :
A list of CLI arguments that are sent to the streaming server when a
stream session launches. You can use this to configure the application or
stream session details. You can also provide custom arguments that Amazon
GameLift Streams passes to your game client.
AdditionalEnvironmentVariables and
AdditionalLaunchArgs have similar purposes.
AdditionalEnvironmentVariables passes data using environment
variables; while AdditionalLaunchArgs passes data using
command-line arguments.
Parameter clientToken :
A unique identifier that represents a client request. The request is
idempotent, which ensures that an API request completes only once. When
users send a request, Amazon GameLift Streams automatically populates this
field.
Parameter connectionTimeoutSeconds :
Length of time (in seconds) that Amazon GameLift Streams should wait for a
client to connect or reconnect to the stream session. Applies to both
connection and reconnection scenarios. This time span starts when the
stream session reaches ACTIVE state. If no client connects
before the timeout, Amazon GameLift Streams terminates the stream session.
Default value is 120.
Parameter description :
A human-readable label for the stream session. You can update this value
later.
Parameter locations :
A list of locations, in order of priority, where you want Amazon GameLift
Streams to start a stream from. For example, us-east-1.
Amazon GameLift Streams selects the location with the next available
capacity to start a single stream session in. If this value is empty,
Amazon GameLift Streams attempts to start a stream session in the primary
location.
For a complete list of locations that Amazon GameLift Streams supports, refer to Regions, quotas, and limitations in the Amazon GameLift Streams Developer Guide.
Parameter performanceStatsConfiguration :
Configuration settings for sharing the stream session's performance stats
with the client
Parameter sessionLengthSeconds :
The maximum duration of a session. Amazon GameLift Streams will
automatically terminate a session after this amount of time has elapsed,
regardless of any existing client connections. Default value is 43200 (12
hours).
Parameter userId :
An opaque, unique identifier for an end-user, defined by the developer.
Implementation
Future<StartStreamSessionOutput> startStreamSession({
required String applicationIdentifier,
required String identifier,
required Protocol protocol,
required String signalRequest,
Map<String, String>? additionalEnvironmentVariables,
List<String>? additionalLaunchArgs,
String? clientToken,
int? connectionTimeoutSeconds,
String? description,
List<String>? locations,
PerformanceStatsConfiguration? performanceStatsConfiguration,
int? sessionLengthSeconds,
String? userId,
}) async {
_s.validateNumRange(
'connectionTimeoutSeconds',
connectionTimeoutSeconds,
1,
3600,
);
_s.validateNumRange(
'sessionLengthSeconds',
sessionLengthSeconds,
1,
86400,
);
final $payload = <String, dynamic>{
'ApplicationIdentifier': applicationIdentifier,
'Protocol': protocol.value,
'SignalRequest': signalRequest,
if (additionalEnvironmentVariables != null)
'AdditionalEnvironmentVariables': additionalEnvironmentVariables,
if (additionalLaunchArgs != null)
'AdditionalLaunchArgs': additionalLaunchArgs,
'ClientToken': clientToken ?? _s.generateIdempotencyToken(),
if (connectionTimeoutSeconds != null)
'ConnectionTimeoutSeconds': connectionTimeoutSeconds,
if (description != null) 'Description': description,
if (locations != null) 'Locations': locations,
if (performanceStatsConfiguration != null)
'PerformanceStatsConfiguration': performanceStatsConfiguration,
if (sessionLengthSeconds != null)
'SessionLengthSeconds': sessionLengthSeconds,
if (userId != null) 'UserId': userId,
};
final response = await _protocol.send(
payload: $payload,
method: 'POST',
requestUri:
'/streamgroups/${Uri.encodeComponent(identifier)}/streamsessions',
exceptionFnMap: _exceptionFns,
);
return StartStreamSessionOutput.fromJson(response);
}