Skip to content

Commit

Permalink
should fix #143
Browse files Browse the repository at this point in the history
  • Loading branch information
shivanshtalwar committed Nov 25, 2023
1 parent 48b92ed commit 5d6bcbe
Show file tree
Hide file tree
Showing 8 changed files with 405 additions and 222 deletions.
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
3 changes: 2 additions & 1 deletion example/lib/Home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class _HomeState extends State<Home> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text("Janus Client Menu")),
appBar: AppBar(
title: Text("Janus Client Menu")),
body: SafeArea(
child: SingleChildScrollView(
child: DefaultTextStyle(
Expand Down
10 changes: 9 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import 'typed_examples/text_room.dart';
void main() {
runApp(MaterialApp(
initialRoute: '/',
themeMode: ThemeMode.light,
theme: ThemeData(
colorScheme: ColorScheme.light(background: Colors.white, primary: Colors.black, secondary: Colors.black, onPrimary: Colors.white, onSecondary: Colors.white),
listTileTheme: ListTileThemeData(titleTextStyle: TextStyle(color: Colors.black)),
appBarTheme: AppBarTheme(titleTextStyle: TextStyle(color: Colors.white), backgroundColor: Colors.purple)),
darkTheme: ThemeData(
colorScheme: ColorScheme.dark(background: Colors.black, primary: Colors.white, secondary: Colors.white, onPrimary: Colors.black, onSecondary: Colors.black),
listTileTheme: ListTileThemeData(titleTextStyle: TextStyle(color: Colors.white)),
appBarTheme: AppBarTheme(titleTextStyle: TextStyle(color: Colors.white), backgroundColor: Colors.grey)),
themeMode: ThemeMode.system,
debugShowCheckedModeBanner: false,
routes: {
"/google-meet": (c) => GoogleMeet(),
Expand Down
455 changes: 274 additions & 181 deletions example/lib/typed_examples/google_meet.dart

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions example/lib/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class StreamRenderer {
String? publisherName;
String? mid;
bool? isAudioMuted;
List<bool> selectedQuality = [false, false, true];
List<bool> subStreamButtonState = [false, false, true];
List<bool> temporalButtonState = [false, true];
ConfigureStreamQuality subStream = ConfigureStreamQuality.HIGH;
ConfigureStreamQuality temporal = ConfigureStreamQuality.MEDIUM;
bool? isVideoMuted;

Future<void> dispose() async {
Expand All @@ -20,10 +23,13 @@ class StreamRenderer {

StreamRenderer(this.id);

Future<void> init() async {
Future<void> init(void Function(void Function()) setState) async {
mediaStream = await createLocalMediaStream('mediaStream_$id');
isAudioMuted = false;
isVideoMuted = false;
videoRenderer.onResize = () {
setState(() {});
};
await videoRenderer.initialize();
videoRenderer.srcObject = mediaStream;
}
Expand All @@ -43,4 +49,4 @@ class VideoRoomPluginStateManager {
subStreamsToFeedIdMap.clear();
feedIdToMidSubscriptionMap.clear();
}
}
}
42 changes: 25 additions & 17 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ packages:
dependency: transitive
description:
name: collection
sha256: "4a07be6cb69c84d677a6c3096fcf960cc3285a8330b4603e0d463d15d9bd934c"
sha256: ee67cb0715911d28db6bf4af1026078bd6f0128b07a5f66fb2ed94ec6783c09a
url: "https://pub.dev"
source: hosted
version: "1.17.1"
version: "1.18.0"
convert:
dependency: transitive
description:
Expand Down Expand Up @@ -243,26 +243,26 @@ packages:
dependency: transitive
description:
name: matcher
sha256: "6501fbd55da300384b768785b83e5ce66991266cec21af89ab9ae7f5ce1c4cbb"
sha256: "1803e76e6653768d64ed8ff2e1e67bea3ad4b923eb5c56a295c3e634bad5960e"
url: "https://pub.dev"
source: hosted
version: "0.12.15"
version: "0.12.16"
material_color_utilities:
dependency: transitive
description:
name: material_color_utilities
sha256: d92141dc6fe1dad30722f9aa826c7fbc896d021d792f80678280601aff8cf724
sha256: "9528f2f296073ff54cb9fee677df673ace1218163c3bc7628093e7eed5203d41"
url: "https://pub.dev"
source: hosted
version: "0.2.0"
version: "0.5.0"
meta:
dependency: transitive
description:
name: meta
sha256: "3c74dbf8763d36539f114c799d8a2d87343b5067e9d796ca22b5eb8437090ee3"
sha256: a6e590c838b18133bb482a2745ad77c5bb7715fb0451209e1a7567d416678b8e
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
package_config:
dependency: transitive
description:
Expand Down Expand Up @@ -488,26 +488,26 @@ packages:
dependency: transitive
description:
name: source_span
sha256: dd904f795d4b4f3b870833847c461801f6750a9fa8e61ea5ac53f9422b31f250
sha256: "53e943d4206a5e30df338fd4c6e7a077e02254531b138a15aec3bd143c1a8b3c"
url: "https://pub.dev"
source: hosted
version: "1.9.1"
version: "1.10.0"
stack_trace:
dependency: transitive
description:
name: stack_trace
sha256: c3c7d8edb15bee7f0f74debd4b9c5f3c2ea86766fe4178eb2a18eb30a0bdaed5
sha256: "73713990125a6d93122541237550ee3352a2d84baad52d375a4cad2eb9b7ce0b"
url: "https://pub.dev"
source: hosted
version: "1.11.0"
version: "1.11.1"
stream_channel:
dependency: transitive
description:
name: stream_channel
sha256: "83615bee9045c1d322bbbd1ba209b7a749c2cbcdcb3fdd1df8eb488b3279c1c8"
sha256: ba2aa5d8cc609d96bbb2899c28934f9e1af5cddbd60a827822ea467161eb54e7
url: "https://pub.dev"
source: hosted
version: "2.1.1"
version: "2.1.2"
string_scanner:
dependency: transitive
description:
Expand All @@ -528,10 +528,10 @@ packages:
dependency: transitive
description:
name: test_api
sha256: eb6ac1540b26de412b3403a163d919ba86f6a973fe6cc50ae3541b80092fdcfb
sha256: "5c2f730018264d276c20e4f1503fd1308dfbbae39ec8ee63c5236311ac06954b"
url: "https://pub.dev"
source: hosted
version: "0.5.1"
version: "0.6.1"
typed_data:
dependency: transitive
description:
Expand Down Expand Up @@ -564,6 +564,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.1.0"
web:
dependency: transitive
description:
name: web
sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152
url: "https://pub.dev"
source: hosted
version: "0.3.0"
web_socket_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -605,5 +613,5 @@ packages:
source: hosted
version: "3.1.2"
sdks:
dart: ">=3.0.0 <3.10.6"
dart: ">=3.2.0-194.0.dev <3.10.6"
flutter: ">=3.3.0"
23 changes: 7 additions & 16 deletions lib/janus_plugin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,10 @@ class JanusPlugin {
_onDataStreamController?.close();
_renegotiationNeededController?.close();
_wsStreamSubscription?.cancel();

await stopAllTracksAndDispose(webRTCHandle?.localStream);
(await webRTCHandle?.peerConnection?.getTransceivers())?.forEach((element) async {
await element.stop();
});
await webRTCHandle?.peerConnection?.close();
await webRTCHandle?.remoteStream?.dispose();
await webRTCHandle?.localStream?.dispose();
Expand Down Expand Up @@ -450,21 +452,10 @@ class JanusPlugin {
if (_context._isUnifiedPlan && !_context._usePlanB) {
_context._logger.finest('using unified plan');
webRTCHandle!.localStream!.getTracks().forEach((element) async {
if (element.kind == 'audio') {
_context._logger.finest('adding audio track in peerconnection');
await webRTCHandle!.peerConnection!.addTrack(element, webRTCHandle!.localStream!);
return;
}
if (simulcastSendEncodings == null) {
_context._logger.finest('adding video track in peerconnection');
await webRTCHandle?.peerConnection?.addTrack(element, webRTCHandle!.localStream!);
} else {
_context._logger.finest('simulcasting enabled, using TransReceiver with custom sendEncodings');
await webRTCHandle!.peerConnection!.addTransceiver(
track: element,
kind: RTCRtpMediaType.RTCRtpMediaTypeVideo,
init: RTCRtpTransceiverInit(direction: TransceiverDirection.SendOnly, sendEncodings: simulcastSendEncodings));
}
await webRTCHandle!.peerConnection!.addTransceiver(
track: element,
kind: element.kind == 'audio' ? RTCRtpMediaType.RTCRtpMediaTypeAudio : RTCRtpMediaType.RTCRtpMediaTypeVideo,
init: RTCRtpTransceiverInit(direction: TransceiverDirection.SendOnly, sendEncodings: element.kind == 'video' ? simulcastSendEncodings : null));
});
} else {
_localStreamController!.sink.add(webRTCHandle!.localStream);
Expand Down
80 changes: 78 additions & 2 deletions lib/wrapper_plugins/janus_video_room_plugin.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,81 @@
part of janus_client;

enum ConfigureStreamQuality { LOW, MEDIUM, HIGH }

class ConfigureStream {
String? mid;
bool? send;
int? fallback;
int? audio_level_average;
int? audio_active_packets;
int? min_delay;
int? max_delay;
ConfigureStreamQuality? substream;
ConfigureStreamQuality? temporal;
ConfigureStreamQuality? spatial_layer;
ConfigureStreamQuality? temporal_layer;

ConfigureStream({
this.mid,
this.substream,
this.temporal,
this.spatial_layer,
this.temporal_layer,
this.send,
this.fallback,
this.audio_level_average,
this.audio_active_packets,
this.min_delay,
this.max_delay,
});

Map<String, dynamic> toMap() {
return {
'mid': mid,
'send': send,
'substream': substream?.index,
'temporal': temporal?.index,
'spatial_layer': spatial_layer?.index,
'temporal_layer': temporal_layer?.index,
'fallback': fallback,
'audio_level_average': audio_level_average,
'audio_active_packets': audio_active_packets,
'min_delay': min_delay,
'max_delay': max_delay,
}..removeWhere((key, value) => value == null);
}

factory ConfigureStream.fromMap(Map<String, dynamic> map) {
return ConfigureStream(
mid: map['mid'],
substream: map['substream'] != null ? ConfigureStreamQuality.values[map['substream']] : null,
temporal: map['temporal'] != null ? ConfigureStreamQuality.values[map['temporal']] : null,
spatial_layer: map['spatial_layer'] != null ? ConfigureStreamQuality.values[map['spatial_layer']] : null,
temporal_layer: map['temporal_layer'] != null ? ConfigureStreamQuality.values[map['temporal_layer']] : null,
send: map['send'],
fallback: map['fallback']?.toInt(),
audio_level_average: map['audio_level_average']?.toInt(),
audio_active_packets: map['audio_active_packets']?.toInt(),
min_delay: map['min_delay']?.toInt(),
max_delay: map['max_delay']?.toInt(),
);
}

String toJson() => json.encode(toMap());

factory ConfigureStream.fromJson(String source) => ConfigureStream.fromMap(json.decode(source));

@override
String toString() {
return '''ConfigureStream(mid: $mid,
substream: $substream,
temporal: $temporal,
spatial_layer: $spatial_layer,
temporal_layer: $temporal_layer,
send: $send, fallback: $fallback, audio_level_average: $audio_level_average, audio_active_packets: $audio_active_packets, min_delay: $min_delay, max_delay: $max_delay)''';
}
}

class JanusVideoRoomPlugin extends JanusPlugin {
JanusVideoRoomPlugin({handleId, context, transport, session})
: super(context: context, handleId: handleId, plugin: JanusPlugins.VIDEO_ROOM, session: session, transport: transport);
Expand Down Expand Up @@ -192,7 +268,7 @@ class JanusVideoRoomPlugin extends JanusPlugin {
dynamic audioActivePackets,
int? audioLevelAverage,
List<Map<String, String>>? descriptions,
List<Map<String, dynamic>>? streams,
List<ConfigureStream>? streams,
bool? restart,
RTCSessionDescription? sessionDescription}) async {
var payload = {
Expand All @@ -204,7 +280,7 @@ class JanusVideoRoomPlugin extends JanusPlugin {
"display": display,
"audio_active_packets": audioActivePackets,
"audio_level_average": audioLevelAverage,
"streams": streams,
"streams": streams?.map((e) => e.toMap()).toList(),
"restart": restart,
"descriptions": descriptions
}..removeWhere((key, value) => value == null);
Expand Down

0 comments on commit 5d6bcbe

Please sign in to comment.