zegoweb 0.0.1
zegoweb: ^0.0.1 copied to clipboard
Unofficial Flutter web plugin wrapping ZEGOCLOUD's Express Video Web SDK (zego-express-engine-webrtc) via dart:js_interop. Not affiliated with or endorsed by ZEGOCLOUD.
zegoweb #
Unofficial community Flutter web plugin wrapping ZEGOCLOUD's
zego-express-engine-webrtc
JavaScript SDK.
Not affiliated with or endorsed by ZEGOCLOUD. This plugin wraps the official
zego-express-engine-webrtcJavaScript SDK and exposes an idiomatic Dart API. For mobile/desktop, use the officialzego_express_engineplugin.
Status #
- Platforms: web only
- Supported Express SDK versions:
^3.0.0(tested against 3.6.x) - API surface: core RTC — engine lifecycle, rooms, local/remote streams, device enumeration, permissions, events. No effects, mixer, CDN, screen share, ZIM chat, or beauty features.
Install #
flutter pub add zegoweb
Loading the JS SDK #
Two options — pick one.
Option A — manual <script> tag (recommended for production) #
Add to web/index.html inside <head>:
<script src="https://unpkg.com/zego-express-engine-webrtc@3.6.0/index.js"></script>
Pin a specific version. Works under strict CSP if you whitelist the CDN.
Option B — dynamic injection #
import 'package:zegoweb/zegoweb.dart';
await ZegoWeb.loadScript(version: '3.6.0');
Idempotent; safe to call multiple times. Good for prototyping.
Minimal usage #
import 'package:zegoweb/zegoweb.dart';
Future<void> joinCall() async {
await ZegoWeb.loadScript();
final engine = await ZegoWeb.createEngine(
ZegoEngineConfig(
appId: 123456789,
server: 'wss://webliveroom-api.zego.im/ws',
scenario: ZegoScenario.communication,
tokenProvider: () async => await fetchTokenFromMyBackend(),
),
);
engine.onError.listen((e) => print('zego error: ${e.code} ${e.message}'));
engine.onRoomStreamUpdate.listen((u) async {
if (u.type == ZegoUpdateType.add) {
for (final s in u.streams) {
await engine.startPlaying(s.streamId);
}
}
});
await engine.loginRoom(
'my-room',
const ZegoUser(userId: 'user-1', userName: 'Alice'),
);
final local = await engine.createLocalStream();
await engine.startPublishing('stream-user-1', local);
// Render with: ZegoVideoView(stream: local)
}
See example/ for a full 1:1 call demo, token generation
patterns, and a real-SDK integration smoke test.
Tokens #
ZegoEngineConfig.tokenProvider is called on login and again on
tokenWillExpire. The plugin handles the refresh loop — you write the fetch
logic once. See example/README.md for three reference
patterns:
- Dev / AppSign mode (empty token)
- Temporary console token, or local
tool/generate_test_token.dart - Serverless function (Supabase Edge or Firebase Callable reference
implementations in
example/)
Permissions #
zegoweb requires a secure context (HTTPS or localhost). createEngine
throws immediately otherwise. engine.checkPermissions() pre-flights
camera/mic permission where the browser exposes the Permissions API; Safari
returns prompt as a safe default.
Testing #
flutter test— pure Dart unitsflutter test --platform chrome— interop tests against a fake JS SDKflutter test integration_test/real_sdk_smoke_test.dart(fromexample/) — gated by--dart-define=ZEGO_APP_ID=...
License #
See LICENSE. Express SDK itself is licensed separately by
ZEGOCLOUD.