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

HMSUpdateListener listener class not working. #762

Closed
asmitzz opened this issue Jul 26, 2022 · 17 comments
Closed

HMSUpdateListener listener class not working. #762

asmitzz opened this issue Jul 26, 2022 · 17 comments

Comments

@asmitzz
Copy link

asmitzz commented Jul 26, 2022

Version tried
Flutter 3.0.5
hmssdk_flutter: ^0.7.3

What happens -
After Joining the room HMSUpdateListener listener class is sometimes listening the events and sometimes it doesn’t listen.

Code --


class SdkInitializer {
  static HMSSDK hmssdk = HMSSDK();
}

final HMSInteractor hmsInteractor = HMSInteractor()

SdkInitializer.hmssdk.build();
 SdkInitializer.hmssdk.addUpdateListener(listener: hmsInteractor);
 
 class HMSInteractor implements HMSUpdateListener {
  HMSInteractor({required this.bloc});

  final RoomBloc bloc;

  @override
  void onChangeTrackStateRequest({required HMSTrackChangeRequest hmsTrackChangeRequest}) {
    // TODO: implement onChangeTrackStateRequest
  }

  @override
  void onJoin({required HMSRoom room}) {
    bloc.add(OnJoinRoomEvent(room: room));
  }

  @override
  void onMessage({required HMSMessage message}) {
    bloc.add(OnHMSMessageEvent(message: message));
  }

  @override
  void onPeerUpdate({required HMSPeer peer, required HMSPeerUpdate update}) {
   }
  }
  
@Decoder07
Copy link
Contributor

Hi @asmitzz can you share what are the cases when you are not getting the events .

@asmitzz
Copy link
Author

asmitzz commented Jul 26, 2022

Hi @asmitzz can you share what are the cases when you are not getting the events .

I am not getting in any case. ( for ex - onJoin, onPeerUpdate )

@ygit
Copy link
Member

ygit commented Jul 27, 2022

hey @asmitzz
We'll need more info to debug this. Let's get on a call to resolve this. Please book a time convenient to you here: https://calendly.com/yogesh-singh-100ms/15min

@asmitzz
Copy link
Author

asmitzz commented Jul 27, 2022

hey @asmitzz We'll need more info to debug this. Let's get on a call to resolve this. Please book a time convenient to you here: https://calendly.com/yogesh-singh-100ms/15

I have booked a slot for tomorrow at 1pm. Thank you

@asmitzz
Copy link
Author

asmitzz commented Jul 28, 2022

@ygit can we connect now?

@ygit
Copy link
Member

ygit commented Jul 28, 2022

@ygit
Copy link
Member

ygit commented Jul 28, 2022

Resolved ✅

@ygit ygit closed this as completed Jul 28, 2022
@kore-utkarsh
Copy link

kore-utkarsh commented Aug 16, 2022

@ygit I am also facing the same issue. HMSUpdateListener updates the very first time I join the meeting. After that no updates are sent from the class even when remote peer joins.

import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:hmssdk_flutter/hmssdk_flutter.dart';
import 'package:http/http.dart' as http;
import 'package:permission_handler/permission_handler.dart';

import '../../../../core/conference/conference.dart';
import '../../../../core/conference/constants.dart';
import '../../../../src/routes/app_routes.dart';

class ConferenceController extends GetxController implements HMSUpdateListener {
  ConferenceController({
    required HmsConferenceInteractor hmsConferenceInteractor,
    required http.Client httpClient,
  })  : _hmsConferenceInteractor = hmsConferenceInteractor,
        _httpClient = httpClient;

  final HmsConferenceInteractor _hmsConferenceInteractor;
  final http.Client _httpClient;

  // variables
  final localPeer = Rx<HMSPeer?>(null);
  final localVideoTrack = Rx<HMSVideoTrack?>(null);
  final peers = <HMSPeer>[].obs;

