1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var backgroundSetup
= {}
7 // If all required activity information is available, then this will return an
8 // activity structure; otherwise, it will return null. This lets us
9 // unconditionally assign to the 'activity' field in a JSON object.
10 tryCreateActivity_ = function(id
, title
, tabId
) {
11 if (id
=== undefined || title
=== undefined || tabId
=== undefined)
21 var receiversActivities
= [];
22 var sendDevices = function() {
23 chrome
.cast
.devicesPrivate
.updateDevices(receiversActivities
);
25 chrome
.cast
.devicesPrivate
.updateDevicesRequested
.addListener(sendDevices
);
27 // Add a new receiver. |activityTitle| and |activityTabId| are optional
29 var addReceiver = function(id
, receiverName
, activityTitle
, activityTabId
) {
30 receiversActivities
.push({
35 'activity': tryCreateActivity_(id
, activityTitle
, activityTabId
)
41 var stopMirroringCalled
= false;
42 chrome
.cast
.devicesPrivate
.stopCast
.addListener(function(reason
) {
43 if (reason
!== 'user-stop')
44 throw 'expected reason to be "user-stop"';
46 var foundActivity
= false;
47 for (item
of receiversActivities
) {
48 if (item
.activity
!= null) {
53 if (foundActivity
=== false)
54 throw 'stopMirroring called when there was nothing being mirrored'
56 stopMirroringCalled
= true;
61 var launchDesktopMirroringReceiverId
= '';
62 chrome
.cast
.devicesPrivate
.startCast
.addListener(function(receiverId
) {
63 launchDesktopMirroringReceiverId
= receiverId
;
65 var tabTitle
= 'Tab Title';
68 for (item
of receiversActivities
) {
69 if (item
.receiver
.id
== receiverId
) {
70 item
.activity
= tryCreateActivity_(receiverId
, tabTitle
, tabId
);