updated controls, android compatiblity
This commit is contained in:
@@ -32,10 +32,15 @@ android {
|
||||
main.java.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId "com.example.livekit_example"
|
||||
minSdkVersion 16
|
||||
applicationId "io.livekit.flutter_example"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 30
|
||||
versionCode flutterVersionCode.toInteger()
|
||||
versionName flutterVersionName
|
||||
|
||||
@@ -1,7 +1,16 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
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
|
||||
android:label="livekit_example"
|
||||
android:label="LiveKit Example"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
@@ -32,6 +41,7 @@
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- Don't delete the meta-data below.
|
||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
||||
<meta-data
|
||||
|
||||
@@ -31,8 +31,8 @@ class PreConnect extends StatefulWidget {
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _PreConnectState(
|
||||
'ws://localhost:7880',
|
||||
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE5ODQzNDMyMzUsImlzcyI6IkFQSU1teGlMOHJxdUt6dFpFb1pKVjlGYiIsImp0aSI6InNlY29uZCIsIm5iZiI6MTYyNDM0MzIzNSwidmlkZW8iOnsicm9vbSI6Im15cm9vbSIsInJvb21Kb2luIjp0cnVlfX0.USJmnqcLabtsX5A0ZIjguG7jnbVkbZxi5RyPxLOXgOg',
|
||||
'<livekit_host>',
|
||||
'<access_token>',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+28
-17
@@ -32,6 +32,20 @@ class _RoomState extends State<RoomWidget> with RoomDelegate {
|
||||
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() {
|
||||
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
|
||||
Widget build(BuildContext context) {
|
||||
_lastContext = context;
|
||||
@@ -184,6 +184,14 @@ class _VideoViewState extends State<VideoView> with ParticipantDelegate {
|
||||
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
|
||||
void _onParticipantChanged() {
|
||||
var subscribedVideos = widget.participant.videoTracks.values.where((pub) {
|
||||
@@ -198,10 +206,13 @@ class _VideoViewState extends State<VideoView> with ParticipantDelegate {
|
||||
if (videoPub is RemoteTrackPublication) {
|
||||
videoPub.videoQuality = widget.quality;
|
||||
}
|
||||
this.videoPub = videoPub;
|
||||
} else {
|
||||
this.videoPub = null;
|
||||
// when muted, show placeholder
|
||||
if (!videoPub.muted) {
|
||||
this.videoPub = videoPub;
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.videoPub = null;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -14,15 +14,17 @@ class Controls extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _ControlsState extends State<Controls> {
|
||||
CameraPosition position = CameraPosition.FRONT;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
widget.participant.addListener(_onChange);
|
||||
participant.addListener(_onChange);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
widget.participant.removeListener(_onChange);
|
||||
participant.removeListener(_onChange);
|
||||
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() {
|
||||
widget.room.disconnect();
|
||||
}
|
||||
@@ -100,7 +127,8 @@ class _ControlsState extends State<Controls> {
|
||||
videoPub = participant.videoTracks.values.first;
|
||||
}
|
||||
|
||||
if (videoPub != null && videoPub.muted) {
|
||||
var videoEnabled = videoPub != null && !videoPub.muted;
|
||||
if (videoEnabled) {
|
||||
buttons.add(IconButton(
|
||||
onPressed: _muteVideo,
|
||||
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(
|
||||
onPressed: _exit,
|
||||
icon: const Icon(Icons.close_rounded),
|
||||
));
|
||||
|
||||
return Row(children: buttons);
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: buttons,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user