initLocalStream method
Initializes the local user media stream.
The media stream must be prepared before the group call enters.
if you allow the user to configure their camera and such ahead of time,
you can pass that stream
on to this function.
This allows you to configure the camera before joining the call without
having to reopen the stream and possibly losing settings.
Implementation
Future<WrappedMediaStream> initLocalStream(
{WrappedMediaStream? stream}) async {
if (state != GroupCallState.LocalCallFeedUninitialized) {
throw Exception('Cannot initialize local call feed in the $state state.');
}
setState(GroupCallState.InitializingLocalCallFeed);
WrappedMediaStream localWrappedMediaStream;
if (stream == null) {
MediaStream stream;
try {
stream = await _getUserMedia(
type == GroupCallType.Video ? CallType.kVideo : CallType.kVoice);
} catch (error) {
setState(GroupCallState.LocalCallFeedUninitialized);
rethrow;
}
final userId = client.userID;
localWrappedMediaStream = WrappedMediaStream(
renderer: voip.delegate.createRenderer(),
stream: stream,
userId: userId!,
room: room,
client: client,
purpose: SDPStreamMetadataPurpose.Usermedia,
audioMuted: stream.getAudioTracks().isEmpty,
videoMuted: stream.getVideoTracks().isEmpty,
isWeb: voip.delegate.isWeb,
isGroupCall: true,
);
} else {
localWrappedMediaStream = stream;
}
localUserMediaStream = localWrappedMediaStream;
await localUserMediaStream!.initialize();
await addUserMediaStream(localWrappedMediaStream);
setState(GroupCallState.LocalCallFeedInitialized);
return localWrappedMediaStream;
}