Skip to content

Add screen share support on both platforms (Android & IOS) #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions Example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,13 @@ const Example = (props) => {
};

const _onShareButtonPressed = () => {
twilioVideo.current.toggleScreenSharing(!isSharing);
setIsSharing(!isSharing);
twilioVideo.current.setScreenShareEnabled(!isScreenShareEnabled);
};

const _onScreenShareChanged = ({screenShareEnabled = false}) => {
setIsScreenShareEnabled(screenShareEnabled);
}

const _onFlipButtonPress = () => {
twilioVideo.current.flipCamera();
};
Expand Down Expand Up @@ -205,7 +208,7 @@ const Example = (props) => {
onPress={_onShareButtonPressed}
>
<Text style={{ fontSize: 12 }}>
{isSharing ? "Stop Sharing" : "Start Sharing"}
{isScreenShareEnabled ? "Stop Screen Sharing" : "Start Screen Sharing"}
</Text>
</TouchableOpacity>
<TwilioVideoLocalView enabled={true} style={styles.localVideo} />
Expand All @@ -217,6 +220,7 @@ const Example = (props) => {
ref={twilioVideo}
onRoomDidConnect={_onRoomDidConnect}
onRoomDidDisconnect={_onRoomDidDisconnect}
onScreenShareChanged={_onScreenShareChanged}
onRoomDidFailToConnect={_onRoomDidFailToConnect}
onParticipantAddedVideoTrack={_onParticipantAddedVideoTrack}
onParticipantRemovedVideoTrack={_onParticipantRemovedVideoTrack}
Expand Down
43 changes: 30 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ import {
Here you can see a complete example of a simple application that uses almost all the apis:

````javascript
import React, { Component, useRef } from 'react';
import React, { useState, useRef } from 'react';
import {
TwilioVideoLocalView,
TwilioVideoParticipantView,
Expand All @@ -221,6 +221,7 @@ import {
const Example = (props) => {
const [isAudioEnabled, setIsAudioEnabled] = useState(true);
const [isVideoEnabled, setIsVideoEnabled] = useState(true);
const [isScreenShareEnabled, setIsScreenShareEnabled] = useState(false);
const [status, setStatus] = useState('disconnected');
const [participants, setParticipants] = useState(new Map());
const [videoTracks, setVideoTracks] = useState(new Map());
Expand All @@ -231,7 +232,7 @@ const Example = (props) => {
twilioRef.current.connect({ accessToken: token });
setStatus('connecting');
}

const _onEndButtonPress = () => {
twilioRef.current.disconnect();
};
Expand All @@ -242,6 +243,14 @@ const Example = (props) => {
.then(isEnabled => setIsAudioEnabled(isEnabled));
};

const _onShareButtonPressed = () => {
twilioRef.current.setScreenShareEnabled(!isScreenShareEnabled);
};

const _onScreenShareChanged = ({screenShareEnabled = false}) => {
setIsScreenShareEnabled(screenShareEnabled);
}

const _onFlipButtonPress = () => {
twilioRef.current.flipCamera();
};
Expand Down Expand Up @@ -310,21 +319,21 @@ const Example = (props) => {
}

{
(status === 'connected' || status === 'connecting') &&
<View style={styles.callContainer}>
(status === 'connected' || status === 'connecting') &&
<View style={styles.callContainer}>
{
status === 'connected' &&
<View style={styles.remoteGrid}>
{
Array.from(videoTracks, ([trackSid, trackIdentifier]) => {
return (
<TwilioVideoParticipantView
style={styles.remoteVideo}
key={trackSid}
trackIdentifier={trackIdentifier}
/>
)
})
return (
<TwilioVideoParticipantView
style={styles.remoteVideo}
key={trackSid}
trackIdentifier={trackIdentifier}
/>
)
})
}
</View>
}
Expand All @@ -345,10 +354,17 @@ const Example = (props) => {
onPress={_onFlipButtonPress}>
<Text style={{fontSize: 12}}>Flip</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.optionButton}
onPress={_onShareButtonPressed}>
<Text style={{ fontSize: 12 }}>
{isScreenShareEnabled ? "Stop Screen Sharing" : "Start Screen Sharing"}
</Text>
</TouchableOpacity>
<TwilioVideoLocalView
enabled={true}
style={styles.localVideo}
/>
/>
</View>
</View>
}
Expand All @@ -357,6 +373,7 @@ const Example = (props) => {
ref={ twilioRef }
onRoomDidConnect={ _onRoomDidConnect }
onRoomDidDisconnect={ _onRoomDidDisconnect }
onScreenShareChanged={ _onScreenShareChanged}
onRoomDidFailToConnect= { _onRoomDidFailToConnect }
onParticipantAddedVideoTrack={ _onParticipantAddedVideoTrack }
onParticipantRemovedVideoTrack= { _onParticipantRemovedVideoTrack }
Expand Down
9 changes: 9 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application>
<service
android:enabled="true"
android:name=".ScreenCapturerService"
android:foregroundServiceType="mediaProjection">
</service>
</application>
</manifest>
Loading