Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Commit

Permalink
building extension
Browse files Browse the repository at this point in the history
  • Loading branch information
pelikhan committed Feb 5, 2016
1 parent 4bdac7c commit 87ab1b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ node_modules
npm-debug.log
typings

# build
background.js
25 changes: 18 additions & 7 deletions background.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,39 @@
///<reference path='typings/browser.d.ts'/>
// A list of: {
// id: number;
// path: string;
// } where [id] is the [connectionId] (internal to Chrome) and [path] is the
// OS' name for the device (e.g. "COM4").
var connections = [];
interface Connection {
id:string;
path:string;
}
var connections : Connection[] = [];

// A list of "ports", i.e. connected clients (such as web pages). Multiple web
// pages can connect to our service: they all receive the same data.
var ports = [];

function byPath(path) {
return connections.filter(function (x) { return x.path == path; });
interface Message {
type:string;
data:string;
id:string;
}

function byPath(path : string) : Connection[] {
return connections.filter((x) => x.path == path);
}

function byId(id) {
return connections.filter(function (x) { return x.id == id; });
function byId(id : string) : Connection[] {
return connections.filter((x) => x.id == id);
}

function onReceive(data, id) {
function onReceive(data, id: string) {
ports.forEach(function (port) {
var view = new DataView(data);
var decoder = new TextDecoder("utf-8");
var decodedString = decoder.decode(view);
port.postMessage({
port.postMessage(<Message>{
type: "serial",
data: decodedString,
id: id,
Expand Down

0 comments on commit 87ab1b9

Please sign in to comment.