Skip to content

Commit bde6dc8

Browse files
committed
Update samples.
1 parent cf11a8f commit bde6dc8

File tree

5 files changed

+65
-20
lines changed

5 files changed

+65
-20
lines changed

android/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ android {
3434
defaultConfig {
3535
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
3636
applicationId "com.cloudwebrtc.flutterwebrtcdemo"
37-
minSdkVersion 17
37+
minSdkVersion 18
3838
targetSdkVersion 27
3939
versionCode flutterVersionCode.toInteger()
4040
versionName flutterVersionName

lib/src/call_sample/call_sample.dart

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ class _CallSampleState extends State<CallSample> {
9898
}
9999
}
100100

101-
_invitePeer(context, peerId) async {
101+
_invitePeer(context, peerId, use_screen) async {
102102
if (_signaling != null && peerId != _selfId) {
103-
_signaling.invite(peerId, 'video');
103+
_signaling.invite(peerId, 'video', use_screen);
104104
}
105105
}
106106

@@ -110,15 +110,38 @@ class _CallSampleState extends State<CallSample> {
110110
}
111111
}
112112

113+
_switchCamera() {
114+
_signaling.switchCamera();
115+
}
116+
117+
_muteMic() {
118+
119+
}
120+
113121
_buildRow(context, peer) {
114122
var self = (peer['id'] == _selfId);
115123
return ListBody(children: <Widget>[
116124
ListTile(
117125
title: Text(self
118126
? peer['name'] + '[Your self]'
119127
: peer['name'] + '[' + peer['user_agent'] + ']'),
120-
onTap: () => _invitePeer(context, peer['id']),
121-
trailing: Icon(Icons.videocam),
128+
onTap: null,
129+
trailing: new SizedBox(
130+
width: 100.0,
131+
child: new Row(
132+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
133+
children: <Widget>[
134+
IconButton(
135+
icon: const Icon(Icons.videocam),
136+
onPressed: () => _invitePeer(context, peer['id'], false),
137+
tooltip: 'Video calling',
138+
),
139+
IconButton(
140+
icon: const Icon(Icons.screen_share),
141+
onPressed: () => _invitePeer(context, peer['id'], true),
142+
tooltip: 'Screen sharing',
143+
)
144+
])),
122145
subtitle: Text('id: ' + peer['id']),
123146
),
124147
Divider()
@@ -138,13 +161,28 @@ class _CallSampleState extends State<CallSample> {
138161
),
139162
],
140163
),
164+
floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
141165
floatingActionButton: _inCalling
142-
? FloatingActionButton(
143-
onPressed: _hangUp,
144-
tooltip: 'Hangup',
145-
child: new Icon(Icons.call_end),
146-
)
147-
: null,
166+
? new SizedBox(
167+
width: 200.0,
168+
child: new Row(
169+
mainAxisAlignment: MainAxisAlignment.spaceBetween,
170+
children: <Widget>[
171+
FloatingActionButton(
172+
child: const Icon(Icons.switch_camera),
173+
onPressed: _switchCamera,
174+
),
175+
FloatingActionButton(
176+
onPressed: _hangUp,
177+
tooltip: 'Hangup',
178+
child: new Icon(Icons.call_end),
179+
backgroundColor: Colors.pink,
180+
),
181+
FloatingActionButton(
182+
child: const Icon(Icons.mic_off),
183+
onPressed: _muteMic,
184+
)
185+
])) : null,
148186
body: _inCalling
149187
? OrientationBuilder(builder: (context, orientation) {
150188
return new Container(

lib/src/call_sample/data_channel_sample.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class _DataChannelSampleState extends State<DataChannelSample> {
108108

109109
_invitePeer(context, peerId) async {
110110
if (_signaling != null && peerId != _selfId) {
111-
_signaling.invite(peerId, 'data');
111+
_signaling.invite(peerId, 'data', false);
112112
}
113113
}
114114

lib/src/call_sample/signaling.dart

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,20 @@ class Signaling {
9393
if (_socket != null) _socket.close();
9494
}
9595

96-
void invite(String peer_id, String media) {
96+
void switchCamera(){
97+
if(_localStream != null){
98+
_localStream.getVideoTracks()[0].switchCamera();
99+
}
100+
}
101+
102+
void invite(String peer_id, String media, use_screen) {
97103
this._sessionId = this._selfId + '-' + peer_id;
98104

99105
if (this.onStateChange != null) {
100106
this.onStateChange(SignalingState.CallStateNew);
101107
}
102108

103-
_createPeerConnection(peer_id, media).then((pc) {
109+
_createPeerConnection(peer_id, media, use_screen).then((pc) {
104110
_peerConnections[peer_id] = pc;
105111
if (media == 'data') {
106112
_createDataChannel(peer_id, pc);
@@ -144,7 +150,7 @@ class Signaling {
144150
this.onStateChange(SignalingState.CallStateNew);
145151
}
146152

147-
_createPeerConnection(id, media).then((pc) {
153+
_createPeerConnection(id, media, false).then((pc) {
148154
_peerConnections[id] = pc;
149155
pc.setRemoteDescription(new RTCSessionDescription(
150156
description['sdp'], description['type']));
@@ -266,7 +272,7 @@ class Signaling {
266272
}
267273
}
268274

269-
Future<MediaStream> createStream() async {
275+
Future<MediaStream> createStream(media, user_screen) async {
270276
final Map<String, dynamic> mediaConstraints = {
271277
'audio': true,
272278
'video': {
@@ -281,15 +287,15 @@ class Signaling {
281287
}
282288
};
283289

284-
MediaStream stream = await navigator.getUserMedia(mediaConstraints);
290+
MediaStream stream = user_screen? await navigator.getDisplayMedia(mediaConstraints) : await navigator.getUserMedia(mediaConstraints);
285291
if (this.onLocalStream != null) {
286292
this.onLocalStream(stream);
287293
}
288294
return stream;
289295
}
290296

291-
_createPeerConnection(id, media) async {
292-
if (media != 'data') _localStream = await createStream();
297+
_createPeerConnection(id, media, user_screen) async {
298+
if (media != 'data') _localStream = await createStream(media, user_screen);
293299
RTCPeerConnection pc = await createPeerConnection(_iceServers, _config);
294300
if (media != 'data') pc.addStream(_localStream);
295301
pc.onIceCandidate = (candidate) {

pubspec.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ dependencies:
1919
# The following adds the Cupertino Icons font to your application.
2020
# Use with the CupertinoIcons class for iOS style icons.
2121
cupertino_icons: ^0.1.2
22-
flutter_webrtc: ^0.0.3
22+
flutter_webrtc: 0.1.0
2323
shared_preferences:
24+
2425
dev_dependencies:
2526
flutter_test:
2627
sdk: flutter

0 commit comments

Comments
 (0)