Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AgoraUser #140

Open
kyawthet-wam opened this issue Jun 8, 2023 · 9 comments
Open

AgoraUser #140

kyawthet-wam opened this issue Jun 8, 2023 · 9 comments
Assignees

Comments

@kyawthet-wam
Copy link

#137 (comment) having the same issue when I pinned the remote user.

@tadaspetra
Copy link
Contributor

Can you try this with the new 1.3.4 version?

@kyawthet-wam
Copy link
Author

Can you try this with the new 1.3.4 version?

Screenshot_1687249316

This is with 1.3.4 version.

@tadaspetra
Copy link
Contributor

@kyawthet-wam Can you share the code, stack trace, and what steps you took to reproduce this issue?

@kyawthet-wam
Copy link
Author

@RoutePage()
class VideoCallPage extends ConsumerStatefulWidget {
const VideoCallPage({
Key? key,
required this.token,
required this.channelName,
required this.gpId,
required this.isGroup,
required this.isCaller,
}) : super(key: key);
final String token;
final String channelName;
final int gpId;
final bool isGroup;
final bool isCaller;
@OverRide
VideoCallPageState createState() => VideoCallPageState();
}

class VideoCallPageState extends ConsumerState {
late String chName;
late String token;
late AgoraClient client;
int initialCountDown = 30;
Timer? _timer;
int waitingTime = 0;
var stopwatch = Stopwatch();

void initAgora() async {
await client.initialize();
}

@OverRide
void dispose() {
client.engine.leaveChannel();
client.engine.release();
_timer!.cancel();
super.dispose();
}

@OverRide
void initState() {
super.initState();
chName = widget.channelName;
client = AgoraClient(
agoraEventHandlers: AgoraRtcEventHandlers(
onUserJoined: (connection, remoteUid, elapsed) {
SystemSound.play(SystemSoundType.click);
HapticFeedback.lightImpact();
stopwatch.start();
},
),
agoraConnectionData: AgoraConnectionData(
appId: appId,
rtmUid: widget.gpId.toString(),
channelName: widget.channelName,
username: 'user',
tempToken: widget.token,
uid: SharedPrefs.getInt('user_id')!,
),
);

initAgora();

waitingTime = initialCountDown;

_timer = Timer.periodic(
  const Duration(seconds: 1),
  (_) {
    waitingTime--;
    if (waitingTime == 0 && client.users.isEmpty) {
      EasyLoading.showToast('Call End');
      Navigator.pop(context, {"duration": 0});
    }
  },
);

}

@OverRide
Widget build(BuildContext context) {
final chatNotifier = ref.read(chatMessageListProvider(
Param(p1: widget.gpId, p2: widget.isGroup ? 1 : 0),
).notifier);

void endCall() {
  String text =
      '📹  Video call (${FormatDuration.format(stopwatch.elapsed)})';

  chatNotifier
      .sentGroupMessage(
    groupId: widget.gpId,
    fileList: [],
    text: text,
    fileNameList: [],
  )
      .then((value) {
    value.maybeWhen(
      error: (l) => l.maybeWhen(
        unexpectedError: () => EasyLoading.showToast(
            AppLocalizations.of(context)!.something_went_wrong),
        serverError: (message) => EasyLoading.showToast(message!),
        orElse: () {},
      ),
      orElse: () {
        Navigator.pop(context);
      },
    );
  });
}

void cancelCall() {
  chatNotifier.cancelCall().then((value) {
    value.maybeWhen(
      error: (l) => l.maybeWhen(
        unexpectedError: () => EasyLoading.showToast(
            AppLocalizations.of(context)!.something_went_wrong),
        serverError: (message) => EasyLoading.showToast(message!),
        orElse: () {},
      ),
      saved: () {
        SharedPrefs.setBool('cancel', true);

        Navigator.pop(context);
      },
      orElse: () {},
    );
  });
}

return WillPopScope(
  onWillPop: () {
    if (client.users.isEmpty &&
        stopwatch.elapsed.inSeconds == 0 &&
        widget.isCaller) {
      cancelCall();
    } else if (client.users.isEmpty) {
      endCall();
    } else {
      Navigator.pop(context);
    }
    return Future.value(true);
  },
  child: SafeArea(
    child: Scaffold(
      backgroundColor: Colors.black,
      body: Stack(
        children: [
          AgoraVideoViewer(
            client: client,
            showAVState: true,
            showNumberOfUsers: true,
            layoutType: Layout.floating,
            enableHostControls: true,
          ),
          AgoraVideoButtons(
            client: client,
            disconnectButtonChild: RawMaterialButton(
              onPressed: () {
                if (client.users.isEmpty &&
                    stopwatch.elapsed.inSeconds == 0 &&
                    widget.isCaller) {
                  cancelCall();
                } else if (client.users.isEmpty) {
                  endCall();
                } else {
                  Navigator.pop(context);
                }
              },
              shape: const CircleBorder(),
              elevation: 2.0,
              fillColor: Colors.redAccent,
              padding: const EdgeInsets.all(15.0),
              child: const Icon(
                Icons.call_end,
                color: Colors.white,
                size: 35.0,
              ),
            ),
            autoHideButtons: true,
          ),
        ],
      ),
    ),
  ),
);

}
}

@kyawthet-wam
Copy link
Author

Sorry for my bad code. Thanks for your help.

@kyawthet-wam
Copy link
Author

image

line no 329

@Meherdeep
Copy link
Contributor

@kyawthet-wam This issue should have been fixed with v1.3.4

Can you please try a flutter clean and then installing the dependencies.

@kyawthet-wam
Copy link
Author

@Meherdeep Yes. But it didn't work.

@Meherdeep
Copy link
Contributor

@kyawthet-wam Can you please try the example code and share the SDK logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants