Skip to content

Commit

Permalink
refactored to use nodejs-mobile-cordova and webintents
Browse files Browse the repository at this point in the history
Note new location for node apps - see readme.
  • Loading branch information
chrisekelley committed Apr 8, 2018
1 parent 0e621da commit 5753628
Show file tree
Hide file tree
Showing 4,331 changed files with 145,524 additions and 40,684 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -8,4 +8,7 @@ bunsen-ang/src/assets/node/.bunsen/*
www/assets/node_modules/
!bunsen-ang/src/assets/node_modules/
node_modules/*
.idea


.DS_Store
20 changes: 10 additions & 10 deletions README.md
Expand Up @@ -45,7 +45,7 @@ You will need to start two services, the UI and the Server in two different term

In the first terminal:
```
cd bunsen-ang/src/node
cd www/nodejs-project
node server.js
```

Expand All @@ -64,26 +64,26 @@ Requirements:
- On Ubuntu, easiest way is `sudo apt install android-tools-adb android-tools-fastboot`
- Enable USB debugging on your Android device. https://www.howtogeek.com/129728/how-to-access-the-developer-options-menu-and-enable-usb-debugging-on-android-4.2/

Run the following to build and install on an Android device.
Run the following to build the app.
```
npm install -g cordova
npm install -g cordova@7.1.0
git clone git@github.com:bunsenbrowser/bunsen
cd bunsen
npm install
./install.sh
cordova build android
```

To install on an Android device, you may use the `./installapp.sh` script

## Architecture
Bunsen consists of a UI App that is the chrome of the browser and an iframe that points at a Dat Server to display the requested Dat. When a user enters a Dat into the bar, it contacts the Dat Server by sending a GET request to `https://localhost:8080/dat/<dat UUID>`, waits until it is ready, and then displays an iframe that points to `https://localhost:8080/` where the backend Dat server that is serving the downloaded Dat.

The location of the UI is at `./bunsen-ang/` while the location of the Dat Server is at `./bunsen-ang/assets/node/`.

The Cordova application depends on the [cordova-node-plugin](https://github.com/bunsenbrowser/cordova-node-plugin)
to provide the node instance. If you wish to modify that plugin, fork/clone it and link to it:
The location of the UI is at `./bunsen-ang/` while the location of the Dat Server is at `./www/nodejs-project/`.

`cordova plugin add --link ../cordova-plugin-node`
The Cordova application depends on the [nodejs-mobile-cordova](https://github.com/janeasystems/nodejs-mobile-cordova)
to provide the node instance. nodejs-mobile-cordova supports ARMv7a and x86 CPU architectures on Android and also supports IOS as well.

Run the `prep-plugin.sh` script whenever you make changes to the plugin; it removes and re-installs the plugin.
Thanks a lot, [Janea Systems](http://www.janeasystems.com/)!

The node_modules packages have been compiled in termux on a Nexus 5X.

Expand Down
38 changes: 19 additions & 19 deletions bunsen-ang/npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 66 additions & 15 deletions bunsen-ang/src/app/app.component.ts
@@ -1,5 +1,4 @@
///<reference path="../typings.d.ts"/>
///<reference path="../../node_modules/cordova-node-plugin/index.d.ts"/>
import {Component, ElementRef, Input, ViewChild} from '@angular/core';
import {HttpClient} from '@angular/common/http';
import {DomSanitizer, SafeResourceUrl} from '@angular/platform-browser';
Expand Down Expand Up @@ -43,26 +42,76 @@ export class AppComponent {
console.log('deviceready');
// console.log(cordova.file);

startNodeServer();
// startNodeServer();
startNodeProject();

function startNodeServer() {
CordovaNodePlugin.startServer(function (result) {
console.log('Result of starting Node: ' + result);
}, function (err) {
// function startNodeServer() {
// CordovaNodePlugin.startServer(function (result) {
// console.log('Result of starting Node: ' + result);
// }, function (err) {
// console.log(err);
// });
// }

function channelListener(msg) {
console.log('[cordova] received: ' + msg);
};

function startupCallback(err) {
if (err) {
console.log(err);
});
}
} else {
console.log ('Node.js Mobile Engine Started');
nodejs.channel.send('Hello from Cordova!');
}
};

function startNodeProject() {
console.log ('Starting nodejs listener');
nodejs.channel.setListener(channelListener);
// console.log ('Starting node project test app');
// nodejs.start('main.js', startupCallback);
console.log ('Starting Angular 2 app');
nodejs.start('index.js', startupCallback);
// To disable the stdout/stderr redirection to the Android logcat:
// nodejs.start('main.js', startupCallback, { redirectOutputToLogcat: false });
};

// WebIntentPlugin.getUri(function (uri) {
// if (uri !== '') {
// console.log("uri: " + uri);
// var datUri = uri.replace('dat://', '')
// this.update(datUri);
// }
// });
}, false);

document.addEventListener('resume', () => {
console.log('resume');
var that = this;

webintent.getExtra(webintent.EXTRA_TEXT,
function (url) {
console.log("getExtra uri: " + url);
var datUri = url.replace('dat://', '')
that.update(datUri);
}, function () {
// There was no extra supplied.
}
);

webintent.getUri(function (uri) {
console.log("webintent getUri triggered: " + uri);
if (uri !== null) {
console.log("uri: " + uri);
var datUri = uri.replace('dat://', '')
that.update(datUri);
}
});

webintent.onNewIntent(function(url) {
console.log("INTENT onNewIntent: " + url);
var datUri = url.replace('dat://', '')
that.update(datUri);
});

}, false);



// var url = this.serverUrl + "index.html"
// this.http.get(url, {observe: 'response'}).subscribe(data => {
//
Expand Down Expand Up @@ -162,6 +211,7 @@ export class AppComponent {
const body = {uri: this.datUri};
var url = this.serverDatUrl + this.datUri;
this.fetchedHtml = "";
let that = this;
// Make the HTTP request:
this.http.get(url, {observe: 'response'}).subscribe(data => {
// Read the result field from the JSON response.
Expand All @@ -174,6 +224,7 @@ export class AppComponent {
// (document.querySelector('#progressSpinner') as HTMLElement).style.display = 'none';
dialogRef.close();
(document.querySelector('#box') as HTMLElement).style.display = "none";
that.refreshIframe();
// this.toggleSpinner()
// window.location.href=this.serverUrl;
});
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion bunsen-ang/src/index.html
Expand Up @@ -12,7 +12,7 @@
</head>
<body>
<app-root>Loading...</app-root>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="../cordova.js"></script>
<script type="text/javascript">
function log(msg){
document.body.innerHTML += '<p>' + msg + '</p>';
Expand Down
8 changes: 8 additions & 0 deletions bunsen-ang/src/typings.d.ts
Expand Up @@ -3,4 +3,12 @@ declare var module: NodeModule;
interface NodeModule {
id: string;
}
declare var nodejs;
interface nodejs {
id: string;
}
declare var webintent;
interface webintent {
id: string;
}

9 changes: 4 additions & 5 deletions config.xml
Expand Up @@ -7,7 +7,7 @@
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<content src="app/index.html" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
Expand All @@ -26,9 +26,8 @@
<allow-intent href="itms-apps:*" />
</platform>
<hook src="scripts/prepareAngular2App.js" type="before_prepare" />
<engine name="android" spec="^6.2.3" />
<plugin name="cordova-node-plugin" spec="git+https://github.com/bunsenbrowser/cordova-node-plugin.git" />
<plugin name="cordova-plugin-android-permissions" spec="^1.0.0" />
<plugin name="cordova-plugin-file" spec="^4.3.3" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.3" />
<plugin name="nodejs-mobile-cordova" spec="^0.1.4" />
<plugin name="com.borismus.webintent" spec="https://github.com/cordova-misc/cordova-webintent.git" />
</widget>
26 changes: 0 additions & 26 deletions hooks/after_platform_add/010_install_plugins.js

This file was deleted.

63 changes: 63 additions & 0 deletions info.txt
@@ -0,0 +1,63 @@
Node version: v9.5.0

Cordova version: 7.0.0

Config.xml file:

<?xml version='1.0' encoding='utf-8'?>
<widget id="org.rti.sses.rcd.bunsen" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>Bunsen</name>
<description>
p2p4u&amp;me
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Apache Cordova Team
</author>
<content src="index.html" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="*" />
<allow-navigation href="*" />
<access origin="*" />
<platform name="android">
<allow-intent href="market:*" />
<hook src="hooks/after_prepare/android/020_add_dat_intent.js" type="after_prepare" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<hook src="scripts/prepareAngular2App.js" type="before_prepare" />
<engine name="android" spec="^6.4.0" />
<plugin name="cordova-plugin-android-permissions" spec="^1.0.0" />
<plugin name="cordova-plugin-file" spec="^4.3.3" />
<plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
<plugin name="nodejs-mobile-cordova" spec="^0.1.4" />
</widget>


Plugins:

cordova-plugin-android-permissions,cordova-plugin-compat,cordova-plugin-file,cordova-plugin-whitelist,nodejs-mobile-cordova

Android platform:

*************************************************************************
The "android" command is deprecated.
For manual SDK, AVD, and project management, please use Android Studio.
For command-line tools, use tools/bin/sdkmanager and tools/bin/avdmanager
*************************************************************************
Running /Users/chrisk/Library/Android/sdk/tools/bin/avdmanager list target

Loading local repository... [========= ] 25% Loading local repository... [========= ] 25% Fetch remote repository... [========= ] 25% Fetch remote repository... [========= ] 25% Fetch remote repository... [=======================================] 100% Fetch remote repository... Available Android targets:
----------
id: 1 or "android-27"
Name: Android API 27
Type: Platform
API level: 27
Revision: 1

Expand Down
3 changes: 2 additions & 1 deletion installapp.sh
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
adb uninstall org.rti.sses.rcd.bunsen
cordova build android
adb install /Users/chrisk/source/bunsenbrowser/bunsen/platforms/android/build/outputs/apk/android-debug.apk
adb install ${HOME}/source/bunsenbrowser/bunsen/platforms/android/build/outputs/apk/android-debug.apk
adb shell am start -n org.rti.sses.rcd.bunsen/org.rti.sses.rcd.bunsen.MainActivity

0 comments on commit 5753628

Please sign in to comment.