Skip to content

Commit

Permalink
Merge branch 'master' into feat/desktop-capture-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc authored Oct 20, 2022
2 parents 420495f + 45be971 commit a92cc75
Show file tree
Hide file tree
Showing 9 changed files with 352 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
java-version: '12.x'
- uses: subosito/flutter-action@v1
with:
flutter-version: '2.0.5'
flutter-version: '3.3.2'
channel: 'stable'
- run: flutter packages get
- run: flutter test
Expand Down

This file was deleted.

17 changes: 0 additions & 17 deletions ios/Runner/GeneratedPluginRegistrant.h

This file was deleted.

33 changes: 0 additions & 33 deletions ios/Runner/GeneratedPluginRegistrant.m

This file was deleted.

8 changes: 4 additions & 4 deletions lib/src/call_sample/call_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class _CallSampleState extends State<CallSample> {
RTCVideoRenderer _remoteRenderer = RTCVideoRenderer();
bool _inCalling = false;
Session? _session;

DesktopCapturerSource? selected_source_;
bool _waitAccept = false;

// ignore: unused_element
Expand All @@ -31,7 +31,7 @@ class _CallSampleState extends State<CallSample> {
initState() {
super.initState();
initRenderers();
_connect();
_connect(context);
}

initRenderers() async {
Expand All @@ -47,8 +47,8 @@ class _CallSampleState extends State<CallSample> {
_remoteRenderer.dispose();
}

void _connect() async {
_signaling ??= Signaling(widget.host)..connect();
void _connect(BuildContext context) async {
_signaling ??= Signaling(widget.host, context)..connect();
_signaling?.onSignalingStateChange = (SignalingState state) {
switch (state) {
case SignalingState.ConnectionClosed:
Expand Down
6 changes: 3 additions & 3 deletions lib/src/call_sample/data_channel_sample.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
@override
initState() {
super.initState();
_connect();
_connect(context);
}

@override
Expand All @@ -39,8 +39,8 @@ class _DataChannelSampleState extends State<DataChannelSample> {
_timer?.cancel();
}

void _connect() async {
_signaling ??= Signaling(widget.host)..connect();
void _connect(BuildContext context) async {
_signaling ??= Signaling(widget.host, context)..connect();

_signaling?.onDataChannelMessage = (_, dc, RTCDataChannelMessage data) {
setState(() {
Expand Down
47 changes: 36 additions & 11 deletions lib/src/call_sample/signaling.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:convert';
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart';

import '../utils/screen_select_dialog.dart';
import 'random_string.dart';

import '../utils/device_info.dart'
Expand Down Expand Up @@ -39,12 +41,13 @@ class Session {
}

class Signaling {
Signaling(this._host);
Signaling(this._host, this._context);

JsonEncoder _encoder = JsonEncoder();
JsonDecoder _decoder = JsonDecoder();
String _selfId = randomNumeric(6);
SimpleWebSocket? _socket;
BuildContext? _context;
var _host;
var _port = 8086;
var _turnCredential;
Expand Down Expand Up @@ -330,7 +333,8 @@ class Signaling {
await _socket?.connect();
}

Future<MediaStream> createStream(String media, bool userScreen) async {
Future<MediaStream> createStream(String media, bool userScreen,
{BuildContext? context}) async {
final Map<String, dynamic> mediaConstraints = {
'audio': userScreen ? false : true,
'video': userScreen
Expand All @@ -346,22 +350,43 @@ class Signaling {
'optional': [],
}
};
late MediaStream stream;
if (userScreen) {
if (WebRTC.platformIsDesktop) {
final source = await showDialog<DesktopCapturerSource>(
context: context!,
builder: (context) => ScreenSelectDialog(),
);
stream = await navigator.mediaDevices.getDisplayMedia(<String, dynamic>{
'video': source == null
? true
: {
'deviceId': {'exact': source.id},
'mandatory': {'frameRate': 30.0}
}
});
} else {
stream = await navigator.mediaDevices.getDisplayMedia(mediaConstraints);
}
} else {
stream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
}

MediaStream stream = userScreen
? await navigator.mediaDevices.getDisplayMedia(mediaConstraints)
: await navigator.mediaDevices.getUserMedia(mediaConstraints);
onLocalStream?.call(stream);
return stream;
}

Future<Session> _createSession(Session? session,
{required String peerId,
required String sessionId,
required String media,
required bool screenSharing}) async {
Future<Session> _createSession(
Session? session, {
required String peerId,
required String sessionId,
required String media,
required bool screenSharing,
}) async {
var newSession = session ?? Session(sid: sessionId, pid: peerId);
if (media != 'data')
_localStream = await createStream(media, screenSharing);
_localStream =
await createStream(media, screenSharing, context: _context);
print(_iceServers);
RTCPeerConnection pc = await createPeerConnection({
..._iceServers,
Expand Down
Loading

0 comments on commit a92cc75

Please sign in to comment.