Monday, December 16, 2024

Kotlin Teacher

Kotlin Programming Language Best Tutorial Website

Uncategorized

Implementing Video Call Using ZegoCloud

1. Main.dart

import 'package:flutter/material.dart';
import 'package:zego/Homepage.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {
const MyApp({super.key});

// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(

colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
home:HomePage(),
);
}
}

2. HomePage.dart 

import ‘dart:math’;
import ‘package:flutter/material.dart’;
import ‘package:zego/videocallpage.dart’;

class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(‘ZEGOCLOUD Demo’),
),
body: Center(
child: ElevatedButton(
onPressed: () {
// Generate random userID and userName
String userID = generateRandomID();
String userName = generateRandomUserName();

String callID = ‘call123’; // Keep callID constant for the same session

Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ZegoVideoCallPage(
userID: userID,
userName: userName,
callID: callID,
),
),
);
},
child: Text(‘Start Video Call’),
),
),
);
}

// Generate random userID
String generateRandomID() {
var random = Random();
int randomNumber = random.nextInt(1000); // Generate a random number between 0 and 999
return ‘user_$randomNumber’; // Generate userID in format ‘user_<number>’
}

// Generate random userName
String generateRandomUserName() {
var random = Random();
List<String> names = [‘Sam’, ‘Alex’, ‘Chris’, ‘Taylor’, ‘Jordan’, ‘Morgan’];
return names[random.nextInt(names.length)]; // Randomly select a name from the list
}
}

3.  VideoCallPage.dart

import 'package:flutter/material.dart';
import 'package:zego_uikit_prebuilt_call/zego_uikit_prebuilt_call.dart';

class ZegoVideoCallPage extends StatelessWidget {
final String userID;
final String userName;
final String callID;

ZegoVideoCallPage({
required this.userID,
required this.userName,
required this.callID,
});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('ZEGOCLOUD Video Call'),
),
body: ZegoUIKitPrebuiltCall(
appID: 190523610, // Replace with your ZEGOCLOUD App ID
appSign: '552c487fc21bc631a90572f87ed36fd7207273d458900acb46bbedd9db1e1f22', // Replace with your ZEGOCLOUD App Sign
userID: userID,
userName: userName,
callID: callID,
config: ZegoUIKitPrebuiltCallConfig.groupVideoCall(),
),
);
}
}

One thought on “Implementing Video Call Using ZegoCloud

  • hey there and thank you for your information ?I抳e certainly picked up anything new from right here. I did however expertise a few technical points using this web site, since I experienced to reload the web site a lot of times previous to I could get it to load correctly. I had been wondering if your web host is OK? Not that I am complaining, but slow loading instances times will often affect your placement in google and could damage your quality score if advertising and marketing with Adwords. Well I抦 adding this RSS to my email and can look out for much more of your respective fascinating content. Make sure you update this again very soon..

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *