Skip to content

Commit d7facbc

Browse files
committed
update simulator
1 parent 8843297 commit d7facbc

377 files changed

Lines changed: 85189 additions & 838 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

components/simulator/.bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
"i18next-xhr-backend": "^1.3.0",
2424
"jquery-i18next": "^1.2.0",
2525
"bootstrap-select": "^1.12.1",
26-
"defiant": "defiant-js#^1.4.0"
26+
"defiant": "defiant-js#^1.4.0",
27+
"webduino-js": "dist"
2728
},
28-
"_release": "662d9dda6f",
29+
"_release": "43a3239365",
2930
"_resolution": {
3031
"type": "branch",
3132
"branch": "blockly",
32-
"commit": "662d9dda6fabacf1d30438c6a00805701605c6c3"
33+
"commit": "43a32393651ebdcbff0b33bc99d4cdb234573793"
3334
},
3435
"_source": "https://git.kingkit.codes/webduino/simulator.git",
3536
"_target": "blockly",

components/simulator/bower.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"i18next-xhr-backend": "^1.3.0",
2424
"jquery-i18next": "^1.2.0",
2525
"bootstrap-select": "^1.12.1",
26-
"defiant": "defiant-js#^1.4.0"
26+
"defiant": "defiant-js#^1.4.0",
27+
"webduino-js": "dist"
2728
}
2829
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 webduino.io. All rights reserved.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# API Proxy for Google Chrome™
2+
3+
Leverage Chrome App APIs in Normal Web Pages
4+
5+
## Installation
6+
7+
1. Install the "API Proxy for Google Chrome™" app. Launch the app whenever you want to use the APIs.
8+
2. Install the "API Proxy Agent for Google Chrome™" extension.
9+
10+
## Usage
11+
12+
Insert
13+
14+
```
15+
<script src="http://webduinoio.github.io/chrome-api-proxy/lib/chrome._api.js"></script>
16+
<script src="http://webduinoio.github.io/chrome-api-proxy/lib/chrome.{API_USED}.js"></script>
17+
```
18+
19+
in your normal web pages.
20+
21+
Now you can use the chrome-app apis even not in chrome-apps.
22+
23+
## Disclaimer
24+
25+
Google Chrome™ is a trademark of Google Inc. Use of this trademark is subject to Google Permissions.
26+
27+
## Contribute
28+
29+
Extending the apis is easy. Any contribution or suggestion is welcome.
30+
31+
## Wiki
32+
33+
- [繁體中文 ( Traditional Chinese )](https://github.com/webduinoio/chrome-api-proxy/wiki/Chinese-(-Traditional-))
34+
35+
## [License](LICENSE)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "chrome-api-proxy",
3+
"description": "Leverage Chrome App APIs in Normal Web Pages",
4+
"license": "MIT",
5+
"dependencies": {
6+
"json-human": "*"
7+
}
8+
}
20.5 KB
Loading
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
+(function (scope) {
2+
3+
'use strict';
4+
5+
var slice = Array.prototype.slice,
6+
undef = undefined,
7+
transReq = scope.transforms.request,
8+
transRes = scope.transforms.response,
9+
listenerMap = {},
10+
portMap = {},
11+
objCache = {};
12+
13+
chrome.app.runtime.onLaunched.addListener(function () {
14+
15+
chrome.app.window.create('status.html', {
16+
id: "status",
17+
innerBounds: {
18+
width: 480,
19+
height: 640,
20+
minWidth: 480,
21+
maxWidth: 480,
22+
minHeight: 640,
23+
maxHeight: 640
24+
}
25+
});
26+
27+
chrome.runtime.onConnectExternal.addListener(function (port) {
28+
if (!port.name) {
29+
return;
30+
}
31+
32+
portMap[port.name] = port;
33+
34+
port.onMessage.addListener(function (msg) {
35+
if (msg.method) {
36+
invoke(port.name, msg.id, msg.method, msg.params);
37+
}
38+
});
39+
40+
port.onDisconnect.addListener(function (port) {
41+
delete portMap[port.name];
42+
cleanupListener(port.name);
43+
});
44+
});
45+
46+
});
47+
48+
function invoke(senderId, id, method, params) {
49+
var m = normalize(method),
50+
obj = resolve(m),
51+
ctx = resolve(m.split('.').slice(0, -1).join('.'));
52+
53+
if (m.indexOf('.addListener') === m.length - 12) {
54+
addListener(m.substr(0, m.length - 12), senderId, id);
55+
} else if (m.indexOf('.removeListener') === m.length - 15) {
56+
removeListener(m.substr(0, m.length - 15), senderId, id);
57+
} else {
58+
if (typeof obj === 'function') {
59+
params = transformParams(m, params, transReq, ctx);
60+
try {
61+
obj.apply(ctx, params.concat(callback));
62+
} catch (e) {
63+
portMap[senderId].postMessage({
64+
jsonrpc: '2.0',
65+
id: id,
66+
exception: e.message
67+
});
68+
}
69+
}
70+
71+
function callback() {
72+
var args = slice.call(arguments),
73+
port = portMap[senderId];
74+
75+
if (!port) {
76+
delete portMap[senderId];
77+
cleanupListener(senderId);
78+
return;
79+
}
80+
81+
if (chrome.runtime.lastError) {
82+
port.postMessage({
83+
jsonrpc: '2.0',
84+
id: id,
85+
error: chrome.runtime.lastError.message
86+
});
87+
} else {
88+
args = transformParams(m, args, transRes, ctx);
89+
port.postMessage({
90+
jsonrpc: '2.0',
91+
id: id,
92+
result: args
93+
});
94+
}
95+
}
96+
}
97+
}
98+
99+
function transformParams(name, params, map, ctx) {
100+
var func = map[name];
101+
102+
if (typeof func === 'function') {
103+
return func.apply(ctx, params);
104+
}
105+
return params;
106+
}
107+
108+
function addListener(objName, portName, id) {
109+
if (listenerMap[objName]) {
110+
listenerMap[objName].receivers.push({
111+
portName: portName,
112+
id: id
113+
});
114+
} else {
115+
listenerMap[objName] = {
116+
listener: function () {
117+
var args = transformParams(objName + '.addListener', slice.call(arguments),
118+
transRes, resolve(objName));
119+
120+
listenerMap[objName].receivers.forEach(function (receiver, idx) {
121+
var rcvPort = receiver.portName;
122+
123+
if (!portMap[rcvPort]) {
124+
delete portMap[rcvPort];
125+
cleanupListener(rcvPort);
126+
} else {
127+
portMap[rcvPort].postMessage({
128+
jsonrpc: '2.0',
129+
id: receiver.id,
130+
result: args
131+
});
132+
}
133+
});
134+
},
135+
receivers: [{
136+
portName: portName,
137+
id: id
138+
}]
139+
};
140+
resolve(objName).addListener(listenerMap[objName].listener);
141+
}
142+
}
143+
144+
function removeListener(objName, portName, id) {
145+
if (listenerMap[objName]) {
146+
if (typeof id === 'undefined') {
147+
listenerMap[objName].receivers = listenerMap[objName].receivers.filter(function (receiver) {
148+
return receiver.portName !== portName;
149+
});
150+
} else {
151+
listenerMap[objName].receivers.some(function (receiver, idx) {
152+
if (receiver.portName === portName && receiver.id === id) {
153+
listenerMap[objName].receivers.splice(idx, 1);
154+
return true;
155+
}
156+
});
157+
}
158+
if (listenerMap[objName].receivers.length === 0) {
159+
resolve(objName).removeListener(listenerMap[objName].listener);
160+
delete listenerMap[objName];
161+
}
162+
}
163+
}
164+
165+
function cleanupListener(portName) {
166+
Object.keys(listenerMap).forEach(function (objName) {
167+
removeListener(objName, portName);
168+
});
169+
}
170+
171+
function normalize(method) {
172+
return (method.indexOf('window.') === 0) ? method.substring(7) : method;
173+
}
174+
175+
function resolve(name) {
176+
var tmpName = '';
177+
178+
return (objCache[name]) ||
179+
name.split('.').reduce(function (obj, prop) {
180+
tmpName += ((tmpName ? '.' : '') + prop);
181+
if (obj && obj[prop]) {
182+
objCache[tmpName] = obj[prop];
183+
return obj[prop];
184+
} else {
185+
return undef;
186+
}
187+
}, scope);
188+
}
189+
190+
}(window));
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"name": "API Proxy for Google Chrome™",
3+
"version": "0.0.11",
4+
"manifest_version": 2,
5+
"minimum_chrome_version": "23",
6+
"app": {
7+
"background": {
8+
"scripts": [
9+
"transforms.js",
10+
"eventPage.js"
11+
]
12+
}
13+
},
14+
"permissions": [
15+
"serial"
16+
],
17+
"bluetooth": {
18+
"uuids": ["1101"],
19+
"socket": true
20+
},
21+
"icons": {
22+
"128": "assets/icon_128.png"
23+
}
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>Status</title>
7+
<script src="json-human/src/json.human.js"></script>
8+
<script src="status.js"></script>
9+
<link rel="stylesheet" href="json-human/css/json.human.css"></link>
10+
<style>
11+
html,
12+
body {
13+
overflow-y: auto;
14+
}
15+
16+
body {
17+
-webkit-user-select: text
18+
}
19+
20+
.button {
21+
font-size: 14px;
22+
}
23+
</style>
24+
</head>
25+
26+
<body>
27+
<h1>Serial Port <button class='button' id='refresh'>Refresh</button></h1>
28+
<div id='status'></div>
29+
<div>
30+
<input id='disconnId' type='text' size='5' />
31+
<button id='disconnect'>Disconnect</button>
32+
<span id='disconnStatus'></span>
33+
</div>
34+
<h1>Bluetooth <button class='button' id='refresh-bt'>Refresh</button></h1>
35+
<div id='status-bt'></div>
36+
<div>
37+
<input id='disconnId-bt' type='text' size='5' />
38+
<button id='disconnect-bt'>Disconnect</button>
39+
<span id='disconnStatus-bt'></span>
40+
</div>
41+
</body>
42+
43+
</html>

0 commit comments

Comments
 (0)