Skip to content

Commit 9976ae8

Browse files
committed
Handle handling of duplicate "add" events that were appearing in some platforms, fix some spacing
1 parent 8b9b7f5 commit 9976ae8

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

nw.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@
207207
'src/api/event/event.cc',
208208
'src/api/screen/desktop_capture_api.h',
209209
'src/api/screen/desktop_capture_api.cc',
210-
'src/api/screen/desktop_capture_monitor.cc',
210+
'src/api/screen/desktop_capture_monitor.cc',
211211
'src/api/screen/desktop_capture_monitor.h',
212212
'<(DEPTH)/chrome/browser/media/desktop_media_list.h',
213213
'<(DEPTH)/chrome/browser/media/desktop_media_list_observer.h',

src/api/screen/desktop_capture_monitor.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,28 +98,28 @@ void DesktopCaptureMonitor::OnSourceAdded(int index){
9898
param.AppendString(src.id.ToString());
9999
param.AppendString(src.name);
100100
param.AppendInteger(index);
101-
param.AppendString(type);
101+
param.AppendString(type);
102102
this->dispatcher_host()->SendEvent(this, "__nw_desktop_capture_monitor_listner_added", param);
103103
}
104104
void DesktopCaptureMonitor::OnSourceRemoved(int index){
105105
base::ListValue param;
106-
param.AppendInteger(index); //pass by index here, because the information about which ID was at that index is lost before the removed callback is called. Its saved in the javascript though, so we can look it up there
106+
param.AppendInteger(index); //pass by index here, because the information about which ID was at that index is lost before the removed callback is called. Its saved in the javascript though, so we can look it up there
107107
this->dispatcher_host()->SendEvent(this, "__nw_desktop_capture_monitor_listner_removed", param);
108108
}
109109
void DesktopCaptureMonitor::OnSourceMoved(int old_index, int new_index){
110110
DesktopMediaList::Source src = media_list_->GetSource(new_index);
111111
base::ListValue param;
112112
param.AppendString(src.id.ToString());
113113
param.AppendInteger(new_index);
114-
param.AppendInteger(old_index);
114+
param.AppendInteger(old_index);
115115
this->dispatcher_host()->SendEvent(this, "__nw_desktop_capture_monitor_listner_moved", param);
116116
}
117117
void DesktopCaptureMonitor::OnSourceNameChanged(int index){
118118
DesktopMediaList::Source src = media_list_->GetSource(index);
119119

120120
base::ListValue param;
121121
param.AppendString(src.id.ToString());
122-
param.AppendString(src.name);
122+
param.AppendString(src.name);
123123
this->dispatcher_host()->SendEvent(this, "__nw_desktop_capture_monitor_listner_namechanged", param);
124124
}
125125

src/api/screen/desktop_capture_monitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace nwapi {
3030
DesktopCaptureMonitor(int id,
3131
const base::WeakPtr<DispatcherHost>& dispatcher_host,
3232
const base::DictionaryValue& option);
33-
virtual ~DesktopCaptureMonitor();
33+
virtual ~DesktopCaptureMonitor() override;
3434
virtual void CallSync(const std::string& method, const base::ListValue& arguments, base::ListValue* result) override;
3535
virtual void OnSourceAdded(int index);
3636
virtual void OnSourceRemoved(int index);

src/api/screen/screen.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function DesktopCaptureMonitor() {
2525
}
2626
require('util').inherits(DesktopCaptureMonitor, exports.Base);
2727

28+
2829
DesktopCaptureMonitor.prototype.start = function (screens, windows) {
2930
if (this.started)
3031
return false;
@@ -43,6 +44,11 @@ DesktopCaptureMonitor.prototype.stop = function () {
4344
}
4445

4546
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_added', function (id, name, order, type) {
47+
if(this.sources.indexOf(id)!=-1)
48+
{
49+
//TODO: Find out what this event comes twice on some platforms
50+
return;
51+
}
4652
this.sources.splice(order, 0, id);
4753
this.emit("added", id, name, order, type);
4854
for (var i = order + 1; i <= this.sources.length - 1; i++) {
@@ -51,7 +57,7 @@ DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_added',
5157
});
5258

5359

54-
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_removed', function (index) {
60+
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_removed', function (index) {
5561
var id = this.sources[index];
5662
if (index != -1) {
5763
this.sources.splice(index, 1);
@@ -62,7 +68,7 @@ DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_removed
6268
}
6369
});
6470

65-
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_moved', function (id, new_index, old_index) {
71+
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_moved', function (id, new_index, old_index) {
6672
var temp = this.sources[old_index];
6773
this.sources.splice(old_index, 1);
6874
this.sources.splice(new_index, 0, temp);
@@ -71,14 +77,15 @@ DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_moved',
7177
this.emit("orderchanged", this.sources[i + 1], i + 1, i);
7278
});
7379

74-
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_namechanged', function (id, name) {
80+
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_namechanged', function (id, name) {
7581
this.emit("namechanged", id, name);
7682
});
7783

78-
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_thumbnailchanged', function (id, thumbnail) {
84+
DesktopCaptureMonitor.prototype.on('__nw_desktop_capture_monitor_listner_thumbnailchanged', function (id, thumbnail) {
7985
this.emit("thumbnailchanged", id, thumbnail);
8086
});
8187

88+
var listenerCount=0;
8289
DesktopCaptureMonitor.prototype.on = DesktopCaptureMonitor.prototype.addListener = function (ev, callback) {
8390
//throw except if unsupported event
8491
if (ev != "added" && ev != "removed" && ev != "orderchanged" && ev != "namechanged" && ev != "thumbnailchanged")
@@ -87,6 +94,9 @@ DesktopCaptureMonitor.prototype.on = DesktopCaptureMonitor.prototype.addListener
8794
process.EventEmitter.prototype.addListener.apply(this, arguments);
8895
}
8996

97+
98+
exports.DesktopCaptureMonitor=DesktopCaptureMonitor;
99+
90100
var screenInstance = null;
91101

92102
function Screen() {

0 commit comments

Comments
 (0)