Files
chrome-extensions-samples/_archive/mv2/api/tabCapture/receiver.js
Oliver Dunk 5bf419b385 Reorganize directory structure (#825)
* Remove docs folder.

This was a redirect from a GitHub pages site that does not appear
to be in use.

* Rename api folder to api-samples.

* Move examples to functional-samples folder.

* Move cookbook sample to functional-samples.

* Move tutorials to functional-samples folder.

* Move mv2 and apps folders to _archive.

* Rename tools folder to .repo.

* Move reference folder to functional-samples.

* Update README.

Update README with new relative links for reorg.

* Update README.md

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>

---------

Co-authored-by: amysteamdev <37001393+AmySteam@users.noreply.github.com>
2023-02-03 10:58:04 -06:00

50 lines
1.5 KiB
JavaScript

// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Note: |window.currentStream| was set in background.js.
// Stop video play-out, stop the MediaStreamTracks, and set style class to
// "shutdown".
function shutdownReceiver() {
if (!window.currentStream) {
return;
}
var player = document.getElementById('player');
player.srcObject = null;
var tracks = window.currentStream.getTracks();
for (var i = 0; i < tracks.length; ++i) {
tracks[i].stop();
}
window.currentStream = null;
document.body.className = 'shutdown';
}
window.addEventListener('load', function() {
// Start video play-out of the captured audio/video MediaStream once the page
// has loaded.
var player = document.getElementById('player');
player.addEventListener('canplay', function() {
this.volume = 0.75;
this.muted = false;
this.play();
});
player.setAttribute('controls', '1');
player.srcObject = window.currentStream;
// Add onended event listeners. This detects when tab capture was shut down by
// closing the tab being captured.
var tracks = window.currentStream.getTracks();
for (var i = 0; i < tracks.length; ++i) {
tracks[i].addEventListener('ended', function() {
console.log('MediaStreamTrack[' + i + '] ended, shutting down...');
shutdownReceiver();
});
}
});
// Shutdown when the receiver page is closed.
window.addEventListener('beforeunload', shutdownReceiver);