Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Add Listen type to flutter sdk; Add option in ui to swithc between re… #433

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version '1.0-SNAPSHOT'

buildscript {
ext.kotlin_version = '1.7.10'
ext.voxeet_sdk_version = "[3.10.1,3.11)"
ext.voxeet_sdk_version = "[3.11.0,3.12)"
ext.dagger_version = "2.40.5"
repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.dolby.comms.sdk.flutter.mapper

import com.voxeet.VoxeetSDK
import com.voxeet.sdk.models.ListenType
import com.voxeet.sdk.models.VideoForwardingStrategy
import com.voxeet.sdk.services.builders.ConferenceListenOptions

Expand All @@ -25,6 +26,9 @@ class ConferenceListenOptionsMapper {
(options?.get("videoForwardingStrategy") as? String)?.let {
builder.setVideoForwardingStrategy(VideoForwardingStrategy.valueOf(it))
}
(options?.get("listenType") as? String)?.let { listenType ->
builder.setListenType(ListenTypeMapper.fromValue(listenType))
}
builder
.setSpatialAudio(options?.get("spatialAudio") as? Boolean ?: false)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.dolby.comms.sdk.flutter.mapper

import com.voxeet.sdk.models.ListenType
import java.security.InvalidParameterException

object ListenTypeMapper {
fun fromValue(listenType: String): ListenType {
return when (listenType) {
REGULAR -> ListenType.REGULAR
MIXED -> ListenType.MIXED
else -> throw InvalidParameterException("Invalid value for listen type")
}
}


private const val REGULAR = "REGULAR"
private const val MIXED = "MIXED"
}
3 changes: 2 additions & 1 deletion lib/dolbyio_comms_sdk_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export 'src/sdk_api/models/enums.dart'
VideoPresentationState,
VideoPresentationEventNames,
RecordingServiceEventNames,
AudioPreviewEventNames;
AudioPreviewEventNames,
ListenType;
export 'src/sdk_api/models/subscription.dart'
show Subscription, SubscriptionType;
export 'src/sdk_api/models/events.dart'
Expand Down
3 changes: 3 additions & 0 deletions lib/src/sdk_api/models/conference.dart
Original file line number Diff line number Diff line change
Expand Up @@ -584,11 +584,14 @@ class ConferenceListenOptions {
/// Enables spatial audio for the local participant who joins a Dolby Voice conference. By default, this parameter is set to false. When set to true in a conference that uses the individual [SpatialAudioStyle], the application must place remote participants in a 3D space using the [ConferenceService.setSpatialPosition] method.
bool? spatialAudio;

ListenType listenType = ListenType.regular;

/// Returns a representation of this object as a JSON object.
Map<String, Object?> toJson() => {
"conferenceAccessToken": conferenceAccessToken,
"maxVideoForwarding": maxVideoForwarding,
"videoForwardingStrategy": videoForwardingStrategy?.encode(),
"spatialAudio": spatialAudio,
"listenType": listenType
};
}
21 changes: 21 additions & 0 deletions lib/src/sdk_api/models/enums.dart
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,24 @@ enum AudioPreviewEventNames implements EnumWithStringValue {
);
}
}

