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

sendMetadata is not working #236

Closed
ilyasmez opened this issue Jan 4, 2021 · 12 comments
Closed

sendMetadata is not working #236

ilyasmez opened this issue Jan 4, 2021 · 12 comments

Comments

@ilyasmez
Copy link

ilyasmez commented Jan 4, 2021

Describe the bug
Can't send a metadata.

To Reproduce
Try sending some metadata using

rtcEngine.sendMetadata('test')

The metadata is not sent to the other users and this error is shown in the console:

E/flutter (29530): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(7, not initialized, null, null)
E/flutter (29530): #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582:7)
E/flutter (29530): #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159:18)
E/flutter (29530): <asynchronous suspension>
E/flutter (29530): #2      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter (29530): #3      RtcEngine._invokeMethod (package:agora_rtc_engine/src/rtc_engine.dart:35:27)
E/flutter (29530): #4      RtcEngine.sendMetadata (package:agora_rtc_engine/src/rtc_engine.dart:576:12)

Expected behavior
The metadata is being sent successfully, and caught by the other users using the metadataReceived event listener.

Smartphone (please complete the following information):

  • Device: Pixel 4 (physical), and a few other emulated devices.
  • OS: Android 11
  • Browser [e.g. stock browser, safari]

Additional context
Using agora_rtc_engine: 3.2.1

@LichKing-2234
Copy link
Contributor

PlatformException(7, not initialized, null, null)

you should init engine first

@ilyasmez
Copy link
Author

ilyasmez commented Jan 4, 2021

PlatformException(7, not initialized, null, null)
you should init engine first

Hi @LichKing-2234, thank you for the reply.

I'm initializing the engine before anything else:

_engine = await RtcEngine.create(AGORA_APP_ID);
await _engine.enableVideo();
await _engine.setChannelProfile(ChannelProfile.LiveBroadcasting);
await _engine.setClientRole(ClientRole.Audience);

I don't think this is the problem, because I try to send the metadata during an active live streaming.

@LichKing-2234
Copy link
Contributor

LichKing-2234 commented Jan 4, 2021

Sorry, my mistake, you should call registerMediaMetadataObserver first.

@ilyasmez
Copy link
Author

ilyasmez commented Jan 4, 2021

Great thank you @LichKing-2234, the error is gone now.
But the metadata is still not received by the other users. The string is really short, so it's probably not the due to the size.
I'm trying to send the metadata from the broadcaster to the audience, in case this matters.

This is a simplified snippet:

RtcEngine _engine;

Future<void> initializeAgora() async {
  _engine = await RtcEngine.create(AGORA_APP_ID);

  _engine.setEventHandler(RtcEngineEventHandler(
    metadataReceived: (buffer, _, __) {
      print('Metadata received $buffer');
    },
  ));

  await _engine.registerMediaMetadataObserver();
} 

Future<void> sendAgoraMetadata() async {
  await _engine.sendMetadata( 'test');
} 

And sendAgoraMetadata is called during the video call.
The "Metadata received" is never printed for any user.

@LichKing-2234
Copy link
Contributor

LichKing-2234 commented Jan 5, 2021

maybe you should call setMaxMetadataSize first

@ilyasmez
Copy link
Author

ilyasmez commented Jan 5, 2021

That actually solves the issue (surprisingly), thank you very much @LichKing-2234.
I've called await _engine.setMaxMetadataSize(1024); right after registering the observer and everything worked as expected.
I think this should still be fixed on the SDK level as well, because in the docs it says that the default value is 1024, so my call should be unnecessary (but apparently it's not).
I'll look deeper into this issue if I find time this weekend.

@ilyasmez ilyasmez closed this as completed Jan 6, 2021
@elricym
Copy link

elricym commented Apr 5, 2021

I find the same issue which I can't receive any metadata sent. Could you tell me the solution about this? Thank you.

@hovanhung98hust
Copy link

Sorry, my mistake, you should call registerMediaMetadataObserver first.

this work for me. Thanks

@hovanhung98hust
Copy link

r registering the ob

i have successfully sentMetadata but still get nothing in metadataReceived in _rtcEngine?.setEventHandler. Can you make me your sample code?
@OverRide
void initState() {
super.initState();
initPlatformState();
}

// Init the app
Future initPlatformState() async {
await [Permission.camera, Permission.microphone].request();

// Create RTC client instance
_rtcEngine = await RtcEngine.create(CallConst.AgoraAppId);
// Define event handling logic

_rtcEngine?.setEventHandler(
  RtcEngineEventHandler(
    joinChannelSuccess: (String channel, int uid, int elapsed) {
      injector<SnackBarBloc>().add(ShowSnackbarEvent(
          type: SnackBarType.success, content: 'joinChannelSuccess: $uid'));
      setState(() {
        _joined = true;
      });
    },
    userJoined: (int uid, int elapsed) {
      injector<SnackBarBloc>().add(ShowSnackbarEvent(
          type: SnackBarType.success, content: 'userJoined: $uid'));
      setState(() {
        _remoteUid = uid;
      });
    },
    metadataReceived: (String data, int uid, int timeStampMs) {
      injector<SnackBarBloc>().add(ShowSnackbarEvent(
        content: '1 - $data | $uid',
        type: SnackBarType.success,
      ));
    },
    streamMessage: (int uid, int streamId, String data) {
      injector<SnackBarBloc>().add(ShowSnackbarEvent(
        content: '2 - $data | $uid',
        type: SnackBarType.success,
      ));
    },
    userOffline: (int uid, UserOfflineReason reason) {
      LOG.d('LogTestLive: userOffline1: ${reason.toString()}');
      LOG.d('LogTestLive: userOffline2: $uid');
      injector<SnackBarBloc>().add(ShowSnackbarEvent(
          type: SnackBarType.success,
          content: 'userOffline: ${reason.toString()}'));
      CommonUtil.copyClipboard('userOffline: $uid', showSnackbar: false);
      setState(() {
        _remoteUid = 0;
      });
    },
  ),
);
// Enable video

await _rtcEngine?.enableVideo();
if (!_isHostLive) {
  await _rtcEngine?.setEnableSpeakerphone(true);
}

await _rtcEngine?.joinChannel(Token, CHANNEL_DEMO_LIVE, null, idUserWatch);
// Set channel profile as livestreaming
await _rtcEngine?.setChannelProfile(ChannelProfile.LiveBroadcasting);
// Set user role as broadcaster
await _rtcEngine?.setClientRole(
    _isHostLive ? ClientRole.Broadcaster : ClientRole.Audience);
await _rtcEngine?.registerMediaMetadataObserver();
await _rtcEngine?.setMaxMetadataSize(1024);

}

void _sendMessageData() async {
try {
  await _rtcEngine?.sendMetadata(_textController.text);
  _textController.text = '';
  injector<SnackBarBloc>().add(ShowSnackbarEvent(
      type: SnackBarType.success, content: '_sendMessageData'));
} catch (e) {
  injector<SnackBarBloc>().add(ShowSnackbarEvent(
      type: SnackBarType.error, content: '_sendMessageData'));
}

}

@Miko2x
Copy link

Miko2x commented Jan 14, 2023

@hovanhung98hust same to me, have you found the solution?
I'm using version 5.3.1 for the agora_rtc_engine.
CC: @littleGnAl

@littleGnAl
Copy link
Contributor

@Miko2x Can you please raise a new issue for your case, thanks.

@github-actions
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please raise a new issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants