Skip to main content

zego_express_engine 3.23.0-private.595 copy "zego_express_engine: ^3.23.0-private.595" to clipboard
zego_express_engine: ^3.23.0-private.595 copied to clipboard

ZegoExpressEngine Flutter SDK is a flutter plugin wrapper based on ZEGO Express RTC SDK (Native & Web), providing live video and real-time audio/video services.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:zego_express_engine/zego_express_engine.dart';
import 'package:zego_express_engine_example/home/home_page.dart';
import 'package:zego_express_engine_example/topics/audio_effect_player/audio_effect_player_autotest.dart';
import 'package:zego_express_engine_example/topics/autotest_reporter.dart';
import 'package:zego_express_engine_example/topics/ktv/ktv_autotest.dart';
import 'package:zego_express_engine_example/topics/mixer/mixer_autotest.dart';
import 'package:zego_express_engine_example/topics/mixer/mixer_render_page.dart';
import 'package:zego_express_engine_example/topics/utility/utility_autotest.dart';
import 'package:zego_express_engine_example/utils/zego_config.dart';

// This is a simple publish & play stream demo,
// shows the basic function of the SDK.

// You can refer to this example topic demo for more use cases.
// https://github.com/zegoim/zego-express-example-topics-flutter

/// Device-side automation switch.
///
///   flutter build hap --debug \
///     --dart-define=MIXER_AUTOTEST=true \
///     --dart-define=ZEGO_APP_ID=<appID> \
///     --dart-define=ZEGO_APP_SIGN=<appSign>
///
/// When enabled, the app boots, creates the engine with the injected
/// credentials, runs the mixer / media player / network time / KTV cases, and
/// prints `ZMX_TEST|...` markers to hilog. See tool/run_mixer_autotest.sh.
const bool kMixerAutoTest = bool.fromEnvironment('AUTOTEST') ||
    bool.fromEnvironment('MIXER_AUTOTEST');

/// Audio effect player suite switch (independent from the mixer/KTV suites):
///
///   flutter build hap --debug \
///     --dart-define=AUDIO_EFFECT_AUTOTEST=true \
///     --dart-define=ZEGO_APP_ID=<appID> \
///     --dart-define=ZEGO_APP_SIGN=<appSign>
///
/// Runs the pre-engine boundary case, then the audio effect player API and
/// callback cases. See tool/run_audio_effect_autotest.sh.
const bool kAudioEffectAutoTest = bool.fromEnvironment('AUDIO_EFFECT_AUTOTEST');

const bool kAutoTest = kMixerAutoTest || kAudioEffectAutoTest;

/// Opens the mixer render page as home: --dart-define=MIXER_RENDER=true
const bool kMixerRender = bool.fromEnvironment('MIXER_RENDER');

const int kAutoTestAppID = int.fromEnvironment('ZEGO_APP_ID');
const String kAutoTestAppSign = String.fromEnvironment('ZEGO_APP_SIGN');
const String kAutoTestMainStream = String.fromEnvironment(
    'MIXER_INPUT_STREAM',
    defaultValue: 'mixer-autotest-in-1');
const String kAutoTestAuxStream =
    String.fromEnvironment('MIXER_AUX_STREAM', defaultValue: 'mixer-autotest-in-2');
const String kAutoTestRoomID =
    String.fromEnvironment('MIXER_ROOM_ID', defaultValue: 'mixer-autotest-room');
const bool kAutoTestPublish =
    bool.fromEnvironment('MIXER_PUBLISH', defaultValue: true);
const String kAutoTestOutputTarget = String.fromEnvironment(
    'MIXER_OUTPUT_TARGET',
    defaultValue: 'mixer-autotest-out');
const String kKtvRoomID =
    String.fromEnvironment('KTV_ROOM_ID', defaultValue: 'ktv-autotest-room');
const String kKtvStreamID =
    String.fromEnvironment('KTV_STREAM_ID', defaultValue: 'ktv-autotest-stream');
const String kKtvOutputTarget = String.fromEnvironment(
    'KTV_OUTPUT_TARGET',
    defaultValue: 'ktv-autotest-mix-out');

