chrome-app-api-proxy
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -15,5 +15,4 @@ 'use strict'; | ||
minHeight: APP_HEIGHT | ||
}, | ||
alwaysOnTop: true | ||
} | ||
}); | ||
}); |
'use strict'; | ||
chrome.runtime.onConnectExternal.addListener(function(port) { | ||
(function() { | ||
var state = document.querySelector('#state'); | ||
state.innerHTML = 'Connected'; | ||
var port; | ||
chrome.runtime.onConnectExternal.addListener(function(_port) { | ||
port = _port; | ||
state.innerHTML = 'Connected'; | ||
port.onMessage.addListener(function(message) { | ||
var callId = message.callId; | ||
var params = message.params; | ||
if (!params) { | ||
params = []; | ||
} | ||
params.push(function(data) { | ||
port.postMessage({ callId: callId, data: data }); | ||
}); | ||
// Convert Array to ArrayBuffer. | ||
if (message.call === 'chrome.serial.send') { | ||
params[1] = new Uint8Array(params[1]).buffer; | ||
} | ||
var call = window; | ||
var objects = message.call.split('.'); | ||
objects.forEach(function(object) { | ||
call = call[object]; | ||
}); | ||
call instanceof Function && call.apply(null, params); | ||
}); | ||
port.onDisconnect.addListener(function() { | ||
state.innerHTML = 'Disconnected'; | ||
}); | ||
}); | ||
// Send serialport data to the Webpage. | ||
// The listener only can be registered once, | ||
// or it will be triggered multiple times. | ||
chrome.serial.onReceive.addListener(function(info) { | ||
info.data = toHexString(info.data); | ||
port.postMessage({ type: 'serial', info: info }); | ||
}); | ||
port.onMessage.addListener(function(message) { | ||
var callId = message.callId; | ||
var params = message.params; | ||
if (!params) { | ||
params = []; | ||
function toHexString(arrayBuffer) { | ||
var string = ''; | ||
var uint8Array = new Uint8Array(arrayBuffer); | ||
for (var i = 0; i < uint8Array.length; i++) { | ||
var hex = uint8Array[i].toString(16); | ||
if (hex.length == 1) { | ||
string += '0'; | ||
} | ||
string += hex; | ||
} | ||
return string; | ||
} | ||
params.push(function(data) { | ||
port.postMessage({ callId: callId, data: data }); | ||
}); | ||
// Convert Array to ArrayBuffer. | ||
if (message.call === 'chrome.serial.send') { | ||
params[1] = new Uint8Array(params[1]).buffer; | ||
} | ||
var call = window; | ||
var objects = message.call.split('.'); | ||
objects.forEach(function(object) { | ||
call = call[object]; | ||
}); | ||
call instanceof Function && call.apply(null, params); | ||
}); | ||
function toHexString(arrayBuffer) { | ||
var string = ''; | ||
var uint8Array = new Uint8Array(arrayBuffer); | ||
for (var i = 0; i < uint8Array.length; i++) { | ||
var hex = uint8Array[i].toString(16); | ||
if (hex.length == 1) { | ||
string += '0'; | ||
} | ||
string += hex; | ||
} | ||
return string; | ||
} | ||
}); | ||
}()); |
@@ -5,3 +5,3 @@ { | ||
"description": "Call Chrome App APIs from a Webpage.", | ||
"version": "0.0.1", | ||
"version": "0.0.3", | ||
"app": { | ||
@@ -8,0 +8,0 @@ "background": { |
/* global ChromeApiProxy */ | ||
'use strict'; | ||
var extensionId = 'mncdajaedfblonbkmodofckdialkolgk'; | ||
var extensionId = 'dacgaojeadgpmpmbfoibmncggacokdjd'; | ||
var proxy = new ChromeApiProxy(extensionId); | ||
@@ -6,0 +6,0 @@ |
{ | ||
"name": "chrome-app-api-proxy", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/evanxd/chrome-api-proxy", | ||
@@ -5,0 +5,0 @@ "authors": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5340
151