enum ListenType implements EnumWithStringValue {
regular("REGULAR"),
mixerMix("MIXER_MIX");

@override
final String value;

const ListenType(this.value);

static ListenType valueOf(String? value) {
final lowerCaseValue = value?.toLowerCase();
return ListenType.values.firstWhere(
(element) {
return element.value == value ||
element.name.toLowerCase() == lowerCaseValue;
},
orElse: () => throw Exception("Invalid enum name"),
);
}
}
2 changes: 1 addition & 1 deletion test_app/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
5 changes: 3 additions & 2 deletions test_app/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:dolbyio_comms_sdk_flutter_example/logger/logger_view.dart';
import 'package:dolbyio_comms_sdk_flutter_example/screens/init_sdk_screen.dart';
import 'package:dolbyio_comms_sdk_flutter_example/state_management/models/conference_model.dart';
import 'package:flutter/material.dart';
import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart';
Expand Down Expand Up @@ -61,8 +62,8 @@ class _MyAppState extends State<MyApp> {
widgetText: const Text('Open example app'),
onPressed: () {
Navigator.of(context).push(MaterialPageRoute(
settings: const RouteSettings(name: "LoginScreen"),
builder: (context) => const LoginScreen()));
settings: const RouteSettings(name: "InitSdkScreen"),
builder: (context) => const InitSdkScreen()));
}),
PrimaryButton(
widgetText: const Text('Run playground'),
Expand Down
158 changes: 158 additions & 0 deletions test_app/lib/screens/init_sdk_screen.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import 'dart:developer' as developer;
import 'package:dolbyio_comms_sdk_flutter_example/screens/login_screen.dart';

import 'join_screen.dart';
import 'package:flutter/material.dart';
import 'package:dolbyio_comms_sdk_flutter/dolbyio_comms_sdk_flutter.dart';
import '/widgets/circular_progress_indicator.dart';
import '/widgets/dolby_title.dart';
import '/widgets/input_text_field.dart';
import '/widgets/primary_button.dart';
import '/widgets/text_form_field.dart';
import '../shared_preferences_helper.dart';

class InitSdkScreen extends StatelessWidget {
const InitSdkScreen({Key? key}) : super(key: key);

@override
Widget build(BuildContext context) {
return SafeArea(
left: false,
right: false,
child: Scaffold(
body: Container(
constraints: const BoxConstraints.expand(),
decoration: const BoxDecoration(color: Colors.deepPurple),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: const [
DolbyTitle(title: 'Dolby.io', subtitle: 'Flutter SDK'),
InitSdkScreenContent()
],
),
),
),
);
}
}

class InitSdkScreenContent extends StatefulWidget {
const InitSdkScreenContent({Key? key}) : super(key: key);

@override
State<InitSdkScreenContent> createState() => _InitSdkScreenContentState();
}

class _InitSdkScreenContentState extends State<InitSdkScreenContent> {
final formKey = GlobalKey<FormState>();
final _dolbyioCommsSdkFlutterPlugin = DolbyioCommsSdk.instance;
TextEditingController accessTokenTextController = TextEditingController();
late String _accessToken;
bool isSessionOpen = false, loginInProgress = false;

@override
void initState() {
super.initState();
initSharedPreferences();
}

Future<void> initSessionStatus() async {
await _dolbyioCommsSdkFlutterPlugin.session.isOpen().then((isOpen) {
if (isOpen) {
isSessionOpen = true;
} else {
isSessionOpen = false;
}
});
}

@override
Widget build(BuildContext context) {
return Expanded(
child: Container(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.vertical(top: Radius.circular(16))),
child: Center(
child: SingleChildScrollView(
padding: const EdgeInsets.all(16),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Form(
key: formKey,
autovalidateMode: AutovalidateMode.disabled,
child: Column(
children: [
InputTextFormField(
labelText: 'Access token',
controller: accessTokenTextController,
focusColor: Colors.deepPurple),
const SizedBox(height: 16),
],
)),
const SizedBox(height: 16),
PrimaryButton(
color: Colors.deepPurple,
widgetText: loginInProgress
? const WhiteCircularProgressIndicator()
: const Text('Initialize'),
onPressed: () {
onLoginButtonPressed();
},
)
],
),
),
),
),
);
}

void onLoginButtonPressed() async {
setState(() => loginInProgress = true);
try {
final isValidForm = formKey.currentState!.validate();
if (isValidForm) {
await initializeSdk();
saveToSharedPreferences();
navigateToLoginScreen();
}
} catch (e) {
onError('Error: ', e);
} finally {
setState(() => loginInProgress = false);
}
}

Future<void> initializeSdk() async {
_accessToken = accessTokenTextController.text;
await _dolbyioCommsSdkFlutterPlugin.initializeToken(
_accessToken, () => getRefreshToken());
}

void navigateToLoginScreen() {
Navigator.of(context).push(
MaterialPageRoute(
settings: const RouteSettings(name: "LoginScreen"),
builder: (context) => const LoginScreen(),
),
);
}

Future<String?> getRefreshToken() async {
return _accessToken;
}

void initSharedPreferences() {
accessTokenTextController.text = SharedPreferencesHelper().accessToken;
}

void saveToSharedPreferences() {
SharedPreferencesHelper().accessToken = _accessToken;
}

void onError(String message, Object? error) {
developer.log(message, error: error);
}
}
18 changes: 11 additions & 7 deletions test_app/lib/screens/join_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class _JoinConferenceContentState extends State<JoinConferenceContent> {
"Spatial Audio with Shared Scene";
static const String spatialAudioDisabled = "Spatial Audio Disabled";
bool joinAsListener = false;
bool isRtsViewer = false;
String _conferenceAlias = '';
final LoggerView _loggerView = LoggerView.getLoggerView();

Expand Down Expand Up @@ -287,15 +288,12 @@ class _JoinConferenceContentState extends State<JoinConferenceContent> {
}
}),
SwitchOption(
title: 'Join as listener',
value: joinAsListener,
title: 'Is rts viewer',
value: isRtsViewer,
onChanged: (value) {
if (value == false) {
setState(() => joinAsListener = value);
} else {
setState(() => joinAsListener = value);
}
setState(() => isRtsViewer = value);
}),
]),
DropdownButton<String>(
focusColor: Colors.white,
value: switchDolbyVoice
Expand Down Expand Up @@ -560,8 +558,14 @@ class _JoinConferenceContentState extends State<JoinConferenceContent> {

ConferenceListenOptions conferenceListenOptions() {
var listenOptions = ConferenceListenOptions();

listenOptions.maxVideoForwarding = 4;
listenOptions.spatialAudio = spatialAudio;
if (isRtsViewer) {
listenOptions.listenType = ListenType.mixerMix;
} else {
listenOptions.listenType = ListenType.regular;
}
return listenOptions;
}

Expand Down
19 changes: 0 additions & 19 deletions test_app/lib/screens/login_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,8 @@ class LoginScreenContent extends StatefulWidget {
class _LoginScreenContentState extends State<LoginScreenContent> {
final formKey = GlobalKey<FormState>();
final _dolbyioCommsSdkFlutterPlugin = DolbyioCommsSdk.instance;
TextEditingController accessTokenTextController = TextEditingController();
TextEditingController usernameTextController = TextEditingController();
TextEditingController externalIdTextController = TextEditingController();
late String _accessToken;
late String _username;
late String? _externalId;
bool isSessionOpen = false, loginInProgress = false;
Expand Down Expand Up @@ -89,10 +87,6 @@ class _LoginScreenContentState extends State<LoginScreenContent> {
autovalidateMode: AutovalidateMode.disabled,
child: Column(
children: [
InputTextFormField(
labelText: 'Access token',
controller: accessTokenTextController,
focusColor: Colors.deepPurple),
const SizedBox(height: 16),
InputTextFormField(
labelText: 'Username',
Expand Down Expand Up @@ -128,7 +122,6 @@ class _LoginScreenContentState extends State<LoginScreenContent> {
try {
final isValidForm = formKey.currentState!.validate();
if (isValidForm) {
await initializeSdk();
await openSession();
await initSessionStatus();
saveToSharedPreferences();
Expand All @@ -143,12 +136,6 @@ class _LoginScreenContentState extends State<LoginScreenContent> {
}
}

Future<void> initializeSdk() async {
_accessToken = accessTokenTextController.text;
await _dolbyioCommsSdkFlutterPlugin.initializeToken(
_accessToken, () => getRefreshToken());
}

Future<void> openSession() async {
_username = usernameTextController.text;
_externalId = externalIdTextController.text;
Expand All @@ -173,17 +160,11 @@ class _LoginScreenContentState extends State<LoginScreenContent> {
);
}

Future<String?> getRefreshToken() async {
return _accessToken;
}

void initSharedPreferences() {
accessTokenTextController.text = SharedPreferencesHelper().accessToken;
usernameTextController.text = SharedPreferencesHelper().username;
}

void saveToSharedPreferences() {
SharedPreferencesHelper().accessToken = _accessToken;
SharedPreferencesHelper().username = _username;
}

Expand Down
Loading