  Future<void> joinConference(String roomId, String userId, String role) async {
    if (!(await Permission.camera.isGranted)) {
      final statuses = await [
        Permission.camera,
        Permission.microphone,
      ].request();

      if (statuses[Permission.camera] != PermissionStatus.granted ||
          statuses[Permission.microphone] != PermissionStatus.granted) return;
    }

    final response = await _httpClient.post(
      Uri.parse(HmsConstants.tokenUrl),
      body: jsonEncode(
        <String, String>{
          'room_id': roomId,
          'user_id': userId,
          'role': 'new-role-6590'
        },
      ),
    );

    final data = jsonDecode(response.body) as Map<String, dynamic>;
    final token = '${data['token']}';

    final config = HMSConfig(authToken: token, userName: 'Utkarsh');
    await _hmsConferenceInteractor.joinRoom(config);
    _hmsConferenceInteractor.addUpdateListener(this);
    await Get.toNamed<void>(Routes.eventConference);
  }

  @override
  void onAudioDeviceChanged(
      {HMSAudioDevice? currentAudioDevice,
      List<HMSAudioDevice>? availableAudioDevice}) {
    // TODO: implement onAudioDeviceChanged
  }

  @override
  void onChangeTrackStateRequest(
      {required HMSTrackChangeRequest hmsTrackChangeRequest}) {
    // TODO: implement onChangeTrackStateRequest
  }

  @override
  void onHMSError({required HMSException error}) {
    // TODO: implement onHMSError
  }

  @override
  void onJoin({required HMSRoom room}) {
    debugPrint('${room.name} joined room with ${room.peerCount} peers');
    peers
      ..clear()
      ..addAll(room.peers!);

    for (final each in room.peers!) {
      if (each.isLocal) {
        localPeer.value = each;
        break;
      }
    }
  }

  @override
  void onMessage({required HMSMessage message}) {
    print('New Message - ${message.message}');
  }

  @override
  void onPeerUpdate({required HMSPeer peer, required HMSPeerUpdate update}) {
    if (peer.isLocal) {
      localVideoTrack.value = peer.videoTrack;
    }
    print(
      'Peer joined in ${peer.peerId} ${peer.name} ${peer.videoTrack == null}',
    );
  }

  @override
  void onReconnected() {
    // TODO: implement onReconnected
  }

  @override
  void onReconnecting() {
    // TODO: implement onReconnecting
  }

  @override
  void onRemovedFromRoom(
      {required HMSPeerRemovedFromPeer hmsPeerRemovedFromPeer}) {
    // TODO: implement onRemovedFromRoom
  }

  @override
  void onRoleChangeRequest({required HMSRoleChangeRequest roleChangeRequest}) {
    // TODO: implement onRoleChangeRequest
  }

  @override
  void onRoomUpdate({required HMSRoom room, required HMSRoomUpdate update}) {
    // TODO: implement onRoomUpdate
  }

  @override
  void onTrackUpdate(
      {required HMSTrack track,
      required HMSTrackUpdate trackUpdate,
      required HMSPeer peer}) {
    print('${peer.name} updated to ${track.kind}');
  }

  @override
  void onUpdateSpeakers({required List<HMSSpeaker> updateSpeakers}) {
    // TODO: implement onUpdateSpeakers
  }
}

@Decoder07 Decoder07 reopened this Aug 16, 2022
@Decoder07
Copy link
Contributor

@kore-utkarsh which flutter version are you using ?

@kore-utkarsh
Copy link

@Decoder07

I am using
flutter - 2.10.5
hmssdk_flutter: ^0.7.4

@Decoder07
Copy link
Contributor

Ok,are you getting onJoin callback or not even that?

@kore-utkarsh
Copy link

Yes, getting only the first time when user joins the room. After that not receiving any update in onJoin as well

@Decoder07
Copy link
Contributor

onJoin gets called only once when the local Peer joins the room.For other peers onPeerUpdate gets called.Are you getting this callback ?

@kore-utkarsh
Copy link

No , onPeerUpdate not getting called for remote peers joining.

@Decoder07
Copy link
Contributor

Hi can you check this implementation and try : https://github.com/100mslive/100ms-flutter/tree/main/sample%20apps/getx

@kore-utkarsh
Copy link

@Decoder07 Great! I will check and try implementing with this. Thank you!

@kore-utkarsh
Copy link

@Decoder07 Thanks for the reference sample app. Its now working for me. Issue has been ressolved

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

4 participants