-
Notifications
You must be signed in to change notification settings - Fork 287
/
Copy pathport.js
35 lines (32 loc) · 1.05 KB
/
port.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
export default Ember.Object.extend(Ember.Evented, {
applicationId: undefined,
detectedApplications: function() {
return [];
}.property(),
init: function() {
var detectedApplications = this.get('detectedApplications');
this.get('adapter').onMessageReceived(function(message) {
if (!message.applicationId) {
return;
}
if (!this.get('applicationId')) {
this.set('applicationId', message.applicationId);
}
// save list of application ids
if (detectedApplications.indexOf(message.applicationId) === -1) {
detectedApplications.pushObject(message.applicationId);
}
var applicationId = this.get('applicationId');
if (applicationId === message.applicationId) {
this.trigger(message.type, message, applicationId);
}
}.bind(this));
},
send: function(type, message) {
message = message || {};
message.type = type;
message.from = 'devtools';
message.applicationId = this.get('applicationId');
this.get('adapter').sendMessage(message);
}
});