Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed May 19, 2021
1 parent 2a5096f commit bfee2f8
Show file tree
Hide file tree
Showing 16 changed files with 1,669 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/typescript-node/.devcontainer/base.Dockerfile

# [Choice] Node.js version: 16, 14, 12
ARG VARIANT="16-buster"
FROM mcr.microsoft.com/vscode/devcontainers/typescript-node:0-${VARIANT}

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment if you want to install an additional version of node using nvm
# ARG EXTRA_NODE_VERSION=10
# RUN su node -c "source /usr/local/share/nvm/nvm.sh && nvm install ${EXTRA_NODE_VERSION}"

# [Optional] Uncomment if you want to install more global node packages
# RUN su node -c "npm install -g <your-package-list -here>"
45 changes: 45 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/typescript-node
{
"name": "Node.js & TypeScript",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick a Node version: 12, 14, 16
"args": {
"VARIANT": "16"
}
},

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"bierner.lit-html",
"runem.lit-plugin",
],

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",

// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "node",

"settings": {
"files.eol": "\n",
"editor.tabSize": 2,
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.trimTrailingWhitespace": true
}

}
24 changes: 24 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 16
- run: yarn install --frozen-lockfile
- run: script/build
- run: prettier --check src
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
node_modules
yarn.log
14 changes: 14 additions & 0 deletions example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<html>
<head>
<title>Improv Example</title>
</head>
<body>
<p>Default button:</p>
<improv-wifi-launch-button></improv-wifi-launch-button>
<p>Custom launch button:</p>
<improv-wifi-launch-button>
<a href="#">Launch improv</a>
</improv-wifi-launch-button>
<script src="./dist/index.js" type="module"></script>
</body>
</html>
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "improv-wifi-sdk",
"version": "0.0.1",
"description": "Improv Wi-Fi SDK for the browser",
"main": "dist/index.js",
"repository": "https://github.com/improv-wifi/sdk-js",
"author": "Improv Wi-Fi maintainers",
"license": "Apache-2.0",
"scripts": {
"prepublishOnly": "script/build"
},
"devDependencies": {
"@rollup/plugin-node-resolve": "^13.0.0",
"@rollup/plugin-typescript": "^8.2.1",
"@types/web-bluetooth": "^0.0.9",
"prettier": "^2.3.0",
"rollup": "^2.48.0",
"serve": "^11.3.2",
"typescript": "^4.2.4"
},
"dependencies": {
"@material/mwc-button": "^0.21.0",
"@material/mwc-circular-progress": "^0.21.0",
"@material/mwc-dialog": "^0.21.0",
"@material/mwc-textfield": "^0.21.0",
"lit": "^2.0.0-rc.2",
"tslib": "^2.2.0"
}
}
11 changes: 11 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';

export default {
input: 'src/index.ts',
output: {
dir: 'dist',
format: 'module',
},
plugins: [typescript(), nodeResolve()],
};
7 changes: 7 additions & 0 deletions script/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Stop on errors
set -e

cd "$(dirname "$0")/.."

rm -rf dist
NODE_ENV=production rollup -c
13 changes: 13 additions & 0 deletions script/develop
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Stop on errors
set -e

cd "$(dirname "$0")/.."

rm -rf dist

# Quit all background tasks when script exits
trap "kill 0" EXIT

yarn serve &
yarn rollup -c --watch &
wait
20 changes: 20 additions & 0 deletions src/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const IMPROV_BLE_SERVICE = "00467768-6228-2272-4663-277478268000";
export const IMPROV_BLE_CURRENT_STATE_CHARACTERISTIC =
"00467768-6228-2272-4663-277478268001";
export const IMPROV_BLE_ERROR_STATE_CHARACTERISTIC =
"00467768-6228-2272-4663-277478268002";
export const IMPROV_BLE_RPC_CHARACTERISTIC =
"00467768-6228-2272-4663-277478268003";

export const IMPROV_BLE_CURRENT_STATE__NO_STATE = 0x00;
export const IMPROV_BLE_CURRENT_STATE__AVAILABLE = 0x01;
export const IMPROV_BLE_CURRENT_STATE__ACTIVATED = 0x02;
export const IMPROV_BLE_CURRENT_STATE__PROVISIONING = 0x03;
export const IMPROV_BLE_CURRENT_STATE__PROVISIONED = 0x04;

export type ImprovState =
| "NO_STATE"
| "AVAILABLE"
| "ACTIVATED"
| "PROVISIONING"
| "PROVISIONED";
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './launch-button';
38 changes: 38 additions & 0 deletions src/launch-button.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { LitElement, html, PropertyValues, css } from "lit";
import { customElement } from "lit/decorators.js";
import { startProvisioning } from "./provision";
import "@material/mwc-button";

@customElement("improv-wifi-launch-button")
class LaunchButton extends LitElement {
protected render() {
return "bluetooth" in navigator
? html`
<slot>
<mwc-button label="Connect device to Wi-Fi"></mwc-button>
</slot>
`
: html`Your browser does not support bluetooth provisioning. Use Google
Chrome or Microsoft Edge.`;
}

protected firstUpdated(changedProps: PropertyValues) {
super.firstUpdated(changedProps);
this.addEventListener("click", (ev) => {
ev.preventDefault();
startProvisioning();
});
}

static styles = css`
:host {
--mdc-theme-primary: #03a9f4;
}
`;
}

declare global {
interface HTMLElementTagNameMap {
"improv-wifi-launch-button": LaunchButton;
}
}
Loading

0 comments on commit bfee2f8

Please sign in to comment.