updated controls, android compatiblity
This commit is contained in:
@@ -32,10 +32,15 @@ android {
|
|||||||
main.java.srcDirs += 'src/main/kotlin'
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
compileOptions {
|
||||||
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
|
}
|
||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||||
applicationId "com.example.livekit_example"
|
applicationId "io.livekit.flutter_example"
|
||||||
minSdkVersion 16
|
minSdkVersion 21
|
||||||
targetSdkVersion 30
|
targetSdkVersion 30
|
||||||
versionCode flutterVersionCode.toInteger()
|
versionCode flutterVersionCode.toInteger()
|
||||||
versionName flutterVersionName
|
versionName flutterVersionName
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.example.livekit_example">
|
package="com.example.livekit_example">
|
||||||
|
|
||||||
|
<uses-feature android:name="android.hardware.camera" />
|
||||||
|
<uses-feature android:name="android.hardware.camera.autofocus" />
|
||||||
|
<uses-permission android:name="android.permission.CAMERA" />
|
||||||
|
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
|
||||||
|
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="livekit_example"
|
android:label="LiveKit Example"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
@@ -32,6 +41,7 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<!-- Don't delete the meta-data below.
|
<!-- Don't delete the meta-data below.
|
||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||||
<meta-data
|
<meta-data
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ class PreConnect extends StatefulWidget {
|
|||||||
@override
|
@override
|
||||||
State<StatefulWidget> createState() {
|
State<StatefulWidget> createState() {
|
||||||
return _PreConnectState(
|
return _PreConnectState(
|
||||||
'ws://localhost:7880',
|
'<livekit_host>',
|
||||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5ODQzNDMyMzUsImlzcyI6IkFQSU1teGlMOHJxdUt6dFpFb1pKVjlGYiIsImp0aSI6InNlY29uZCIsIm5iZiI6MTYyNDM0MzIzNSwidmlkZW8iOnsicm9vbSI6Im15cm9vbSIsInJvb21Kb2luIjp0cnVlfX0.USJmnqcLabtsX5A0ZIjguG7jnbVkbZxi5RyPxLOXgOg',
|
'<access_token>',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-17
@@ -32,6 +32,20 @@ class _RoomState extends State<RoomWidget> with RoomDelegate {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_onConnected() async {
|
||||||
|
// video will fail when running in ios simulator
|
||||||
|
try {
|
||||||
|
var localVideo = await LocalVideoTrack.createCameraTrack();
|
||||||
|
await widget.room.localParticipant.publishVideoTrack(localVideo);
|
||||||
|
} catch (e) {
|
||||||
|
print('could not publish video: $e');
|
||||||
|
}
|
||||||
|
|
||||||
|
var localAudio = await LocalAudioTrack.createTrack();
|
||||||
|
await widget.room.localParticipant.publishAudioTrack(localAudio);
|
||||||
|
sortParticipants();
|
||||||
|
}
|
||||||
|
|
||||||
void _onChange() {
|
void _onChange() {
|
||||||
sortParticipants();
|
sortParticipants();
|
||||||
}
|
}
|
||||||
@@ -92,20 +106,6 @@ class _RoomState extends State<RoomWidget> with RoomDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_onConnected() async {
|
|
||||||
// video will fail when running in ios simulator
|
|
||||||
try {
|
|
||||||
var localVideo = await LocalVideoTrack.createCameraTrack();
|
|
||||||
await widget.room.localParticipant.publishVideoTrack(localVideo);
|
|
||||||
} catch (e) {
|
|
||||||
print('could not publish video: $e');
|
|
||||||
}
|
|
||||||
|
|
||||||
var localAudio = await LocalAudioTrack.createTrack();
|
|
||||||
await widget.room.localParticipant.publishAudioTrack(localAudio);
|
|
||||||
sortParticipants();
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
_lastContext = context;
|
_lastContext = context;
|
||||||
@@ -184,6 +184,14 @@ class _VideoViewState extends State<VideoView> with ParticipantDelegate {
|
|||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didUpdateWidget(covariant VideoView oldWidget) {
|
||||||
|
oldWidget.participant.removeListener(_onParticipantChanged);
|
||||||
|
widget.participant.addListener(_onParticipantChanged);
|
||||||
|
_onParticipantChanged();
|
||||||
|
super.didUpdateWidget(oldWidget);
|
||||||
|
}
|
||||||
|
|
||||||
// register for change so Flutter will re-build the widget upon change
|
// register for change so Flutter will re-build the widget upon change
|
||||||
void _onParticipantChanged() {
|
void _onParticipantChanged() {
|
||||||
var subscribedVideos = widget.participant.videoTracks.values.where((pub) {
|
var subscribedVideos = widget.participant.videoTracks.values.where((pub) {
|
||||||
@@ -198,10 +206,13 @@ class _VideoViewState extends State<VideoView> with ParticipantDelegate {
|
|||||||
if (videoPub is RemoteTrackPublication) {
|
if (videoPub is RemoteTrackPublication) {
|
||||||
videoPub.videoQuality = widget.quality;
|
videoPub.videoQuality = widget.quality;
|
||||||
}
|
}
|
||||||
this.videoPub = videoPub;
|
// when muted, show placeholder
|
||||||
} else {
|
if (!videoPub.muted) {
|
||||||
this.videoPub = null;
|
this.videoPub = videoPub;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
this.videoPub = null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,15 +14,17 @@ class Controls extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _ControlsState extends State<Controls> {
|
class _ControlsState extends State<Controls> {
|
||||||
|
CameraPosition position = CameraPosition.FRONT;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
widget.participant.addListener(_onChange);
|
participant.addListener(_onChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
widget.participant.removeListener(_onChange);
|
participant.removeListener(_onChange);
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +71,31 @@ class _ControlsState extends State<Controls> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_setCameraPosition(TrackPublication? pub, CameraPosition position) async {
|
||||||
|
if (this.position == position) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
LocalVideoTrack? track;
|
||||||
|
if (pub?.track is LocalVideoTrack) {
|
||||||
|
track = pub!.track as LocalVideoTrack;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (track == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await track.restartTrack(LocalVideoTrackOptions(position: position));
|
||||||
|
} catch (e) {
|
||||||
|
print('could not restart track: $e');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
this.position = position;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
_exit() {
|
_exit() {
|
||||||
widget.room.disconnect();
|
widget.room.disconnect();
|
||||||
}
|
}
|
||||||
@@ -100,7 +127,8 @@ class _ControlsState extends State<Controls> {
|
|||||||
videoPub = participant.videoTracks.values.first;
|
videoPub = participant.videoTracks.values.first;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (videoPub != null && videoPub.muted) {
|
var videoEnabled = videoPub != null && !videoPub.muted;
|
||||||
|
if (videoEnabled) {
|
||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
onPressed: _muteVideo,
|
onPressed: _muteVideo,
|
||||||
icon: const Icon(Icons.videocam_rounded),
|
icon: const Icon(Icons.videocam_rounded),
|
||||||
@@ -112,11 +140,34 @@ class _ControlsState extends State<Controls> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (position == CameraPosition.FRONT) {
|
||||||
|
buttons.add(IconButton(
|
||||||
|
icon: const Icon(Icons.video_camera_front_rounded),
|
||||||
|
onPressed: videoEnabled
|
||||||
|
? () {
|
||||||
|
_setCameraPosition(videoPub, CameraPosition.BACK);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
buttons.add(IconButton(
|
||||||
|
icon: const Icon(Icons.video_camera_back_rounded),
|
||||||
|
onPressed: videoEnabled
|
||||||
|
? () {
|
||||||
|
_setCameraPosition(videoPub, CameraPosition.FRONT);
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
buttons.add(IconButton(
|
buttons.add(IconButton(
|
||||||
onPressed: _exit,
|
onPressed: _exit,
|
||||||
icon: const Icon(Icons.close_rounded),
|
icon: const Icon(Icons.close_rounded),
|
||||||
));
|
));
|
||||||
|
|
||||||
return Row(children: buttons);
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: buttons,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user