From 2927a53d9ad3d7cba61e3642fa789de0dd9a2542 Mon Sep 17 00:00:00 2001 From: Harsh Patel Date: Wed, 19 May 2021 13:51:18 +0530 Subject: [PATCH] - Updated flutter version and null safety --- lib/flutter_live.dart | 38 +++++++++++++++++++------------------- pubspec.yaml | 8 ++++++-- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/lib/flutter_live.dart b/lib/flutter_live.dart index 6cd7607..18f52a6 100644 --- a/lib/flutter_live.dart +++ b/lib/flutter_live.dart @@ -110,9 +110,9 @@ class RealtimePlayer { /// streamUrl: "webrtc://d.ossrs.net:11985/live/livestream" class WebRTCUri { /// The api server url for WebRTC streaming. - String api; + String? api; /// The stream url to play or publish. - String streamUrl; + String? streamUrl; /// Parse the url to WebRTC uri. static WebRTCUri parse(String url) { @@ -120,7 +120,7 @@ class WebRTCUri { var schema = 'https'; // For native, default to HTTPS if (uri.queryParameters.containsKey('schema')) { - schema = uri.queryParameters['schema']; + schema = uri.queryParameters['schema']!; } else { schema = 'https'; } @@ -134,7 +134,7 @@ class WebRTCUri { var api = '/rtc/v1/play/'; if (uri.queryParameters.containsKey('play')) { - api = uri.queryParameters['play']; + api = uri.queryParameters['play']!; } var apiParams = []; @@ -159,8 +159,8 @@ class WebRTCUri { /// A WebRTC player, using [flutter_webrtc](https://pub.dev/packages/flutter_webrtc) class WebRTCPlayer { - webrtc.AddStreamCallback _onRemoteStream; - webrtc.RTCPeerConnection _pc; + webrtc.AddStreamCallback? _onRemoteStream; + webrtc.RTCPeerConnection? _pc; /// When got a remote stream. set onRemoteStream(webrtc.AddStreamCallback v) { @@ -175,7 +175,7 @@ class WebRTCPlayer { /// [url] must a path parsed by [WebRTCUri.parse] in https://github.com/rtcdn/rtcdn-draft Future play(String url) async { if (_pc != null) { - await _pc.close(); + await _pc!.close(); } // Create the peer connection. @@ -187,36 +187,36 @@ class WebRTCPlayer { print('WebRTC: createPeerConnection done'); // Setup the peer connection. - _pc.onAddStream = (webrtc.MediaStream stream) { + _pc!.onAddStream = (webrtc.MediaStream stream) { print('WebRTC: got stream ${stream.id}'); if (_onRemoteStream == null) { print('Warning: Stream ${stream.id} is leak'); return; } - _onRemoteStream(stream); + _onRemoteStream!(stream); }; - _pc.addTransceiver( + _pc!.addTransceiver( kind: webrtc.RTCRtpMediaType.RTCRtpMediaTypeAudio, init: webrtc.RTCRtpTransceiverInit(direction: webrtc.TransceiverDirection.RecvOnly), ); - _pc.addTransceiver( + _pc!.addTransceiver( kind: webrtc.RTCRtpMediaType.RTCRtpMediaTypeVideo, init: webrtc.RTCRtpTransceiverInit(direction: webrtc.TransceiverDirection.RecvOnly), ); print('WebRTC: Setup PC done, A|V RecvOnly'); // Start SDP handshake. - webrtc.RTCSessionDescription offer = await _pc.createOffer({ + webrtc.RTCSessionDescription offer = await _pc!.createOffer({ 'mandatory': {'OfferToReceiveAudio': true, 'OfferToReceiveVideo': true}, }); - await _pc.setLocalDescription(offer); - print('WebRTC: createOffer, ${offer.type} is ${offer.sdp.replaceAll('\n', '\\n').replaceAll('\r', '\\r')}'); + await _pc!.setLocalDescription(offer); + print('WebRTC: createOffer, ${offer.type} is ${offer.sdp!.replaceAll('\n', '\\n').replaceAll('\r', '\\r')}'); - webrtc.RTCSessionDescription answer = await _handshake(url, offer.sdp); - print('WebRTC: got ${answer.type} is ${answer.sdp.replaceAll('\n', '\\n').replaceAll('\r', '\\r')}'); + webrtc.RTCSessionDescription answer = await _handshake(url, offer.sdp!); + print('WebRTC: got ${answer.type} is ${answer.sdp!.replaceAll('\n', '\\n').replaceAll('\r', '\\r')}'); - await _pc.setRemoteDescription(answer); + await _pc!.setRemoteDescription(answer); } /// Handshake to exchange SDP, send offer and got answer. @@ -238,7 +238,7 @@ class WebRTCPlayer { // {api: "xxx", sdp: "offer", streamurl: "webrtc://d.ossrs.net:11985/live/livestream"} // Response: // {code: 0, sdp: "answer", sessionid: "007r51l7:X2Lv"} - HttpClientRequest req = await client.postUrl(Uri.parse(uri.api)); + HttpClientRequest req = await client.postUrl(Uri.parse(uri.api!)); req.headers.set('Content-Type', 'application/json'); req.add(utf8.encode(json.encode({'api': uri.api, 'streamurl': uri.streamUrl, 'sdp': offer}))); print('WebRTC request: ${uri.api} offer=${offer.length}B'); @@ -261,7 +261,7 @@ class WebRTCPlayer { /// Dispose the player. void dispose() { if (_pc != null) { - _pc.close(); + _pc!.close(); } } } diff --git a/pubspec.yaml b/pubspec.yaml index a872e2f..c80f916 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -4,7 +4,7 @@ description: Live streaming player, iOS+Android, RTMP/HTTP-FLV/HLS/WebRTC, by Fl homepage: https://github.com/ossrs/flutter_live environment: - sdk: ">=2.7.0 <3.0.0" + sdk: ">=2.12.0 <3.0.0" flutter: ">=1.20.0 <2.0.0" dependencies: @@ -12,7 +12,11 @@ dependencies: sdk: flutter fijkplayer: ^0.8.8 flutter_webrtc: ^0.6.3 - camera_with_rtmp: ^0.3.2 + camera_with_rtmp: + git: + url: https://github.com/babulpatel1309/flutter_rtmppublisher.git + ref: 963c0b82cd94f09f1e4387d33a89e3b067957c19 + dev_dependencies: flutter_test: