-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JSDK-2353 Adding an example for capturing screen using getDisplayMedi…
…a(). (#71)
- Loading branch information
1 parent
b27dd7c
commit f737dd5
Showing
9 changed files
with
341 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
@import url('https://fonts.googleapis.com/css?family=Roboto+Mono:300'); | ||
|
||
html { | ||
height: 100%; | ||
} | ||
|
||
body { | ||
height: 100%; | ||
} | ||
|
||
div.container-fluid { | ||
height: 100%; | ||
} | ||
|
||
div.row { | ||
height: 100%; | ||
} | ||
|
||
div.row.thin-gutters { | ||
margin: 0 2px 0 2px; | ||
} | ||
|
||
div.row.thin-gutters > .col, | ||
div.row.thin-gutters > [class*="col-"] { | ||
padding: 0 2px; | ||
} | ||
|
||
div.col-sm-8, div.col-sm-4 { | ||
height: 100%; | ||
} | ||
|
||
pre.language-javascript { | ||
font-family: 'Roboto Mono', monospace; | ||
font-size: 13px; | ||
} | ||
|
||
pre.language-javascript a { | ||
color: aquamarine; | ||
text-decoration: underline; | ||
} | ||
|
||
pre.language-javascript a:hover { | ||
text-decoration: none; | ||
} | ||
|
||
div.card { | ||
border: none; | ||
overflow-y: auto; | ||
} | ||
|
||
div.col-sm-8 > .card { | ||
height: 100%; | ||
} | ||
|
||
div.col-sm-4 > .card:first-child { | ||
height: 30%; | ||
} | ||
|
||
div.col-sm-4 > .card:last-child { | ||
height: 70%; | ||
} | ||
|
||
video#screenpreview { | ||
background-color: lightgrey !important; | ||
background-image: url('https://static0.twilio.com/marketing/bundles/archetype/img/logo-wordmark.svg'); | ||
background-position: 50%; | ||
background-repeat: no-repeat; | ||
} | ||
|
||
@media (max-width: 900px) { | ||
div.col-sm-8, div.col-sm-4 { | ||
max-width: 100%; | ||
flex: 100%; | ||
} | ||
|
||
div.col-sm-8 { | ||
height: 40%; | ||
} | ||
|
||
div.col-sm-4 { | ||
height: 60%; | ||
} | ||
|
||
pre.language-javascript { | ||
font-size: 12px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<title>Share Your Screen</title> | ||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous"> | ||
<link rel="stylesheet" href="prism.css"> | ||
<link rel="stylesheet" href="index.css"> | ||
</head> | ||
<body> | ||
<div class="container-fluid"> | ||
<div class="row thin-gutters"> | ||
<div class="col-sm-6"> | ||
<div class="card"> | ||
<div class="card-block"> | ||
<h4 class="card-title"> | ||
Share Your Screen | ||
</h4> | ||
<pre class="language-javascript"></pre> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="col-sm-6"> | ||
<div class="card"> | ||
<div class="card-block"> | ||
<h4 class="card-title">Local Screen</h4> | ||
<video id="screenpreview" autoplay height="480" width="640"></video> | ||
<button id="capturescreen" class="btn btn-primary btn-block">Capture Screen</button> | ||
<button id="stopscreencapture" class="btn btn-primary btn-block">Stop Screen Capture</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<script src="index.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* http://prismjs.com/download.html?themes=prism-okaidia&languages=markup+css+clike+javascript */ | ||
/** | ||
* okaidia theme for JavaScript, CSS and HTML | ||
* Loosely based on Monokai textmate theme by http://www.monokai.nl/ | ||
* @author ocodia | ||
*/ | ||
|
||
code[class*="language-"], | ||
pre[class*="language-"] { | ||
color: #f8f8f2; | ||
background: none; | ||
text-shadow: 0 1px rgba(0, 0, 0, 0.3); | ||
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace; | ||
text-align: left; | ||
white-space: pre; | ||
word-spacing: normal; | ||
word-break: normal; | ||
word-wrap: normal; | ||
line-height: 1.5; | ||
|
||
-moz-tab-size: 4; | ||
-o-tab-size: 4; | ||
tab-size: 4; | ||
|
||
-webkit-hyphens: none; | ||
-moz-hyphens: none; | ||
-ms-hyphens: none; | ||
hyphens: none; | ||
} | ||
|
||
/* Code blocks */ | ||
pre[class*="language-"] { | ||
padding: 1em; | ||
margin: .5em 0; | ||
overflow: auto; | ||
border-radius: 0.3em; | ||
} | ||
|
||
:not(pre) > code[class*="language-"], | ||
pre[class*="language-"] { | ||
background: #272822; | ||
} | ||
|
||
/* Inline code */ | ||
:not(pre) > code[class*="language-"] { | ||
padding: .1em; | ||
border-radius: .3em; | ||
white-space: normal; | ||
} | ||
|
||
.token.comment, | ||
.token.prolog, | ||
.token.doctype, | ||
.token.cdata { | ||
color: #87ceeb; | ||
} | ||
|
||
.token.operator, | ||
.token.punctuation { | ||
color: #ff5555; | ||
} | ||
|
||
.namespace { | ||
opacity: .7; | ||
} | ||
|
||
.token.property, | ||
.token.tag, | ||
.token.constant, | ||
.token.symbol, | ||
.token.deleted { | ||
color: #f92672; | ||
} | ||
|
||
.token.boolean { | ||
color: #55ff55; | ||
} | ||
|
||
.token.number { | ||
color: #cd5c5c; | ||
} | ||
|
||
.token.selector, | ||
.token.attr-name, | ||
.token.string, | ||
.token.char, | ||
.token.builtin, | ||
.token.inserted { | ||
color: #ff55ff; | ||
} | ||
|
||
.token.entity, | ||
.token.url, | ||
.language-css .token.string, | ||
.style .token.string, | ||
.token.variable { | ||
color: #ff55ff; | ||
} | ||
|
||
.token.function { | ||
color: #ccc; | ||
} | ||
|
||
.token.keyword { | ||
color: #55ff55; | ||
} | ||
|
||
.token.regex, | ||
.token.important { | ||
color: #fd971f; | ||
} | ||
|
||
.token.important, | ||
.token.bold { | ||
font-weight: bold; | ||
} | ||
.token.italic { | ||
font-style: italic; | ||
} | ||
|
||
.token.entity { | ||
cursor: help; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict'; | ||
|
||
const Video = require('twilio-video'); | ||
|
||
/** | ||
* Create a LocalVideoTrack for your screen. You can then share it | ||
* with other Participants in the Room. | ||
* @param {number} height - Desired vertical resolution in pixels | ||
* @param {number} width - Desired horizontal resolution in pixels | ||
* @returns {Promise<LocalVideoTrack>} | ||
*/ | ||
function createScreenTrack(height, width) { | ||
if (typeof navigator === 'undefined' | ||
|| !navigator.mediaDevices | ||
|| !navigator.mediaDevices.getDisplayMedia) { | ||
return Promise.reject(new Error('getDisplayMedia is not supported')); | ||
} | ||
return navigator.mediaDevices.getDisplayMedia({ | ||
video: { | ||
height: height, | ||
width: width | ||
} | ||
}).then(function(stream) { | ||
return new Video.LocalVideoTrack(stream.getVideoTracks()[0]); | ||
}); | ||
} | ||
|
||
exports.createScreenTrack = createScreenTrack; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use strict'; | ||
|
||
const Prism = require('prismjs'); | ||
const getSnippet = require('../../util/getsnippet'); | ||
const helpers = require('./helpers'); | ||
const createScreenTrack = helpers.createScreenTrack; | ||
const captureScreen = document.querySelector('button#capturescreen'); | ||
const screenPreview = document.querySelector('video#screenpreview'); | ||
const stopScreenCapture = document.querySelector('button#stopscreencapture'); | ||
|
||
(async function() { | ||
// Load the code snippet. | ||
const snippet = await getSnippet('./helpers.js'); | ||
const pre = document.querySelector('pre.language-javascript'); | ||
pre.innerHTML = Prism.highlight(snippet, Prism.languages.javascript); | ||
|
||
// Hide the "Stop Capture Screen" button. | ||
stopScreenCapture.style.display = 'none'; | ||
|
||
// The LocalVideoTrack for your screen. | ||
let screenTrack; | ||
|
||
captureScreen.onclick = async function() { | ||
try { | ||
// Create and preview your local screen. | ||
screenTrack = await createScreenTrack(720, 1280); | ||
screenTrack.attach(screenPreview); | ||
// Show the "Capture Screen" button after screen capture stops. | ||
screenTrack.on('stopped', toggleButtons); | ||
// Show the "Stop Capture Screen" button. | ||
toggleButtons(); | ||
} catch (e) { | ||
alert(e.message); | ||
} | ||
}; | ||
|
||
stopScreenCapture.onclick = function() { | ||
// Stop capturing your screen. | ||
screenTrack.stop(); | ||
} | ||
}()); | ||
|
||
function toggleButtons() { | ||
captureScreen.style.display = captureScreen.style.display === 'none' ? '' : 'none'; | ||
stopScreenCapture.style.display = stopScreenCapture.style.display === 'none' ? '' : 'none'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f737dd5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how can we specify track name for screensharing?
createLocalTracks({
audio: { name: 'microphone' },
video: { name: 'camera' }
});