void main() {
  WidgetsFlutterBinding.ensureInitialized();

  // Credentials injected at build time also apply to the manual test pages
  // (KTV Test / Mixer Test / Quick Start), so the whole flow can be exercised
  // on device without typing AppID / AppSign into the setting page first:
  //   flutter build hap --debug \
  //     --dart-define=ZEGO_APP_ID=<appID> \
  //     --dart-define=ZEGO_APP_SIGN=<appSign>
  // The setting page still overrides them at runtime.
  if (kAutoTestAppID > 0 && ZegoConfig.instance.appID <= 0) {
    ZegoConfig.instance.appID = kAutoTestAppID;
  }
  if (kAutoTestAppSign.isNotEmpty && ZegoConfig.instance.appSign.isEmpty) {
    ZegoConfig.instance.appSign = kAutoTestAppSign;
  }
  if (ZegoConfig.instance.userID.isEmpty) {
    const String injectedUserID =
        String.fromEnvironment('ZEGO_USER_ID', defaultValue: 'ohos_ktv_user');
    ZegoConfig.instance.userID = injectedUserID;
    ZegoConfig.instance.userName = injectedUserID;
  }

  // Allow credentials injection for the automated / render modes
  if (kAutoTestAppID > 0) {
    ZegoConfig.instance.appID = kAutoTestAppID;
    ZegoConfig.instance.appSign = kAutoTestAppSign;
    ZegoConfig.instance.userID = 'ohos_autotest';
  }

  runApp(MyApp());

  if (kAutoTest) {
    _runAutoTest();
  }
}

Future<void> _runAutoTest() async {
  print('ZMX_TEST|START|prepare');

  if (kAutoTestAppID <= 0) {
    print('ZMX_TEST|FAIL|prepare|missing --dart-define=ZEGO_APP_ID');
    print('ZMX_TEST|DONE|passed=0|failed=1');
    return;
  }

  ZegoConfig.instance.appID = kAutoTestAppID;
  ZegoConfig.instance.appSign = kAutoTestAppSign;
  ZegoConfig.instance.userID = 'ohos_autotest';

  AutoTestReporter.reset();

  // Boundary case that must run before the engine exists.
  if (kAudioEffectAutoTest) {
    await AudioEffectPlayerAutoTest.runPreEngine();
  }

  ZegoEngineProfile profile = ZegoEngineProfile(
      ZegoConfig.instance.appID, ZegoConfig.instance.scenario,
      appSign: ZegoConfig.instance.appSign);
  ZegoExpressEngine.createEngineWithProfile(profile);
  print('ZMX_TEST|PASS|prepare|engineCreated,appID=${ZegoConfig.instance.appID}');

  // Give the native engine time to initialize before calling the APIs
  await Future.delayed(const Duration(seconds: 2));

  if (kAudioEffectAutoTest) {
    // Audio effect player APIs + onAudioEffectPlayStateUpdate callback routing
    await AudioEffectPlayerAutoTest.run();
  }

  if (kMixerAutoTest) {
    // Non-mixer APIs first (they only need the engine)
    await UtilityAutoTest.run();

    // Mixer task suite (logs in and publishes its own input streams)
    await MixerAutoTest.run(
        roomID: kAutoTestRoomID,
        inputMainStreamID: kAutoTestMainStream,
        inputAuxStreamID: kAutoTestAuxStream,
        outputTarget: kAutoTestOutputTarget,
        publishInputs: kAutoTestPublish);

    // KTV regressions from meego 7179454705: SEI round-trip, sendSEI
    // marshalling, setAudioSource error code, mixer sound level int keys
    await KtvAutoTest.run(
        roomID: kKtvRoomID,
        streamID: kKtvStreamID,
        outputTarget: kKtvOutputTarget,
        publishInputs: kAutoTestPublish);
  }

  AutoTestReporter.done();

  ZegoExpressEngine.destroyEngine();
  print('ZMX_TEST|FINISHED');
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'ZegoExpressExample',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: kMixerRender ? MixerRenderPage() : HomePage(),
    );
  }
}
59
likes
0
points
13.9k
downloads

Publisher

verified publisherzego.im

Weekly Downloads

ZegoExpressEngine Flutter SDK is a flutter plugin wrapper based on ZEGO Express RTC SDK (Native & Web), providing live video and real-time audio/video services.

Homepage

License

unknown (license)

Dependencies

flutter, flutter_web_plugins, js

More

Packages that depend on zego_express_engine

Packages that implement zego_express_engine