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
4 changes: 2 additions & 2 deletions TRTC-API-Example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if (flutterVersionName == null) {
}

android {
namespace = "com.tencent.trtcflutterapidemo"
namespace = "io.trtc.flutter.apiexample"
compileSdk = 35
ndkVersion = flutter.ndkVersion

Expand All @@ -44,7 +44,7 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "com.tencent.trtcflutterapidemo"
applicationId = "io.trtc.flutter.apiexample"
// You can update the following values to match your application needs.
// For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration.
minSdk = flutter.minSdkVersion
Expand Down
2 changes: 1 addition & 1 deletion TRTC-API-Example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_CAMERA"/>

<application
android:label="TRTCFlutterApiDemo"
android:label="apiExample"
android:name="${applicationName}"
android:icon="@mipmap/ic_launcher">
<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package io.trtc.flutter.apiexample

import io.flutter.embedding.android.FlutterActivity

class MainActivity : FlutterActivity()
23 changes: 23 additions & 0 deletions TRTC-API-Example/lib/common/app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:shared_preferences/shared_preferences.dart';

class AppConfig {
static const defaultRoomId = '20260710';

static late SharedPreferences _prefs;

static String _roomId = defaultRoomId;
static String _userId = DateTime.now()
.millisecondsSinceEpoch.remainder(100000).toString().padLeft(5, '0');

static Future<void> init() async {
_prefs = await SharedPreferences.getInstance();
_roomId = _prefs.getString('room_id') ?? _roomId;
_userId = _prefs.getString('user_id') ?? _userId;
}

static String get roomId => _roomId;
static set roomId(String v) { _roomId = v; _prefs.setString('room_id', v); }

static String get userId => _userId;
static set userId(String v) { _userId = v; _prefs.setString('user_id', v); }
}
5 changes: 4 additions & 1 deletion TRTC-API-Example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:api_example/common/app_config.dart';
import 'package:api_example/router/router_page.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:tencent_rtc_sdk/trtc_cloud_def.dart';

void main() {
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await AppConfig.init();
runApp(const MyApp());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'audio_quality_page.dart';
import 'package:api_example/common/app_config.dart';

class AudioQualityPreparePage extends StatefulWidget {
const AudioQualityPreparePage({Key? key}) : super(key: key);
Expand All @@ -10,8 +11,8 @@ class AudioQualityPreparePage extends StatefulWidget {

class _AudioQualityPreparePageState extends State<AudioQualityPreparePage> {
final _formKey = GlobalKey<FormState>();
final _userIdController = TextEditingController();
final _roomIdController = TextEditingController();
final _userIdController = TextEditingController(text: AppConfig.userId);
final _roomIdController = TextEditingController(text: AppConfig.roomId);

@override
void dispose() {
Expand Down Expand Up @@ -55,7 +56,6 @@ class _AudioQualityPreparePageState extends State<AudioQualityPreparePage> {
border: OutlineInputBorder(),
prefixIcon: Icon(Icons.meeting_room),
),
keyboardType: TextInputType.number,
validator: (value) {
if (value == null || value.isEmpty) {
return 'Please enter room ID';
Expand All @@ -67,6 +67,8 @@ class _AudioQualityPreparePageState extends State<AudioQualityPreparePage> {
ElevatedButton(
onPressed: () {
if (_formKey.currentState?.validate() ?? false) {
AppConfig.roomId = _roomIdController.text;
AppConfig.userId = _userIdController.text;
Navigator.push(
context,
MaterialPageRoute(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AudioQualityState extends ChangeNotifier {
_trtcCloud?.enterRoom(TRTCParams(
sdkAppId: GenerateTestUserSig.sdkAppId,
userId: userId,
roomId: int.parse(roomId),
strRoomId: roomId,
role: TRTCRoleType.anchor,
userSig: GenerateTestUserSig.genTestSig(userId)
), TRTCAppScene.voiceChatRoom);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:tencent_rtc_sdk/trtc_cloud_def.dart';
import 'local_record_state.dart';
import '../../../../common/user_list_widget.dart';
import '../../../../common/user_list_state.dart';
import 'package:api_example/common/app_config.dart';

class LocalRecordPage extends StatefulWidget {
const LocalRecordPage({Key? key}) : super(key: key);
Expand All @@ -18,11 +19,17 @@ class _LocalRecordPageState extends State<LocalRecordPage> with SingleTickerProv
late LocalRecordState _localRecordState;
UserListState? _userListState;

final _roomIdController = TextEditingController(text: AppConfig.roomId);
final _userIdController = TextEditingController(
text: AppConfig.userId);

@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_localRecordState = LocalRecordState();
_localRecordState.roomId = _roomIdController.text;
_localRecordState.localUserId = _userIdController.text;
}

Future<void> _initialize() async {
Expand All @@ -35,6 +42,8 @@ class _LocalRecordPageState extends State<LocalRecordPage> with SingleTickerProv
void dispose() {
_tabController.dispose();
_localRecordState.dispose();
_roomIdController.dispose();
_userIdController.dispose();
_userListState?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -136,9 +145,9 @@ class _LocalRecordPageState extends State<LocalRecordPage> with SingleTickerProv
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
keyboardType: TextInputType.number,
controller: _roomIdController,
onChanged: (value) {
_localRecordState.roomId = int.tryParse(value) ?? 0;
_localRecordState.roomId = value;
},
),
const SizedBox(height: 16),
Expand All @@ -148,6 +157,7 @@ class _LocalRecordPageState extends State<LocalRecordPage> with SingleTickerProv
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
controller: _userIdController,
onChanged: (value) {
_localRecordState.localUserId = value;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class LocalRecordState extends ChangeNotifier {
bool _isInitialized = false;

String? localUserId;
int? roomId;
String? roomId;
UserListState? userListState;

ValueNotifier<bool> isEnterRoom = ValueNotifier(false);
Expand Down Expand Up @@ -64,7 +64,7 @@ class LocalRecordState extends ChangeNotifier {
}

void enterRoom() {
if (localUserId == null || roomId == null) {
if (localUserId == null || roomId == null || roomId!.isEmpty) {
print("VideoContentState localUserId or roomId is null");
Fluttertoast.showToast(msg: "User ID or Room ID cannot be empty");
return;
Expand All @@ -74,7 +74,7 @@ class LocalRecordState extends ChangeNotifier {
TRTCParams(
sdkAppId: GenerateTestUserSig.sdkAppId,
userId: localUserId!,
roomId: roomId!,
strRoomId: roomId!,
role: TRTCRoleType.anchor,
userSig: GenerateTestUserSig.genTestSig(localUserId!)
), TRTCAppScene.videoCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:tencent_rtc_sdk/trtc_cloud_def.dart';
import 'render_params_state.dart';
import '../../../../common/user_list_widget.dart';
import '../../../../common/user_list_state.dart';
import 'package:api_example/common/app_config.dart';

class RenderParamsPage extends StatefulWidget {
const RenderParamsPage({Key? key}) : super(key: key);
Expand All @@ -18,11 +19,17 @@ class _RenderParamsPageState extends State<RenderParamsPage> with SingleTickerPr
late RenderParamsState _renderParamsState;
UserListState? _userListState;

final _roomIdController = TextEditingController(text: AppConfig.roomId);
final _userIdController = TextEditingController(
text: AppConfig.userId);

@override
void initState() {
super.initState();
_tabController = TabController(length: 3, vsync: this); // Adjusted to 3 Tabs
_renderParamsState = RenderParamsState();
_renderParamsState.roomId = _roomIdController.text;
_renderParamsState.localUserId = _userIdController.text;
}

Future<void> _initialize() async {
Expand All @@ -35,6 +42,8 @@ class _RenderParamsPageState extends State<RenderParamsPage> with SingleTickerPr
void dispose() {
_tabController.dispose();
_renderParamsState.dispose();
_roomIdController.dispose();
_userIdController.dispose();
_userListState?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -138,9 +147,9 @@ class _RenderParamsPageState extends State<RenderParamsPage> with SingleTickerPr
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
keyboardType: TextInputType.number,
controller: _roomIdController,
onChanged: (value) {
_renderParamsState.roomId = int.tryParse(value) ?? 0;
_renderParamsState.roomId = value;
},
),
const SizedBox(height: 16),
Expand All @@ -150,6 +159,7 @@ class _RenderParamsPageState extends State<RenderParamsPage> with SingleTickerPr
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
controller: _userIdController,
onChanged: (value) {
_renderParamsState.localUserId = value;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RenderParamsState extends ChangeNotifier {
bool _isInitialized = false;

String? localUserId;
int? roomId;
String? roomId;
UserListState? userListState;

// Local render parameters
Expand Down Expand Up @@ -53,7 +53,7 @@ class RenderParamsState extends ChangeNotifier {
}

void enterRoom() {
if (localUserId == null || roomId == null) {
if (localUserId == null || roomId == null || roomId!.isEmpty) {
print("localUserId or roomId is null");
return;
}
Expand All @@ -62,7 +62,7 @@ class RenderParamsState extends ChangeNotifier {
TRTCParams(
sdkAppId: GenerateTestUserSig.sdkAppId,
userId: localUserId!,
roomId: roomId!,
strRoomId: roomId!,
role: TRTCRoleType.anchor,
userSig: GenerateTestUserSig.genTestSig(localUserId!)
), TRTCAppScene.videoCall);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:tencent_rtc_sdk/trtc_cloud.dart';
import 'package:tencent_rtc_sdk/trtc_cloud_def.dart';
import '../../../../common/user_list_widget.dart';
import '../../../../common/user_list_state.dart';
import 'package:api_example/common/app_config.dart';

class ScreenshotPage extends StatefulWidget {
const ScreenshotPage({Key? key}) : super(key: key);
Expand All @@ -18,11 +19,17 @@ class _ScreenshotPageState extends State<ScreenshotPage> with SingleTickerProvid
late ScreenshotState _screenshotState;
UserListState? _userListState;

final _roomIdController = TextEditingController(text: AppConfig.roomId);
final _userIdController = TextEditingController(
text: AppConfig.userId);

@override
void initState() {
super.initState();
_tabController = TabController(length: 2, vsync: this);
_screenshotState = ScreenshotState();
_screenshotState.roomId = _roomIdController.text;
_screenshotState.localUserId = _userIdController.text;
}

Future<void> _initialize() async {
Expand All @@ -35,6 +42,8 @@ class _ScreenshotPageState extends State<ScreenshotPage> with SingleTickerProvid
void dispose() {
_tabController.dispose();
_screenshotState.dispose();
_roomIdController.dispose();
_userIdController.dispose();
_userListState?.dispose();
super.dispose();
}
Expand Down Expand Up @@ -136,9 +145,9 @@ class _ScreenshotPageState extends State<ScreenshotPage> with SingleTickerProvid
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
keyboardType: TextInputType.number,
controller: _roomIdController,
onChanged: (value) {
_screenshotState.roomId = int.tryParse(value) ?? 0;
_screenshotState.roomId = value;
},
),
const SizedBox(height: 16),
Expand All @@ -148,6 +157,7 @@ class _ScreenshotPageState extends State<ScreenshotPage> with SingleTickerProvid
border: OutlineInputBorder(),
contentPadding: EdgeInsets.symmetric(horizontal: 12, vertical: 12),
),
controller: _userIdController,
onChanged: (value) {
_screenshotState.localUserId = value;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ScreenshotState extends ChangeNotifier {
bool _isInitialized = false;

String? localUserId;
int? roomId;
String? roomId;
UserListState? userListState;

ValueNotifier<bool> isEnterRoom = ValueNotifier(false);
Expand Down Expand Up @@ -52,7 +52,7 @@ class ScreenshotState extends ChangeNotifier {
}

void enterRoom() {
if (localUserId == null || roomId == null) {
if (localUserId == null || roomId == null || roomId!.isEmpty) {
print("ScreenshotState localUserId or roomId is null");
Fluttertoast.showToast(msg: "localUserId or roomId is null");
return;
Expand All @@ -62,7 +62,7 @@ class ScreenshotState extends ChangeNotifier {
TRTCParams(
sdkAppId: GenerateTestUserSig.sdkAppId,
userId: localUserId!,
roomId: roomId!,
strRoomId: roomId!,
role: TRTCRoleType.anchor,
userSig: GenerateTestUserSig.genTestSig(localUserId!)
), TRTCAppScene.videoCall);
Expand Down
Loading