搜索插件、代码仓与 APP 分类

插件详情v1.5.4

ant_media_flutter

适用于 Android、iOS、Web 和桌面端的 Flutter 包,用于使用 Ant Media Server 企业版流媒体引擎

AndroidiOSWeb
近 30 天下载
1300
喜欢数
28
Pub 分数
110

安装插件

flutter pub add ant_media_flutter

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

ant_media_flutter 包可跨 Android、iOS、Web 和桌面平台,使用 Ant Media Server 企业版实现实时流媒体和通信。它提供了一个 Flutter 友好的接口,用于集成基于 WebRTC 的实时音视频流,支持低延迟传输,非常适合交互式应用。该包利用 Ant Media Server 强大的基础设施,提供可扩展、安全且高性能的流媒体解决方案。开发者可以轻松构建直播广播、视频会议和互动媒体应用。完整源代码可在 GitHub 上获取,以确保透明度和可定制性。

适合场景

  • 直播视频广播
  • 视频会议
  • 互动网络研讨会
  • 实时游戏直播
  • 远程教育平台

主要特点

  • 跨平台 WebRTC 支持
  • 低延迟流媒体
  • 安全连接协议
  • 可扩展的服务器集成
  • 轻松集成 Flutter

适合对象

  • 开发实时视频应用的开发者
  • 使用 Ant Media Server 的团队
  • 需要多平台流媒体的项目
  • 需要低延迟通信的应用程序
  • 教育或企业视频解决方案

使用建议

  • 需要 Ant Media Server 企业版
  • 仅限支持的平台(Android、iOS、Web、桌面端)
  • 服务器配置需要完整功能
  • 可能需要额外的网络设置以获得最佳性能
  • 依赖稳定的互联网连接

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Ant Media Server Logo

Pub Star on Github License: GPL3


This Flutter Package includes Ant Media Flutter SDK for WebRTC.

To be able to use it, you need to have an Ant Media Server instance first. To be able to get more information, you can check Ant Media Server's website.

If you have Ant Media Server Community Edition, you can only use WebRTC publishing feature.

WebRTC play, Conference and Data Channel features are available in Ant Media Server Enterprise Edition.


Usage

Lets take a look at how to use AntMediaFlutter

AntMediaFlutter.connect
AntMediaFlutter.connect(
        //host
        'wss://<domain>:<port>/<application_name>/websocket',

        //streamID
        'stream1',

        //roomID
        '',

        //token
        '',

        //type
        AntMediaType.Publish,

        //userScreen
        true,

        //onStateChange
        (HelperState state) {
          switch (state) {
            case HelperState.CallStateNew:
              setState(() {
                _inCalling = true;
              });
              break;
            case HelperState.CallStateBye:
              setState(() {
                _localRenderer.srcObject = null;
                _remoteRenderer.srcObject = null;
                _inCalling = false;
                Navigator.pop(context);
              });
              break;
            case HelperState.ConnectionOpen:
              break;
            case HelperState.ConnectionClosed:
              break;
            case HelperState.ConnectionError:
              break;
          }
        },

        //onLocalStream
        ((stream) {
          setState(() {
            _remoteRenderer.srcObject = stream;
          });
        }),

        //onAddRemoteStream
        ((stream) {
          setState(() {
            _remoteRenderer.srcObject = stream;
          });
        }),

        // onDataChannel
        (datachannel) {
          print(datachannel.id);
          print(datachannel.state);
        },

        // onDataChannelMessage
        (channel, message, isReceived) {
          print("Message Received: ${message.received}");
        },

        // onupdateConferencePerson
        (streams) {},

        //onRemoveRemoteStream
        ((stream) {
          setState(() {
            _remoteRenderer.srcObject = null;
          });
        }),

        //ice servers
        [
          {'url': 'stun:stun.l.google.com:19302'},
        ],

        // callbacks
        (command, mapData) {});

Connect is the main function that we can do pretty much everything with using its parameters. Let's look at its parts and how we can use it for different purposes like WebRTC Publishing, WebRTC Playing, etc.

Sections of the connect function

-> Host

Host is the websocket url of your Ant Media Server instance.

-> Stream ID

Stream ID is used to identify each stream for publishing and playing purposes.

-> Room ID

Room ID is used in the WebRTC Multi track Conference mode.

-> Type

Type is used to determine different modes. Possible options:

  • AntMediaType.Publish
  • AntMediaType.Play
  • AntMediaType.Peer
  • AntMediaType.Conference
  • AntMediaType.DataChannelOnly
-> User Screen

User Screen is used to switch between screen and camera publishing mode during initialization part.

-> On State Change

On State Change is the status of the websocket connection between Ant Media Server and the device which uses the SDK. Possible options:

  • HelperState.CallStateNew
  • HelperState.CallStateBye
  • HelperState.ConnectionOpen
  • HelperState.ConnectionClosed
  • HelperState.ConnectionError
