Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/src/core/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ import '../proto/livekit_models.pb.dart' as lk_models;
import '../proto/livekit_rtc.pb.dart' as lk_rtc;
import '../publication/local.dart';
import '../support/disposable.dart';
import '../support/platform.dart' show lkPlatformIsTest, lkPlatformIs, PlatformType;
import '../support/platform.dart'
show lkPlatformIsTest, lkPlatformIs, PlatformType;
import '../support/region_url_provider.dart';
import '../support/websocket.dart';
import '../track/local/local.dart';
Expand Down
3 changes: 2 additions & 1 deletion lib/src/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,8 @@ class ParticipantStateUpdatedEvent with RoomEvent, ParticipantEvent {

/// [Pariticpant]'s [ConnectionQuality] has updated.
/// Emitted by [Room] and [Participant].
class ParticipantConnectionQualityUpdatedEvent with RoomEvent, ParticipantEvent {
class ParticipantConnectionQualityUpdatedEvent
with RoomEvent, ParticipantEvent {
final Participant participant;
final ConnectionQuality connectionQuality;
const ParticipantConnectionQualityUpdatedEvent({
Expand Down
48 changes: 32 additions & 16 deletions lib/src/participant/participant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ import '../utils.dart';

/// Base for [RemoteParticipant] and [LocalParticipant],
/// can not be instantiated directly.
abstract class Participant<T extends TrackPublication> extends DisposableChangeNotifier
with EventsEmittable<ParticipantEvent> {
abstract class Participant<T extends TrackPublication>
extends DisposableChangeNotifier with EventsEmittable<ParticipantEvent> {
/// Reference to [Room]
@internal
final Room room;
Expand Down Expand Up @@ -81,7 +81,8 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN
ParticipantPermissions get permissions => _permissions;

/// Attributes associated with the participant
UnmodifiableMapView<String, String> get attributes => UnmodifiableMapView(_attributes);
UnmodifiableMapView<String, String> get attributes =>
UnmodifiableMapView(_attributes);
Map<String, String> _attributes = {};

// Participant state
Expand All @@ -92,7 +93,8 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN
DateTime get joinedAt {
final pi = _participantInfo;
if (pi != null) {
return DateTime.fromMillisecondsSinceEpoch(pi.joinedAt.toInt() * 1000, isUtc: true);
return DateTime.fromMillisecondsSinceEpoch(pi.joinedAt.toInt() * 1000,
isUtc: true);
}
return DateTime.now();
}
Expand Down Expand Up @@ -191,10 +193,14 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN
}

void _setAttributes(Map<String, String> attrs) {
final diff = mapDiff(_attributes, attrs).map((k, v) => MapEntry(k as String, v as String));
final diff = mapDiff(_attributes, attrs)
.map((k, v) => MapEntry(k as String, v as String));
_attributes = attrs;
if (diff.isNotEmpty) {
[events, room.events].emit(ParticipantAttributesChanged(participant: this, attributes: diff));
[
events,
room.events
].emit(ParticipantAttributesChanged(participant: this, attributes: diff));
}
}

Expand All @@ -211,7 +217,9 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN
@internal
Future<bool> updateFromInfo(lk_models.ParticipantInfo info) async {
logger.fine('LocalParticipant.updateFromInfo(info: $info)');
if (_participantInfo != null && _participantInfo!.sid == info.sid && _participantInfo!.version > info.version) {
if (_participantInfo != null &&
_participantInfo!.sid == info.sid &&
_participantInfo!.version > info.version) {
return false;
}

Expand Down Expand Up @@ -287,14 +295,19 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN
T? getTrackPublicationBySource(TrackSource source) {
if (source == TrackSource.unknown) return null;
// try to find by source
final result = trackPublications.values.firstWhereOrNull((e) => e.source == source);
final result =
trackPublications.values.firstWhereOrNull((e) => e.source == source);
if (result != null) return result;
// try to find by compatibility
return trackPublications.values.where((e) => e.source == TrackSource.unknown).firstWhereOrNull((e) =>
(source == TrackSource.microphone && e.kind == TrackType.AUDIO) ||
(source == TrackSource.camera && e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareVideo && e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareAudio && e.kind == TrackType.AUDIO));
return trackPublications.values
.where((e) => e.source == TrackSource.unknown)
.firstWhereOrNull((e) =>
(source == TrackSource.microphone && e.kind == TrackType.AUDIO) ||
(source == TrackSource.camera && e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareVideo &&
e.kind == TrackType.VIDEO) ||
(source == TrackSource.screenShareAudio &&
e.kind == TrackType.AUDIO));
}

/// Convenience property to check whether [TrackSource.camera] is published or not.
Expand All @@ -304,17 +317,20 @@ abstract class Participant<T extends TrackPublication> extends DisposableChangeN

/// Convenience property to check whether [TrackSource.microphone] is published or not.
bool isMicrophoneEnabled() {
return !(getTrackPublicationBySource(TrackSource.microphone)?.muted ?? true);
return !(getTrackPublicationBySource(TrackSource.microphone)?.muted ??
true);
}

/// Convenience property to check whether [TrackSource.screenShareVideo] is published or not.
bool isScreenShareEnabled() {
return !(getTrackPublicationBySource(TrackSource.screenShareVideo)?.muted ?? true);
return !(getTrackPublicationBySource(TrackSource.screenShareVideo)?.muted ??
true);
}

/// Convenience property to check whether [TrackSource.screenShareAudio] is published or not.
bool isScreenShareAudioEnabled() {
return !(getTrackPublicationBySource(TrackSource.screenShareAudio)?.muted ?? true);
return !(getTrackPublicationBySource(TrackSource.screenShareAudio)?.muted ??
true);
}

/// (Equality operator) [Participant.hashCode] is same as [sid.hashCode].
Expand Down
3 changes: 2 additions & 1 deletion lib/src/types/participant_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ extension ParticipantStateExt on lk_models.ParticipantInfo_State {
lk_models.ParticipantInfo_State.JOINING => ParticipantState.joining,
lk_models.ParticipantInfo_State.JOINED => ParticipantState.joined,
lk_models.ParticipantInfo_State.ACTIVE => ParticipantState.active,
lk_models.ParticipantInfo_State.DISCONNECTED => ParticipantState.disconnected,
lk_models.ParticipantInfo_State.DISCONNECTED =>
ParticipantState.disconnected,
_ => ParticipantState.unknown,
};
}
7 changes: 0 additions & 7 deletions test/core/data_stream_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import 'dart:io';
import 'dart:math';

import 'package:flutter_test/flutter_test.dart';
import 'package:uuid/uuid.dart' show Uuid;

import 'package:livekit_client/livekit_client.dart';
import '../mock/e2e_container.dart';
Expand Down Expand Up @@ -97,12 +96,8 @@ void main() {
});
});

final streamId = Uuid().v4();
var stream = await room.localParticipant?.streamText(StreamTextOptions(
topic: 'chat-stream',
streamId: streamId,
totalSize: 10000,
attachedStreamIds: [],
));
await stream?.write('a' * 10);
await stream?.write('b' * 10);
Expand Down Expand Up @@ -202,10 +197,8 @@ void main() {
'bytes content = ${content}, \n string content = ${utf8.decode(content)}');
});

final streamId = Uuid().v4();
var stream = await room.localParticipant?.streamBytes(StreamBytesOptions(
topic: 'bytes-stream',
streamId: streamId,
totalSize: 30,
));
await stream?.write(utf8.encode('a' * 10));
Expand Down
2 changes: 2 additions & 0 deletions test/core/room_e2e_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ void main() {
expect(
room.events.streamCtrl.stream,
emitsInOrder(<Matcher>[
predicate<ParticipantStateUpdatedEvent>(
(event) => event.participant.sid == remoteParticipantData.sid),
predicate<ParticipantConnectedEvent>(
(event) => event.participant.sid == remoteParticipantData.sid,
),
Expand Down
Loading