Skip to content
This repository was archived by the owner on Feb 12, 2023. It is now read-only.

Commit ca187a2

Browse files
author
Ke, Mingze
committed
Fixed posting message to unconnected ports
1 parent 92804cb commit ca187a2

File tree

5 files changed

+23
-12
lines changed

5 files changed

+23
-12
lines changed

‎chrome-app/eventPage.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
port = portMap[senderId];
6464

6565
if (!port) {
66+
delete portMap[senderId];
67+
cleanupListener(senderId);
6668
return;
6769
}
6870

@@ -106,11 +108,18 @@
106108
transRes, resolve(objName));
107109

108110
listenerMap[objName].receivers.forEach(function (receiver, idx) {
109-
portMap[receiver.portName].postMessage({
110-
jsonrpc: '2.0',
111-
id: receiver.id,
112-
result: args
113-
});
111+
var rcvPort = receiver.portName;
112+
113+
if (!portMap[rcvPort]) {
114+
delete portMap[rcvPort];
115+
cleanupListener(rcvPort);
116+
} else {
117+
portMap[rcvPort].postMessage({
118+
jsonrpc: '2.0',
119+
id: receiver.id,
120+
result: args
121+
});
122+
}
114123
});
115124
},
116125
receivers: [{

‎chrome-app/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "API Proxy for Google Chrome™",
3-
"version": "0.0.6",
3+
"version": "0.0.7",
44
"manifest_version": 2,
55
"minimum_chrome_version": "23",
66
"app": {

‎chrome-app/serial.html

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@
1818
}
1919

2020
.button {
21-
font-size: 26px;
21+
font-size: 14px;
2222
}
2323
</style>
2424
</head>
2525

2626
<body>
27-
<button class='button' id='refresh'>Refresh</button>
28-
<h1>Serial Port Status</h1>
27+
<h1>Serial Port Status <button class='button' id='refresh'>Refresh</button></h1>
2928
<div id='serial-port-status'></div>
3029
<div>
3130
<input id='disconnId' type='text' size='5' />

‎chrome-app/serial.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
+(function () {
1+
+(function (window, document) {
22

33
'use strict';
44

@@ -21,6 +21,10 @@
2121
});
2222

2323
refreshStatus(node);
24+
25+
window.addEventListener('focus', function () {
26+
refreshStatus(node);
27+
}, false);
2428
}, false);
2529

2630
function refreshStatus(node) {
@@ -43,4 +47,4 @@
4347
return document.getElementById(id);
4448
}
4549

46-
}());
50+
}(window, document));

‎package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"name": "chrome-api-proxy",
3-
"version": "0.0.6",
43
"description": "Leverage Chrome App APIs in Normal Web Pages",
54
"scripts": {
65
"build": "./node_modules/.bin/gulp",

0 commit comments

Comments
 (0)