-> On Local Stream

On Local Stream is triggered whenever we started sending stream to the Ant Media Server.

-> On Add Remote Stream

On Add Remote Stream is triggered whenever we receive a new remote stream from the Ant Media Server.

-> On Data Channel

On Data Channel is triggered when the data channel state changed.

-> On Data Channel Message

On Data Channel Message is triggered whenever we receive a new data channel message.

-> On Update Conference Person

On Update Conference Person is triggered whenever someone added/removed from the conference room on the fly.

-> On Remove Remote Stream

On Remove Remote Stream is triggered whenever you stopped publishing yourself or the stream that you are playing stopped publishing.

-> Ice Servers

Ice Servers is the list where you can define your own turn/stun server list.

-> Callbacks

Callbacks you can listen all the callbacks which are sent from the Ant Media Server side.


Gallery


Examples

  • Conference Sample App - An example of how to create a WebRTC Multi track Conference application using Ant Media Server Flutter SDK
  • Data Channel Sample App - An example of how to create a Data Channel text based messaging application using Ant Media Server Flutter SDK
  • Peer Sample App - An example of how to create a Peer to Peer application using Ant Media Server Flutter SDK
  • Play Sample App - An example of how to create a WebRTC Player using Ant Media Server Flutter SDK
  • Publish Sample App - An example of how to create a WebRTC Publish application using Ant Media Server Flutter SDK
  • Sample Project - It's a complete sample project which contains every sample above.

Function List

AntMediaFlutter.anthelper?.switchCamera()

You can call switchCamera() to switch between front and back camera on mobile devices.

AntMediaFlutter.anthelper?.muteMic(bool mute)

You can call muteMic(bool mute) to mute/unmute microphone.

AntMediaFlutter.anthelper?.toggleCam(bool state)

You can call toggleCam(bool state) to open/close your camera.

AntMediaFlutter.anthelper?.disconnectPeer()

You can call disconnectPeer() to stop a peer connection.

AntMediaFlutter.anthelper?.getSender(streamId, type)

You can call getSender(streamId, type) to receive sender tracks.

AntMediaFlutter.anthelper?.setMaxBitrate(streamId, type, maxBitrateKbps)

You can call setMaxBitrate(streamId, type, maxBitrateKbps) to limit maximum bitrate for audio or video type.

AntMediaFlutter.anthelper?.createStream(media, userScreen)

You can call registerPushNotificationToken(subscriberId, authToken, pushNotificationToken, tokenType) to register user push notification token to Ant Media Server.

AntMediaFlutter.anthelper?.registerPushNotificationToken(subscriberId, authToken, pushNotificationToken, tokenType)

You can call sendPushNotification(subscriberId, authToken, pushNotificationContent, subscriberIdsToNotify) to send push notification to subscribers.

AntMediaFlutter.anthelper?.sendPushNotification(subscriberId, authToken, pushNotificationContent, subscriberIdsToNotify)

You can call createStream(media, userScreen) to create a local stream using camera or display.

AntMediaFlutter.anthelper?.setStream(MediaStream? media)

You can call setStream(MediaStream? media) to set local stream.

AntMediaFlutter.anthelper?.startStreamingAntMedia(streamId, token)

You can call startStreamingAntMedia(streamId, token) to start publishing.

AntMediaFlutter.anthelper?.forceStreamQuality(streamId, resolution)

You can call forceStreamQuality(streamId, resolution) to force stream into a specific quality.

AntMediaFlutter.anthelper?.join(streamId)

You can call join(streamId) to join into a conference room as player.

AntMediaFlutter.anthelper?.joinroom(streamId)

You can call joinroom(streamId) to join into a conference room as participant.

AntMediaFlutter.anthelper?.sendMessage(RTCDataChannelMessage message)

You can call sendMessage(RTCDataChannelMessage message) to send a text message using the WebRTC data channel.

AntMediaFlutter.anthelper?.getStreamInfo(streamId)

You can call getStreamInfo(streamId) to receive information about a specific stream.

AntMediaFlutter.anthelper?.closePeerConnection(streamId)

You can call closePeerConnection(streamId) to close peer connection.

AntMediaFlutter.anthelper?.bye()

You can call bye() to stop publishing.

AntMediaFlutter.anthelper?.close()

You can call close() to dispose local stream and close peer and websocket connections.


Integration

In order to integrate Flutter SDK to your project, please follow this link.


Support

Have any questions about the Flutter SDK? Visit our community platform.


Issues

Create issues on the Ant-Media-Server


Dart Versions

  • Dart 2: >= 2.12

所属分类

依赖

依赖清单 10 项

源码仓库

使用此插件的项目

暂无相关数据。