Compare commits
No commits in common. "master" and "v0.9" have entirely different histories.
@ -1,6 +1,4 @@
|
||||
node_modules
|
||||
radata
|
||||
stats.radata
|
||||
.git
|
||||
.gitignore
|
||||
*.md
|
||||
|
12
.github/FUNDING.yml
vendored
@ -1,12 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: amark
|
||||
patreon: gunDB
|
||||
open_collective: gun
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
114
.github/workflows/ci.yml
vendored
@ -1,114 +0,0 @@
|
||||
name: ci
|
||||
|
||||
on:
|
||||
- push
|
||||
- pull_request
|
||||
|
||||
jobs:
|
||||
|
||||
test:
|
||||
strategy:
|
||||
matrix:
|
||||
node-version: [ 14.x ]
|
||||
os: [ ubuntu-latest ]
|
||||
runs-on: ${{ matrix.os }}
|
||||
steps:
|
||||
|
||||
# checkout the code
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# verify the version in package.json matches the release tag
|
||||
- name: Version
|
||||
uses: tcurdt/action-verify-version-npm@master
|
||||
|
||||
# setup the node version
|
||||
- name: Setup Node ${{ matrix.node-version }}
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: ${{ matrix.node-version }}
|
||||
|
||||
# cache node_modules if we can
|
||||
- name: Cache
|
||||
id: cache-modules
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: node_modules
|
||||
key: ${{ matrix.node-version }}-${{ runner.OS }}-build-${{ hashFiles('package.json') }}
|
||||
|
||||
# ottherweise run install
|
||||
- name: Install
|
||||
if: steps.cache-modules.outputs.cache-hit != 'true'
|
||||
run: npm install
|
||||
|
||||
# run tests
|
||||
- name: Test
|
||||
run: npm test
|
||||
|
||||
# create github release
|
||||
release:
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
needs: [ test ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
# create github release (which triggers the release workflows)
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
# env:
|
||||
# GITHUB_TOKEN: ${{ secrets.PAT }}
|
||||
|
||||
# # publish latest master or release to dockerhub
|
||||
# dockerhub:
|
||||
# if: github.event_name == 'push'
|
||||
# needs: [ test ]
|
||||
# runs-on: ubuntu-latest
|
||||
# env:
|
||||
# image: ${{ secrets.DOCKERHUB_USERNAME }}/gun
|
||||
# steps:
|
||||
|
||||
# - name: Checkout
|
||||
# uses: actions/checkout@v2
|
||||
|
||||
# - name: Login
|
||||
# env:
|
||||
# DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
# DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
# run: echo -n ${{ secrets.DOCKERHUB_TOKEN }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin
|
||||
|
||||
# - name: Build
|
||||
# run: |
|
||||
# echo "SHA=$GITHUB_SHA"
|
||||
# docker build --build-arg SHA=$GITHUB_SHA \
|
||||
# BUILD_DATE=$(date +'%Y-%m-%dT%H:%M:%S') \
|
||||
# VCS_REF=${GITHUB_REF} \
|
||||
# VCS_URL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY} \
|
||||
# VERSION=${GITHUB_REF##*/} \
|
||||
# SHA=$GITHUB_SHA \
|
||||
# --label "SHA=$GITHUB_SHA" \
|
||||
# --tag ${{ env.image }}:${GITHUB_REF##*/} \
|
||||
# --tag ${{ env.image }}:latest \
|
||||
# .
|
||||
|
||||
# - name: Push
|
||||
# run: docker push ${{ env.image }}
|
||||
|
||||
|
||||
# publish release to npm
|
||||
npm:
|
||||
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
|
||||
needs: [ test ]
|
||||
# needs: [ release ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Publish
|
||||
env:
|
||||
NPM_AUTH_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
|
||||
run: |
|
||||
npm config set //registry.npmjs.org/:_authToken=$NPM_AUTH_TOKEN
|
||||
npm install
|
||||
npm publish --access=public
|
8
.gitignore
vendored
@ -7,15 +7,7 @@ yarn.lock
|
||||
.idea/
|
||||
*.bak
|
||||
*.new
|
||||
*.log
|
||||
v8.json
|
||||
*.DS_store
|
||||
isolate*.log
|
||||
.esm-cache
|
||||
.sessionStorage
|
||||
.localStorage
|
||||
/types/**/*.ts
|
||||
!/types/**/*.d.ts
|
||||
!/types/**/*.test-d.ts
|
||||
/gun.ts
|
||||
/temp/
|
@ -1,5 +0,0 @@
|
||||
*.ts
|
||||
/temp/
|
||||
!*.d.ts
|
||||
*.radata
|
||||
isolate-*
|
@ -1 +0,0 @@
|
||||
*
|
13
.travis.yml
@ -1,10 +1,7 @@
|
||||
language: node_js
|
||||
branches:
|
||||
except:
|
||||
- debug
|
||||
- manhattan
|
||||
node_js:
|
||||
- 10
|
||||
cache:
|
||||
directories:
|
||||
- node_modules
|
||||
- 4.0
|
||||
- 4.2
|
||||
- 5.0
|
||||
- 6.8
|
||||
- 7.9
|
22
CHANGELOG.md
@ -1,27 +1,5 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 0.2020.x
|
||||
|
||||
`>0.2020.520` may break in-process `gun1` `gun2` message passing. Check `test/common.js` "Check multi instance message passing" for a hint and/or complain on community chat.
|
||||
|
||||
- No breaking changes to core API.
|
||||
- Storage adapter `put` event breaking change (temporary?), RAD is official now and storage adapters should be RAD plugins instead of GUN adapters.
|
||||
- GUN soul format changed from being a random UUID to being a more predictable graph path (of where initially created) to support even better offline behavior. This means `null`ing & replacing an object will not create a new but re-merge.
|
||||
- Pretty much all internal GUN utility will be deleted, these are mostly undocumented but will affect some people - they will still be available as a separate file but deprecated.
|
||||
- As the DHT gets implemented, your relay peers may automatically connect to it, so do not assume your peer is standalone. `Gun({axe: false` should help prevent this but loses you most scaling properties.
|
||||
- The 2019 -> 2020 "changes" are happening gradually, based on experimental in-production tests.
|
||||
- As always, **most important** is to ask in the [community chat](http://chat.gun.eco) if you have any issues, and to keep up to date with changes.
|
||||
|
||||
## 0.2019.x
|
||||
|
||||
Some RAD & SEA data format changes, but with as much backward compatibility as possible, tho ideally should be dropped.
|
||||
|
||||
## 0.9.x
|
||||
|
||||
No breaking changes, but the new Radix Storage Engine (RSE) has been finally integrated and works with S3 as a backup.
|
||||
|
||||
// Edit: commentary removed.
|
||||
|
||||
## 0.8.x
|
||||
|
||||
Adapter interfaces have changed from `Gun.on('event', cb)` to `gun.on('event', cb)`, this will force adapters to be instance specific.
|
||||
|
29
Dockerfile
@ -1,35 +1,24 @@
|
||||
# install packages
|
||||
FROM node:lts-alpine as builder
|
||||
RUN mkdir /work
|
||||
WORKDIR /work
|
||||
RUN apk add --no-cache alpine-sdk python3
|
||||
COPY package*.json ./
|
||||
RUN mkdir -p node_modules
|
||||
RUN npm ci --only=production
|
||||
|
||||
# fresh image without dev packages
|
||||
FROM node:lts-alpine
|
||||
# build-time metadata as defined at http://label-schema.org
|
||||
FROM alpine:edge
|
||||
# Build-time metadata as defined at http://label-schema.org
|
||||
ARG BUILD_DATE
|
||||
ARG VCS_REF
|
||||
ARG VCS_URL
|
||||
ARG VERSION
|
||||
LABEL org.label-schema.build-date=$BUILD_DATE \
|
||||
org.label-schema.name="Gun - Offline First, Javascript Graph Database" \
|
||||
# org.label-schema.description="Let it be pulled from Readme.md..." \
|
||||
org.label-schema.url="http://gun.js.org" \
|
||||
org.label-schema.vcs-ref=$VCS_REF \
|
||||
org.label-schema.vcs-url=$VCS_URL \
|
||||
org.label-schema.vendor="The Gun Database Team" \
|
||||
org.label-schema.version=$VERSION \
|
||||
org.label-schema.schema-version="1.0"
|
||||
ARG SHA
|
||||
RUN mkdir /work
|
||||
WORKDIR /work
|
||||
COPY --from=builder /work/node_modules ./node_modules
|
||||
RUN npm rebuild -q
|
||||
WORKDIR /app
|
||||
ADD . .
|
||||
RUN echo "{ \"sha\": \"$SHA\" }" > version.json
|
||||
RUN cat version.json
|
||||
ENV NPM_CONFIG_LOGLEVEL warn
|
||||
RUN apk update && apk upgrade \
|
||||
&& apk add --no-cache ca-certificates nodejs \
|
||||
&& npm install \
|
||||
&& rm -rf /var/cache/* -rf /tmp/npm*
|
||||
EXPOSE 8080
|
||||
EXPOSE 8765
|
||||
CMD ["npm","start"]
|
||||
|
253
README.md
@ -1,87 +1,70 @@
|
||||
<p id="readme"><a href="https://gun.eco/"><img width="40%" src="https://cldup.com/TEy9yGh45l.svg"/></a><img width="50%" align="right" vspace="25" src="https://gun.eco/see/demo.gif"/></p>
|
||||
<p>
|
||||
<a href="http://gun.js.org/"><img width="40%" src="https://cldup.com/TEy9yGh45l.svg"/></a>
|
||||
<img width="50%" align="right" vspace="25" src="http://gun.js.org/see/demo.gif"/>
|
||||
</p>
|
||||
|
||||
[](https://www.jsdelivr.com/package/npm/gun)
|
||||

|
||||
[](http://chat.gun.eco)
|
||||
[](https://www.npmjs.com/package/gun)
|
||||
[](https://travis-ci.org/amark/gun)
|
||||
[](https://app.fossa.io/projects/git%2Bhttps%3A%2F%2Fgithub.com%2Famark%2Fgun?ref=badge_shield)
|
||||
[](https://gitter.im/amark/gun)
|
||||
|
||||
**GUN** is an [ecosystem](https://gun.eco/docs/Ecosystem) of **tools** that let you build [community run](https://www.nbcnews.com/tech/tech-news/these-technologists-think-internet-broken-so-they-re-building-another-n1030136) and [encrypted applications](https://gun.eco/docs/Cartoon-Cryptography) - like an Open Source Firebase or a Decentralized Dropbox.
|
||||
GUN is a realtime, distributed, offline-first, graph database engine. Doing **[20M+](https://github.com/amark/gun/wiki/100000-ops-sec-in-IE6-on-2GB-Atom-CPU) ops/sec** in just **~9KB** gzipped.
|
||||
|
||||
The [Internet Archive](https://news.ycombinator.com/item?id=17685682) and [100s of other apps](https://github.com/amark/gun/wiki/awesome-gun) run GUN in-production.
|
||||
<a href="https://youtu.be/-i-11T5ZI9o" title="1 minute demo of fault tolerance"><img src="http://img.youtube.com/vi/-i-11T5ZI9o/0.jpg" width="425px"></a>
|
||||
<a href="https://youtu.be/-FN_J3etdvY" title="1 minute demo of fault tolerance"><img src="http://img.youtube.com/vi/-FN_J3etdvY/0.jpg" width="425px"></a>
|
||||
|
||||
+ Multiplayer by default with realtime p2p state synchronization!
|
||||
+ Graph data lets you use key/value, tables, documents, videos, & more!
|
||||
+ Local-first, offline, and decentralized with end-to-end encryption.
|
||||
## Why?
|
||||
|
||||
Decentralized alternatives to [Zoom](https://www.zdnet.com/article/era-hatches-meething-an-open-source-browser-based-video-conferencing-system/), [Reddit](https://notabug.io/t/whatever/comments/36588a16b9008da4e3f15663c2225e949eca4a15/gpu-bot-test), [Instagram](https://iris.to/), [Slack](https://iris.to/), [YouTube](https://d.tube/), [Stripe](https://twitter.com/marknadal/status/1422717427427647489), [Wikipedia](https://news.ycombinator.com/item?id=17685682), Facebook [Horizon](https://twitter.com/marknadal/status/1424476179189305347) and more have already pushed terabytes of daily P2P traffic on GUN. We are a [friendly community](http://chat.gun.eco/) creating a [free fun future for freedom](https://youtu.be/1HJdrBk3BlE):
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<a href="https://youtu.be/s_m16-w6bBI"><img width="31%" src="https://gun.eco/see/3dvr.gif" title="3D VR"/></a>
|
||||
<a href="https://github.com/cstefanache/cstefanache.github.io/blob/06697003449e4fc531fd32ee068bab532976f47b/_posts/2016-08-02-gun-db-artificial-knowledge-sharing.md"><img width="31%" src="https://gun.eco/see/aiml.gif" title="AI/ML"/></a>
|
||||
<a href="http://gps.gunDB.io/"><img width="31%" src="https://gun.eco/see/gps.gif" title="GPS"/></a>
|
||||
</tr>
|
||||
<tr>
|
||||
<a href="https://github.com/lmangani/gun-scape#gun-scape"><img width="31%" src="https://gun.eco/see/dataviz.gif" title="Data Viz"/></a>
|
||||
<a href="https://github.com/amark/gun/wiki/Auth"><img width="31%" src="https://gun.eco/see/p2p.gif" title="P2P"/></a>
|
||||
<a href="https://github.com/Stefdv/gun-ui-lcd#okay-what-about-gundb-"><img width="31%" src="https://gun.eco/see/iot.gif" title="IoT"/></a>
|
||||
</tr>
|
||||
<tr>
|
||||
<a href="http://chat.gun.eco"><img width="31%" src="https://gun.eco/see/vr-world.gif" title="VR World"/></a>
|
||||
<a href="https://youtu.be/1ASrmQ-CwX4"><img width="31%" src="https://gun.eco/see/ar.gif" title="AR"/></a>
|
||||
<a href="https://meething.space/"><img width="31%" src="https://gun.eco/see/video-conf.gif" title="Video Confernece"/></a>
|
||||
</tr>
|
||||
</table>
|
||||
- **Realtime** - You might use socketio for realtime updates, but what happens if you reload the page? GUN solves *state synchronization* for you, no matter what, on reloads, across all your users, and even on conflicting updates.
|
||||
- **Distributed** - GUN is peer-to-peer by design, meaning you have no centralized database server to maintain or that could crash. This lets you sleep through the night without worrying about database DevOps - we call it "NoDB". From there, you can build decentralized, federated, or centralized apps.
|
||||
- **Offline-first** - GUN works even if your internet or cell reception doesn't. Users can still plug away and save data as normal, and then when the network comes back online GUN will automatically synchronize all the changes and handle any conflicts for you.
|
||||
- **Graph** - Most databases force you to bend over backwards to match their storage constraints. But graphs are different, they let you have any data structure you want. Whether that be traditional tables with relations, document oriented trees, or tons of circular references. You choose.
|
||||
|
||||
## Quickstart
|
||||
|
||||
GUN is *super easy* to get started with:
|
||||
|
||||
- Try the [interactive tutorial](https://gun.eco/docs/Todo-Dapp) in the browser (**5min** ~ average developer).
|
||||
- Try the [interactive tutorial](http://gun.js.org/think.html) in the browser (**5min** ~ average developer).
|
||||
- Or `npm install gun` and run the examples with `cd node_modules/gun && npm start` (**5min** ~ average developer).
|
||||
|
||||
> **Note:** If you don't have [node](http://nodejs.org/) or [npm](https://www.npmjs.com/), read [this](https://github.com/amark/gun/blob/master/examples/install.sh) first.
|
||||
> If the `npm` command line didn't work, you may need to `mkdir node_modules` first or use `sudo`.
|
||||
|
||||
- An online demo of the examples are available here: http://try.axe.eco/
|
||||
- Or write a quick app: ([try now in a playground](https://jsbin.com/kadobamevo/edit?js,console))
|
||||
- An online demo of the examples are available here: http://gunjs.herokuapp.com/
|
||||
- Or write a quick app: ([try now in jsbin](http://jsbin.com/sovihaveso/edit?js,console))
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
|
||||
<script>
|
||||
// import GUN from 'gun'; // in ESM
|
||||
// GUN = require('gun'); // in NodeJS
|
||||
// GUN = require('gun/gun'); // in React
|
||||
gun = GUN();
|
||||
// var Gun = require('gun'); // in NodeJS
|
||||
// var Gun = require('gun/gun'); // in React
|
||||
var gun = Gun();
|
||||
|
||||
gun.get('mark').put({
|
||||
name: "Mark",
|
||||
email: "mark@gun.eco",
|
||||
email: "mark@gunDB.io",
|
||||
});
|
||||
|
||||
gun.get('mark').on((data, key) => {
|
||||
console.log("realtime updates:", data);
|
||||
gun.get('mark').on(function(data, key){
|
||||
console.log("update:", data);
|
||||
});
|
||||
|
||||
setInterval(() => { gun.get('mark').get('live').put(Math.random()) }, 9);
|
||||
</script>
|
||||
```
|
||||
- Or try something **mind blowing**, like saving circular references to a table of documents! ([play](http://jsbin.com/wefozepume/edit?js,console))
|
||||
- Or try something mind blowing, like saving circular references to a table of documents! ([play](http://jsbin.com/wefozepume/edit?js,console))
|
||||
```javascript
|
||||
cat = {name: "Fluffy", species: "kitty"};
|
||||
mark = {boss: cat};
|
||||
var cat = {name: "Fluffy", species: "kitty"};
|
||||
var mark = {boss: cat};
|
||||
cat.slave = mark;
|
||||
|
||||
// partial updates merge with existing data!
|
||||
gun.get('mark').put(mark);
|
||||
|
||||
// access the data as if it is a document.
|
||||
gun.get('mark').get('boss').get('name').once(function(data, key){
|
||||
// `once` grabs the data once, no subscriptions.
|
||||
gun.get('mark').get('boss').get('name').val(function(data, key){
|
||||
// `val` grabs the data once, no subscriptions.
|
||||
console.log("Mark's boss is", data);
|
||||
});
|
||||
|
||||
// traverse a graph of circular references!
|
||||
gun.get('mark').get('boss').get('slave').once(function(data, key){
|
||||
console.log("Mark is the cat's slave!", data);
|
||||
gun.get('mark').get('boss').get('slave').val(function(data, key){
|
||||
console.log("Mark is the slave!", data);
|
||||
});
|
||||
|
||||
// add both of them to a table!
|
||||
@ -89,189 +72,78 @@ gun.get('list').set(gun.get('mark').get('boss'));
|
||||
gun.get('list').set(gun.get('mark'));
|
||||
|
||||
// grab each item once from the table, continuously:
|
||||
gun.get('list').map().once(function(data, key){
|
||||
gun.get('list').map().val(function(data, key){
|
||||
console.log("Item:", data);
|
||||
});
|
||||
|
||||
// live update the table!
|
||||
gun.get('list').set({type: "cucumber", goal: "jumping cat"});
|
||||
gun.get('list').set({type: "cucumber", goal: "scare cat"});
|
||||
```
|
||||
|
||||
Want to keep building more? **Jump to [THE DOCUMENTATION](#documentation)!**
|
||||
|
||||
# About
|
||||
First & foremost, GUN is **a community of the nicest and most helpful people** out there. So [I want to invite you](http://chat.gun.eco) to come tell us about what **you** are working on & wanting to build (new or old school alike! Just be nice as well.) and ask us your questions directly. :)
|
||||
|
||||
<p align="center"><a href="https://www.youtube.com/watch?v=oTQXzhm8w_8"><img width="250" src="https://img.youtube.com/vi/oTQXzhm8w_8/0.jpg"><br/>Watch the 100 second intro!</a></p>
|
||||
|
||||
The GUN ecosystem stack is a collection of independent and modular tools covering everything from [CRDT](https://crdt.tech/) [conflict resolution](https://gun.eco/distributed/matters.html), [cryptographic security](https://gun.eco/docs/Cartoon-Cryptography) & [encryption](https://gun.eco/docs/SEA), [radix storage serialization](https://gun.eco/docs/RAD), [mesh networking](https://gun.eco/docs/DAM) & [routing algorithms](https://gun.eco/docs/Routing), to distributed systems [correctness & load testing](https://github.com/gundb/panic-server), CPU scheduled [JSON parser](https://github.com/amark/gun/blob/master/lib/yson.js) to prevent UI lag, and more!
|
||||
|
||||
<div><img width="48%" src="https://gun.eco/see/stack.png"/>
|
||||
<img width="48%" align="right" src="https://gun.eco/see/layers.png"/></div>
|
||||
|
||||
On that note, let's get some official shout outs covered first:
|
||||
|
||||
### Support
|
||||
## Support
|
||||
|
||||
<p align="center">
|
||||
Thanks to:
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td vlign="center"><a href="https://mozilla.org/builders"><img height="100" src="https://user-images.githubusercontent.com/1423657/81992335-85346480-9643-11ea-8754-8275e98e06bc.png"></a></td>
|
||||
<td vlign="center"><a href="http://unstoppabledomains.com/"><img src="https://gun.eco/img/unstoppable.png"></a></td>
|
||||
<td vlign="center"><a href="https://mask.io/"><img src="https://dimensiondev.github.io/Mask-VI/assets/Logo/MB--Logo--CombH-Circle--Blue.svg" width="250"></a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td vlign="center"> <a href="https://www.ajar.org/"><img src="https://www.ajar.org/logo.png" height="120"></a></td>
|
||||
<td vlign="center"><a href="https://wallie.io/"><img src="https://raw.githubusercontent.com/gundb/gun-site/master/img/wallie.png" width="250"></a></td>
|
||||
<td vlign="center"> <a href="https://ghostdrive.com/"><img src="https://gun.eco/img/ghostdrive.png" height="120"></a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a href="https://github.com/robertheessels">Robert Heessels</a>,
|
||||
<a href="http://qxip.net/">Lorenzo Mangani</a>,
|
||||
<a href="https://nlnet.nl/">NLnet Foundation</a>,
|
||||
Thanks to:<br/>
|
||||
<a href="http://qxip.net/"><img src="http://qxip.net/images/qxip_logo.png" width="100"></a><br/>
|
||||
<a href="http://github.com/samliu">Sam Liu</a>,
|
||||
<a href="http://github.com/ddombrow">Daniel Dombrowsky</a>,
|
||||
<a href="http://github.com/vincentwoo">Vincent Woo</a>,
|
||||
<a href="http://github.com/coolaj86">AJ ONeal</a>,
|
||||
<a href="http://github.com/ottman">Bill Ottman</a>,
|
||||
<a href="http://github.com/mikewlange">Mike Lange</a>,
|
||||
<a href="http://github.com/ctrlplusb">Sean Matheson</a>,
|
||||
<a href="http://github.com/alanmimms">Alan Mimms</a>,
|
||||
<a href="https://github.com/dfreire">Dário Freire</a>,
|
||||
<a href="http://github.com/velua">John Williamson</a>,
|
||||
<a href="http://github.com/finwo">Robin Bron</a>,
|
||||
<a href="http://github.com/ElieMakhoul">Elie Makhoul</a>,
|
||||
<a href="http://github.com/mikestaub">Mike Staub</a>,
|
||||
<a href="http://github.com/bmatusiak">Bradley Matusiak</a>,
|
||||
<a href="https://github.com/sjuxax">Jeff Cook</a>,
|
||||
<a href="https://github.com/nmauersberg">Nico</a>,
|
||||
<a href="https://github.com/ajartille">Aaron Artille</a>,
|
||||
<a href="https://github.com/timjrobinson">Tim Robinson</a>,
|
||||
<a href="https://github.com/hibas123">Fabian Stamm</a>,
|
||||
<a href="https://twitter.com/mikestaub">Mike Staub</a>,
|
||||
<a href="https://hunterowens.com/">Hunter Owens</a>,
|
||||
<a href="https://github.com/JacobMillner">Jacob Millner</a>,
|
||||
<a href="https://github.com/b-lack">Gerrit Balindt</a>,
|
||||
<a href="https://github.com/gabriellemon">Gabriel Lemon</a>,
|
||||
<a href="https://github.com/murageyun">Murage Martin</a>,
|
||||
<a href="https://github.com/octalmage">Jason Stallings</a>
|
||||
<a href="http://github.com/alanmimms">Alan Mimms</a>
|
||||
</p>
|
||||
|
||||
- Join others in sponsoring code: https://www.patreon.com/gunDB !
|
||||
- Ask questions: http://stackoverflow.com/questions/tagged/gun ?
|
||||
- Found a bug? Report at: https://github.com/amark/gun/issues ;
|
||||
- **Need help**? Chat with us: http://chat.gun.eco .
|
||||
- **Need help**? Chat with us: https://gitter.im/amark/gun .
|
||||
|
||||
### History
|
||||
|
||||
[GUN](https://gun.eco) was created by [Mark Nadal](https://twitter.com/marknadal) in 2014 after he had spent 4 years trying to get his collaborative web app to scale up with traditional databases.
|
||||
|
||||
<img width="250px" src="https://gun.eco/see/problem.png" align="left" title="pain point" style="margin: 0 1em 1em 0"> After he realized [Master-Slave database architecture causes one big bottleneck](https://gun.eco/distributed/matters.html), he (as a complete newbie outsider) naively decided **to question the status quo** and shake things up with controversial, heretical, and contrarian experiments:
|
||||
|
||||
**The NoDB** - no master, no servers, no "single source of truth", not built with a real programming language or real hardware, no DevOps, no locking, not *just* SQL or NoSQL but both (**all** - graphs, documents, tables, key/value).
|
||||
|
||||
The goal was to build a P2P database that could survive living inside **any** browser, and could correctly sync data between **any** device after assuming **any** offline-first activity.
|
||||
|
||||
<img src="https://gun.eco/see/compare.png" title="comparison table">
|
||||
|
||||
Technically, **GUN is a graph synchronization protocol** with a *lightweight embedded engine*, capable of doing *[20M+ API ops/sec](https://gun.eco/docs/Performance)* in **just ~9KB gzipped size**.
|
||||
|
||||
## Documentation
|
||||
|
||||
<table>
|
||||
<tr>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/API">API reference</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/Todo-Dapp">Tutorials</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/API">API reference</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="http://gun.js.org/think.html">Tutorials</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/tree/master/examples">Examples</a></h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/brysgo/graphql-gun">GraphQL</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/PenguinMan98/electrontest">Electron</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/React-Native">React & Native</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/staltz/gun-asyncstorage">Native</a></h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/sjones6/vue-gun">Vue</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/Svelte">Svelte</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/React-Tutorial">React</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/Stefdv/gun-ui-lcd#syncing">Webcomponents</a></h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/CAP-Theorem">CAP Theorem Tradeoffs</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/distributed/matters.html">How Data Sync Works</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/Porting-GUN">How GUN is Built</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/CAP-Theorem">CAP Theorem Tradeoffs</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="http://gun.js.org/distributed/matters.html">How Data Sync Works</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/porting-gun">How GUN is Built</a></h3></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/Auth">Crypto Auth</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/Awesome-GUN">Modules</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://gun.eco/docs/Roadmap">Roadmap</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/auth">Crypto Auth</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/Modules">Modules</a></h3></td>
|
||||
<td style="border: 0;"><h3><a href="https://github.com/amark/gun/wiki/roadmap">Roadmap</a></h3></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
This would not be possible without **community contributors**, big shout out to:
|
||||
|
||||
**[ajmeyghani](https://github.com/ajmeyghani) ([Learn GUN Basics with Diagrams](https://medium.com/@ajmeyghani/gundb-a-graph-database-in-javascript-3860a08d873c))**; **[anywhichway](https://github.com/anywhichway) ([Block Storage](https://github.com/anywhichway/gun-block))**; **[beebase](https://github.com/beebase) ([Quasar](https://github.com/beebase/gun-vuex-quasar))**; **[BrockAtkinson](https://github.com/BrockAtkinson) ([brunch config](https://github.com/BrockAtkinson/brunch-gun))**; **[Brysgo](https://github.com/brysgo) ([GraphQL](https://github.com/brysgo/graphql-gun))**; **[d3x0r](https://github.com/d3x0r) ([SQLite](https://github.com/d3x0r/gun-db))**; **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; **[hillct](https://github.com/hillct) (Docker)**; **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[JuniperChicago](https://github.com/JuniperChicago) ([cycle.js bindings](https://github.com/JuniperChicago/cycle-gun))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; **[kristianmandrup](https://github.com/kristianmandrup) ([edge](https://github.com/kristianmandrup/gun-edge))**; **[Lightnet](https://github.com/Lightnet)** ([Awesome Vue User Examples](https://glitch.com/edit/#!/jsvuegunui?path=README.md:1:0) & [User Kitchen Sink Playground](https://gdb-auth-vue-node.glitch.me/)); **[lmangani](https://github.com/lmangani) ([Cytoscape Visualizer](https://github.com/lmangani/gun-scape), [Cassandra](https://github.com/lmangani/gun-cassandra), [Fastify](https://github.com/lmangani/fastify-gundb), [LetsEncrypt](https://github.com/lmangani/polyGun-letsencrypt))**; **[mhelander](https://github.com/mhelander) ([SEA](https://github.com/amark/gun/blob/master/sea.js))**; [omarzion](https://github.com/omarzion) ([Sticky Note App](https://github.com/omarzion/stickies)); [PsychoLlama](https://github.com/PsychoLlama) ([LevelDB](https://github.com/PsychoLlama/gun-level)); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; **[robertheessels](https://github.com/swifty) ([gun-p2p-auth](https://github.com/swifty/gun-p2p-auth))**; **[rogowski](https://github.com/rogowski) (AXE)**; [sbeleidy](https://github.com/sbeleidy); **[sbiaudet](https://github.com/sbiaudet) ([C# Port](https://github.com/sbiaudet/cs-gun))**; **[Sean Matheson](https://github.com/ctrlplusb) ([Observable/RxJS/Most.js bindings](https://github.com/ctrlplusb/gun-most))**; **[Shadyzpop](https://github.com/Shadyzpop) ([React Native example](https://github.com/amark/gun/tree/master/examples/react-native))**; **[sjones6](https://github.com/sjones6) ([Flint](https://github.com/sjones6/gun-flint))**; RIP **[Stefdv](https://github.com/stefdv) (Polymer/web components)**; **[zrrrzzt](https://github.com/zrrrzzt) ([JWT Auth](https://gist.github.com/zrrrzzt/6f88dc3cedee4ee18588236756d2cfce))**; **[xmonader](https://github.com/xmonader) ([Python Port](https://github.com/xmonader/pygundb))**;
|
||||
**[BrockAtkinson](https://github.com/BrockAtkinson) ([brunch config](https://github.com/BrockAtkinson/brunch-gun))**; **[Brysgo](https://github.com/brysgo) ([GraphQL](https://github.com/brysgo/graphql-gun))**; **[d3x0r](https://github.com/d3x0r) ([SQLite](https://github.com/d3x0r/gun-db))**; **[forrestjt](https://github.com/forrestjt) ([file.js](https://github.com/amark/gun/blob/master/lib/file.js))**; **[JosePedroDias](https://github.com/josepedrodias) ([graph visualizer](http://acor.sl.pt:9966))**; **[JuniperChicago](https://github.com/JuniperChicago) ([cycle.js bindings](https://github.com/JuniperChicago/cycle-gun))**; **[jveres](https://github.com/jveres) ([todoMVC](https://github.com/jveres/todomvc))**; **[kristianmandrup](https://github.com/kristianmandrup) ([edge](https://github.com/kristianmandrup/gun-edge))**; [PsychoLlama](https://github.com/PsychoLlama) ([LevelDB](https://github.com/PsychoLlama/gun-level)); **[RangerMauve](https://github.com/RangerMauve) ([schema](https://github.com/gundb/gun-schema))**; **[robertheessels](https://github.com/swifty) ([gun-p2p-auth](https://github.com/swifty/gun-p2p-auth))**; [sbeleidy](https://github.com/sbeleidy); **[Sean Matheson](https://github.com/ctrlplusb) ([Observable/RxJS/Most.js bindings](https://github.com/ctrlplusb/gun-most))**; **[Stefdv](https://github.com/stefdv) (Polymer/web components)**; **[sjones6](https://github.com/sjones6) ([Flint](https://github.com/sjones6/gun-flint))**;
|
||||
|
||||
I am missing many others, apologies, will be adding them soon! This list is infinitely old & way out of date, if you want to be listed in it please make a PR! :)
|
||||
|
||||
## Testing
|
||||
|
||||
You will need to `npm install -g mocha` first. Then in the gun root folder run `npm test`. Tests will trigger persistent writes to the DB, so subsequent runs of the test will fail. You must clear the DB before running the tests again. This can be done by running `rm -rf *data*` command in the project directory.
|
||||
|
||||
## Shims
|
||||
|
||||
> These are only needed for NodeJS & React Native, they shim the native Browser WebCrypto API.
|
||||
|
||||
If you want to use [SEA](https://gun.eco/docs/SEA) for `User` auth and security, you will need to install:
|
||||
|
||||
`npm install @peculiar/webcrypto --save`
|
||||
|
||||
Please see [our React Native docs](https://gun.eco/docs/React-Native) for installation instructions!
|
||||
|
||||
Then you can require [SEA](https://gun.eco/docs/SEA) without an error:
|
||||
|
||||
```javascript
|
||||
GUN = require('gun/gun');
|
||||
SEA = require('gun/sea');
|
||||
```
|
||||
I am missing many others, apologies, will be adding them soon!
|
||||
|
||||
## Deploy
|
||||
|
||||
> Note: The default examples that get auto-deployed on `npm start` CDN-ify all GUN files, modules, & storage.
|
||||
|
||||
> Note: Moving forward, AXE will start to automatically cluster your peer into a shared DHT. You may want to disable this to run an isolated network.
|
||||
|
||||
> Note: When deploying a web application using GUN on a cloud provider, you may have to set `CI=false` in your `.env`. This prevents GUN-specific warnings from being treated as errors when deploying your app. You may also resolve this by modifying your webpack config to not try to build the GUN dependencies.
|
||||
|
||||
To quickly spin up a GUN relay peer for your development team, utilize [Heroku](http://heroku.com), [Docker](http://docker.com), or any others listed below. Or some variant thereof [Dokku](http://dokku.viewdocs.io/dokku/), K8s, etc. ! Or use all of them so your relays are decentralized too!
|
||||
|
||||
### Linux
|
||||
|
||||
`SSH` into the home directory of a clean OS install with `sudo` ability. Set any environment variables you need (see below), then do:
|
||||
|
||||
```bash
|
||||
curl -o- https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash
|
||||
```
|
||||
|
||||
> Read [install.sh](https://github.com/amark/gun/blob/master/examples/install.sh) first!
|
||||
> If `curl` is not found, *copy&paste* the contents of install.sh into your ssh.
|
||||
|
||||
You can now safely `CTRL+A+D` to escape without stopping the peer. To stop everything `killall screen` or `killall node`.
|
||||
|
||||
Environment variables may need to be set like `export HTTPS_CERT=~/cert.pem HTTPS_KEY=~/key.pem PORT=443`. You can also look at a sample [nginx](https://gun.eco/docs/nginx) config. For production deployments, you probably will want to use something like `pm2` or better to keep the peer alive after machine reboots.
|
||||
|
||||
### [Dome](https://www.trydome.io/)
|
||||
[Deploy GUN in one-click](https://app.trydome.io/signup?package=gun) with [Dome](https://trydome.io) and receive a free trial:
|
||||
|
||||
[](https://app.trydome.io/signup?package=gun)
|
||||
To quickly spin up a Gun test server for your development team, utilize either [Heroku](http://heroku.com) or [Docker](http://docker.com) or any variant thereof [Dokku](http://dokku.viewdocs.io/dokku/), [Flynn.io](http://flynn.io), [now.sh](https://zeit.co/now), etc. !
|
||||
|
||||
### [Heroku](https://www.heroku.com/)
|
||||
|
||||
[](https://heroku.com/deploy?template=https://github.com/amark/gun)
|
||||
|
||||
> Heroku deletes your data every 15 minutes, one way to fix this is by adding [cheap storage](https://gun.eco/docs/Using-Amazon-S3-for-Storage).
|
||||
|
||||
Or:
|
||||
|
||||
```bash
|
||||
@ -281,24 +153,25 @@ heroku create
|
||||
git push -f heroku HEAD:master
|
||||
```
|
||||
|
||||
Then visit the URL in the output of the 'heroku create' step, in a browser. Make sure to set any environment config vars in the settings tab.
|
||||
Then visit the URL in the output of the 'heroku create' step, in a browser.
|
||||
|
||||
### [Zeet.co](https://www.zeet.co/)
|
||||
### [Now.sh](https://zeit.co/now/)
|
||||
|
||||
[](https://deploy.zeet.co/?url=https://github.com/amark/gun)
|
||||
```bash
|
||||
npm install -g now
|
||||
now --npm amark/gun
|
||||
```
|
||||
|
||||
Then visit the URL in the output of the 'now --npm' step, in your browser.
|
||||
|
||||
### [Docker](https://www.docker.com/)
|
||||
|
||||
> Warning: Docker image is community contributed and may be old with missing security updates, please check version numbers to compare.
|
||||
|
||||
[](https://hub.docker.com/r/gundb/gun/) [](https://microbadger.com/images/gundb/gun "Get your own image badge on microbadger.com") [](https://hub.docker.com/r/gundb/gun/) [](https://hub.docker.com/r/gundb/gun/)
|
||||
[](https://hub.docker.com/r/gundb/gun/) [](https://microbadger.com/images/gundb/gun "Get your own image badge on microbadger.com") [](https://hub.docker.com/r/gundb/gun/) [](https://hub.docker.com/r/gundb/gun/)
|
||||
|
||||
Pull from the [Docker Hub](https://hub.docker.com/r/gundb/gun/) [](https://microbadger.com/images/gundb/gun). Or:
|
||||
|
||||
```bash
|
||||
docker run -p 8765:8765 gundb/gun
|
||||
docker run -p 8080:8080 gundb/gun
|
||||
```
|
||||
|
||||
Or build the [Docker](https://docs.docker.com/engine/installation/) image locally:
|
||||
@ -307,17 +180,17 @@ Or build the [Docker](https://docs.docker.com/engine/installation/) image locall
|
||||
git clone https://github.com/amark/gun.git
|
||||
cd gun
|
||||
docker build -t myrepo/gundb:v1 .
|
||||
docker run -p 8765:8765 myrepo/gundb:v1
|
||||
docker run -p 8080:8080 myrepo/gundb:v1
|
||||
```
|
||||
|
||||
Or, if you prefer your Docker image with metadata labels (Linux/Mac only):
|
||||
|
||||
```bash
|
||||
npm run docker
|
||||
docker run -p 8765:8765 username/gun:git
|
||||
docker run -p 8080:8080 usenameHere/gun:git
|
||||
```
|
||||
|
||||
Then visit [http://localhost:8765](http://localhost:8765) in your browser.
|
||||
Then visit [http://localhost:8080](http://localhost:8080) in your browser.
|
||||
|
||||
## License
|
||||
|
||||
|
25
RELEASE.md
@ -1,25 +0,0 @@
|
||||
Every push or pull request will
|
||||
|
||||
- run the tests
|
||||
|
||||
Every push to master will
|
||||
|
||||
- run the tests
|
||||
- publish the latest docker image to dockerhub
|
||||
|
||||
Creating a tag that starts with `v` will
|
||||
|
||||
- create a new github release
|
||||
- publish the release to npm
|
||||
- publish the release to dockerhub
|
||||
|
||||
Creating a release from the github web interface will
|
||||
|
||||
- publish the release to npm
|
||||
- publish the release to dockerhub
|
||||
|
||||
Creating the release for version `0.2021.001` from the command line works as follows
|
||||
|
||||
git tag v0.2021.001
|
||||
git push --tags
|
||||
|
47
SECURITY.md
@ -1,47 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Introduction
|
||||
|
||||
Security is our top priority. We are committed to ensuring that our project is as secure as possible for everyone who uses it. This document outlines our security policy and procedures for dealing with security issues.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
We provide security updates for the following versions of our project:
|
||||
|
||||
| Version | Supported |
|
||||
| ------- | ------------------ |
|
||||
| 0.2020.x| :white_check_mark: |
|
||||
| < 0.2020| :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
If you discover a vulnerability, we would like to know about it so we can take steps to address it as quickly as possible.
|
||||
|
||||
### Report Format
|
||||
|
||||
When reporting vulnerabilities, please include the following details:
|
||||
|
||||
- Description of the vulnerability
|
||||
- Steps to reproduce the issue
|
||||
- Potential impact if left unaddressed
|
||||
- Suggested mitigation or resolution if any
|
||||
|
||||
### Response Time
|
||||
|
||||
We aim to confirm the receipt of your vulnerability report within 48 hours. Depending on the severity and complexity of the issue, we strive to investigate the issue and provide an initial response within a week.
|
||||
|
||||
### Disclosure Policy
|
||||
|
||||
If the vulnerability is confirmed, we will work on a fix and plan a release. We ask that you do not publicly disclose the issue until it has been addressed by us.
|
||||
|
||||
## Security Practices
|
||||
|
||||
We follow industry-standard security practices, including regular audits of the services and features we provide, to maintain the trust of our users.
|
||||
|
||||
## Security Updates
|
||||
|
||||
We will communicate any security updates through our standard communication channels, including our project's release notes and official website.
|
||||
|
||||
## Conclusion
|
||||
|
||||
We greatly value the work of security researchers and believe that responsible disclosure of vulnerabilities is a valuable contribution to the security of the Internet. We encourage users to contribute to the security of our project by reporting any security-related issues to us.
|
14
app.json
@ -1,18 +1,8 @@
|
||||
{
|
||||
"name": "gun-server",
|
||||
"website": "http://gun.eco/",
|
||||
"website": "http://gun.js.org",
|
||||
"repository": "https://github.com/amark/gun",
|
||||
"logo": "https://avatars3.githubusercontent.com/u/8811914",
|
||||
"keywords": ["node", "gun", "gunDB", "database","graph","offline-first"],
|
||||
"description": "Javascript, Offline-First Javascript Graph Database Server Peer",
|
||||
"env": {
|
||||
"NPM_CONFIG_PRODUCTION": {
|
||||
"description": "If you do not want default features, set to \"true\".",
|
||||
"value": "false"
|
||||
},
|
||||
"PEERS": {
|
||||
"description": "Comma-separated list of peer urls to connect to",
|
||||
"required": false
|
||||
}
|
||||
}
|
||||
"description": "Javascript, Offline-First Javascript Graph Database Server Peer"
|
||||
}
|
||||
|
239
as.js
@ -1,239 +0,0 @@
|
||||
;(function(){
|
||||
function as(el, gun, cb, opt){
|
||||
el = $(el);
|
||||
if(gun === as.gui && as.el && as.el.is(el)){ return }
|
||||
|
||||
opt = opt || {};
|
||||
opt.match = opt.match || '{{ ';
|
||||
opt.end = opt.end || ' }}';
|
||||
;(function(){ // experimental
|
||||
function nest(t, s,e, r, i,tmp,u){
|
||||
if(r && !r.length){ return t||'' }
|
||||
if(!t){ return [] }
|
||||
e = e || s;
|
||||
i = t.indexOf(s, i||0);
|
||||
if(0 > i){ return [] }
|
||||
tmp = t.indexOf(e, i+1);
|
||||
if(!r){ return [t.slice(i+s.length, tmp)].concat(nest(t, s,e, r, tmp,tmp,u)) }
|
||||
return t.slice(0,i)+r[0]+nest(t.slice(tmp+e.length), s,e, r.slice(1), 0,tmp,u);
|
||||
}
|
||||
|
||||
/* experimental */
|
||||
function template(tag, attr){
|
||||
var html = (tag = $(tag))[0].outerHTML, sub, tmp;
|
||||
if(html && (0 > html.indexOf(opt.match))){ return }
|
||||
if(!attr){
|
||||
$.each(tag[0].attributes, function(i,v){
|
||||
if(!v){ return }
|
||||
if(!nest(v.value, opt.match, opt.end).length){ return }
|
||||
template(tag, v.name)
|
||||
});
|
||||
if((sub = tag.children()).length){
|
||||
return sub.each(function(){ template(this) });
|
||||
}
|
||||
}
|
||||
var data = [], plate = attr? tag.attr(attr) : tag.html();
|
||||
tmp = nest(plate, opt.match, opt.end);
|
||||
if(!tmp.length){ return }
|
||||
$.each(tmp, function(pos, match){
|
||||
var expr = match.split(' ');
|
||||
var path = (expr[0]).split('.');
|
||||
if(expr = expr.slice(1).join(' ')){
|
||||
expr = new Function("_", "b", "return (_)" + expr);
|
||||
}
|
||||
var val = (expr && expr('')) || '';
|
||||
data.push(val);
|
||||
if(!attr){ tag.text(val) }
|
||||
|
||||
var ref = gun, sup = [], tmp;
|
||||
if(tmp = tag.attr('name')){ sup.push(tmp) }
|
||||
tag.parents("[name]").each(function(){
|
||||
sup.push($(this).attr('name'));
|
||||
});
|
||||
$.each(path = sup.reverse().concat(path), function(i,v){
|
||||
ref = ref.get(v);
|
||||
});
|
||||
ref.on(function(v){
|
||||
v = data[pos] = expr? expr(v) : v;
|
||||
var tmp = nest(plate, opt.match, opt.end, data);
|
||||
if(attr){
|
||||
tag.attr(attr, tmp);
|
||||
} else {
|
||||
tag.text(tmp);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
template(el);
|
||||
|
||||
}());
|
||||
|
||||
as.gui = gun;
|
||||
as.el = el;
|
||||
if(el.data('as')){
|
||||
el.html(el.data('as').fresh);
|
||||
} else {
|
||||
el.data('as', {
|
||||
fresh: el.html()
|
||||
})
|
||||
}
|
||||
el.find("[name]").each(function(){
|
||||
if($(this).find("[name]").length){ return }
|
||||
var name = $(this),
|
||||
parents = name.parents("[name]"),
|
||||
path = [],
|
||||
ref = gun;
|
||||
|
||||
path.push(name.attr('name'));
|
||||
parents.each(function(){
|
||||
path.push($(this).attr('name'));
|
||||
});
|
||||
path = path.reverse();
|
||||
|
||||
path.forEach(function(key){
|
||||
if('#' === key){
|
||||
ref = ref.map()
|
||||
} else {
|
||||
ref = ref.get(key);
|
||||
}
|
||||
});
|
||||
|
||||
var many = path.slice().reverse().indexOf('#'), model;
|
||||
many = (0 < ++many)? many : false;
|
||||
if(many){
|
||||
model = name.closest("[name='#']");
|
||||
model = model.data('model') || model.data('model', {$: model.clone(), on: model.parent(), has: {}}).hide().data('model');
|
||||
}
|
||||
|
||||
ref.get(function(at){
|
||||
var data = at.put, key = at.get, gui = at.gun || at.$, ui = name, back;
|
||||
if(model){
|
||||
ui = model.has[(gui._).id];
|
||||
if(!ui){
|
||||
back = gui.back(many - 1);
|
||||
ui = model.has[(back._).id];
|
||||
if(!ui){
|
||||
if(!(back._).get){ return }
|
||||
ui = (model.has[(back._).id] = model.$.clone(true).prependTo(model.on));
|
||||
}
|
||||
ui = ui.find("[name='"+key+"']").first();
|
||||
model.has[(gui._).id] = ui;
|
||||
}
|
||||
}
|
||||
ui.data('gun', gui);
|
||||
if(ui.data('was') === data){ return }
|
||||
if(many && ui.is('.sort')){
|
||||
var up = ui.closest("[name='#']");
|
||||
var tmp = as.sort(data, up.parent().children().last());
|
||||
tmp? up.insertAfter(tmp) : up.prependTo(up.parent());
|
||||
}
|
||||
if(as.lock === gui){ return }
|
||||
if(!(data && data instanceof Object)){
|
||||
(ui[0] && u === ui[0].value)? ui.text(data) : ui.val(data);
|
||||
}
|
||||
ui.data('was', data);
|
||||
if(cb){
|
||||
cb(data, key, ui);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
as.wait = function(cb, wait, to){
|
||||
return function(a,b,c){
|
||||
var me = as.typing = this;
|
||||
clearTimeout(to);
|
||||
to = setTimeout(function(){
|
||||
cb.call(me, a,b,c);
|
||||
as.typing = me = false;
|
||||
}, wait || 200);
|
||||
}
|
||||
}
|
||||
as.sort = function sort(num, li){ return parseFloat(num) >= parseFloat($(li).find('.sort').text() || -Infinity)? li : sort(num, li.prev()) }
|
||||
$(document).on('keyup', 'input, textarea, [contenteditable]', as.wait(function(){
|
||||
var el = $(this);
|
||||
var data = (el[0] && u === el[0].value)? el.text() : el.val();
|
||||
var g = el.data('gun');
|
||||
if(!g){ return }
|
||||
as.lock = g;
|
||||
g.put(data);
|
||||
}, 99));
|
||||
//$(document).on('submit', 'form', function(e){ e.preventDefault() });
|
||||
var u;
|
||||
window.as = as;
|
||||
$.as = as;
|
||||
}());
|
||||
|
||||
;(function(){
|
||||
$(document).on('click', 'a, button', function(e){
|
||||
var tmp = $(this).attr('href') || '';
|
||||
if(0 === tmp.indexOf('http')){ return }
|
||||
e.preventDefault();
|
||||
r(tmp);
|
||||
});
|
||||
function r(href){
|
||||
if(!href){ return }
|
||||
if(href[0] == '#'){ href = href.slice(1) }
|
||||
var h = href.split('/')[0];
|
||||
$('.page').hide();
|
||||
$('#' + h).show();
|
||||
if(r.on === h){ return }
|
||||
location.hash = href;
|
||||
(r.page[h] || {on:function(){}}).on();
|
||||
r.on = h;
|
||||
return r;
|
||||
};
|
||||
r.page = function(h, cb){
|
||||
r.page[h] = r.page[h] || {on: cb};
|
||||
return r;
|
||||
}
|
||||
r.render = function(id, model, onto, data){
|
||||
var $data = $(
|
||||
$('#' + id).get(0) ||
|
||||
$('.model').find(model).clone(true).attr('id', id).appendTo(onto)
|
||||
);
|
||||
$.each(data, function(field, val){
|
||||
if($.isPlainObject(val)){ return }
|
||||
$data.find("[name='" + field + "']").val(val).text(val);
|
||||
});
|
||||
return $data;
|
||||
}
|
||||
window.onhashchange = function(){ r(location.hash.slice(1)) };
|
||||
$.as && ($.as.route = r);
|
||||
if(window.as){
|
||||
as.route = r;
|
||||
} else {
|
||||
$.route = r;
|
||||
}
|
||||
}());
|
||||
|
||||
;$(function(){
|
||||
$('.page').not(':first').hide();
|
||||
$.as.route(location.hash.slice(1));
|
||||
$(JOY.start = JOY.start || function(){ $.as(document, gun, null, JOY.opt) });
|
||||
|
||||
if($('body').attr('peers')){ (console.warn || console.log)('Warning: Please upgrade <body peers=""> to https://github.com/eraeco/joydb#peers !') }
|
||||
|
||||
});
|
||||
;(function(){ // need to isolate into separate module!
|
||||
var joy = window.JOY = function(){};
|
||||
joy.auth = function(a,b,cb,o){
|
||||
if(!o){ o = cb ; cb = 0 }
|
||||
if(o === true){
|
||||
gun.user().create(a, b);
|
||||
return;
|
||||
}
|
||||
gun.user().auth(a,b, cb,o);
|
||||
}
|
||||
|
||||
var opt = joy.opt = window.CONFIG || {}, peers;
|
||||
$('link[type=peer]').each(function(){ (peers || (peers = [])).push($(this).attr('href')) });
|
||||
!window.gun && (opt.peers = opt.peers || peers || (function(){
|
||||
(console.warn || console.log)('Warning: No peer provided, defaulting to DEMO peer. Do not run in production, or your data will be regularly wiped, reset, or deleted. For more info, check https://github.com/eraeco/joydb#peers !');
|
||||
return ['https://gunjs.herokuapp.com/gun'];
|
||||
}()));
|
||||
window.gun = window.gun || Gun(opt);
|
||||
|
||||
gun.on('auth', function(ack){
|
||||
console.log("Your namespace is publicly available at", ack.soul);
|
||||
});
|
||||
}());
|
109
axe.js
@ -1,109 +0,0 @@
|
||||
;(function(){
|
||||
|
||||
var sT = setTimeout || {}, u;
|
||||
if(typeof window !== ''+u){ sT.window = window }
|
||||
var AXE = (sT.window||'').AXE || function(){};
|
||||
if(AXE.window = sT.window){ AXE.window.AXE = AXE }
|
||||
|
||||
var Gun = (AXE.window||'').GUN || require('./gun');
|
||||
(Gun.AXE = AXE).GUN = AXE.Gun = Gun;
|
||||
|
||||
//if(!Gun.window){ try{ require('./lib/axe') }catch(e){} }
|
||||
if(!Gun.window){ require('./lib/axe') }
|
||||
|
||||
Gun.on('opt', function(at){ start(at) ; this.to.next(at) }); // make sure to call the "next" middleware adapter.
|
||||
|
||||
function start(root){
|
||||
if(root.axe){ return }
|
||||
var opt = root.opt, peers = opt.peers;
|
||||
if(false === opt.axe){ return }
|
||||
if(!Gun.window){ return } // handled by ^ lib/axe.js
|
||||
var w = Gun.window, lS = w.localStorage || opt.localStorage || {}, loc = w.location || opt.location || {}, nav = w.navigator || opt.navigator || {};
|
||||
var axe = root.axe = {}, tmp, id;
|
||||
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
|
||||
|
||||
tmp = peers[id = loc.origin + '/gun'] = peers[id] || {};
|
||||
tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0;
|
||||
tmp = peers[id = 'http://localhost:8765/gun'] = peers[id] || {};
|
||||
tmp.id = tmp.url = id; tmp.retry = tmp.retry || 0;
|
||||
Gun.log.once("AXE", "AXE enabled: Trying to find network via (1) local peer (2) last used peers (3) a URL parameter, and last (4) hard coded peers.");
|
||||
Gun.log.once("AXEWarn", "Warning: AXE is in alpha, use only for testing!");
|
||||
var last = lS.peers || ''; if(last){ last += ' ' }
|
||||
last += ((loc.search||'').split('peers=')[1]||'').split('&')[0];
|
||||
|
||||
root.on('bye', function(peer){
|
||||
this.to.next(peer);
|
||||
if(!peer.url){ return } // ignore WebRTC disconnects for now.
|
||||
if(!nav.onLine){ peer.retry = 1 }
|
||||
if(peer.retry){ return }
|
||||
if(axe.fall){ delete axe.fall[peer.url || peer.id] }
|
||||
(function next(){
|
||||
if(!axe.fall){ setTimeout(next, 9); return } // not found yet
|
||||
var fall = Object.keys(axe.fall||''), one = fall[(Math.random()*fall.length) >> 0];
|
||||
if(!fall.length){ lS.peers = ''; one = 'https://gunjs.herokuapp.com/gun' } // out of peers
|
||||
if(peers[one]){ next(); return } // already choose
|
||||
mesh.hi(one);
|
||||
}());
|
||||
});
|
||||
|
||||
root.on('hi', function(peer){ // TEMPORARY! Try to connect all peers.
|
||||
this.to.next(peer);
|
||||
if(!peer.url){ return } // ignore WebRTC disconnects for now.
|
||||
return; // DO NOT COMMIT THIS FEATURE YET! KEEP TESTING NETWORK PERFORMANCE FIRST!
|
||||
(function next(){
|
||||
if(!peer.wire){ return }
|
||||
if(!axe.fall){ setTimeout(next, 9); return } // not found yet
|
||||
var one = (next.fall = next.fall || Object.keys(axe.fall||'')).pop();
|
||||
if(!one){ return }
|
||||
setTimeout(next, 99);
|
||||
mesh.say({dam: 'opt', opt: {peers: one}}, peer);
|
||||
}());
|
||||
});
|
||||
|
||||
function found(text){
|
||||
|
||||
axe.fall = {};
|
||||
((text||'').match(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/ig)||[]).forEach(function(url){
|
||||
axe.fall[url] = {url: url, id: url, retry: 0}; // RETRY
|
||||
});
|
||||
|
||||
return;
|
||||
|
||||
// TODO: Finish porting below? Maybe not.
|
||||
|
||||
Object.keys(last.peers||'').forEach(function(key){
|
||||
tmp = peers[id = key] = peers[id] || {};
|
||||
tmp.id = tmp.url = id;
|
||||
});
|
||||
tmp = peers[id = 'https://guntest.herokuapp.com/gun'] = peers[id] || {};
|
||||
tmp.id = tmp.url = id;
|
||||
|
||||
var mesh = opt.mesh = opt.mesh || Gun.Mesh(root); // DAM!
|
||||
mesh.way = function(msg){
|
||||
if(root.$ === msg.$ || (msg._||'').via){
|
||||
mesh.say(msg, opt.peers);
|
||||
return;
|
||||
}
|
||||
var at = (msg.$||'')._;
|
||||
if(!at){ mesh.say(msg, opt.peers); return }
|
||||
if(msg.get){
|
||||
if(at.axe){ return } // don't ask for it again!
|
||||
at.axe = {};
|
||||
}
|
||||
mesh.say(msg, opt.peers);
|
||||
}
|
||||
}
|
||||
|
||||
if(last){ found(last); return }
|
||||
try{ fetch(((loc.search||'').split('axe=')[1]||'').split('&')[0] || loc.axe || 'https://raw.githubusercontent.com/wiki/amark/gun/volunteer.dht.md').then(function(res){
|
||||
return res.text()
|
||||
}).then(function(text){
|
||||
found(lS.peers = text);
|
||||
}).catch(function(){
|
||||
found(); // nothing
|
||||
})}catch(e){found()}
|
||||
}
|
||||
|
||||
var empty = {}, yes = true;
|
||||
try{ if(typeof module != ''+u){ module.exports = AXE } }catch(e){}
|
||||
}());
|
@ -1,4 +0,0 @@
|
||||
// if(!(typeof navigator == "undefined") && navigator.product == "ReactNative"){
|
||||
// require("./lib/mobile.js");
|
||||
// }
|
||||
module.exports = require('./gun.js');
|
217
examples/Main.js
@ -1,217 +0,0 @@
|
||||
import { render } from './iris/js/lib/preact.js';
|
||||
import { Router, route } from './iris/js/lib/preact-router.es.js';
|
||||
import { createHashHistory } from './iris/js/lib/history.production.min.js';
|
||||
import { Component } from './iris/js/lib/preact.js';
|
||||
import { Link } from './iris/js/lib/preact.match.js';
|
||||
|
||||
import Helpers from './iris/js/Helpers.js';
|
||||
import { html } from './iris/js/Helpers.js';
|
||||
import QRScanner from './iris/js/QRScanner.js';
|
||||
import PeerManager from './iris/js/PeerManager.js';
|
||||
import Session from './iris/js/Session.js';
|
||||
import { translate as t } from './iris/js/Translation.js';
|
||||
|
||||
import Settings from './iris/js/views/Settings.js';
|
||||
import LogoutConfirmation from './iris/js/views/LogoutConfirmation.js';
|
||||
import Chat from './iris/js/views/Chat.js';
|
||||
import Store from './iris/js/views/Store.js';
|
||||
import Checkout from './iris/js/views/Checkout.js';
|
||||
import Product from './iris/js/views/Product.js';
|
||||
import Login from './iris/js/views/Login.js';
|
||||
import Profile from './iris/js/views/Profile.js';
|
||||
import Group from './iris/js/views/Group.js';
|
||||
import Message from './iris/js/views/Message.js';
|
||||
import Follows from './iris/js/views/Follows.js';
|
||||
import Feed from './iris/js/views/Feed.js';
|
||||
import About from './iris/js/views/About.js';
|
||||
import Explorer from './iris/js/views/Explorer.js';
|
||||
import Contacts from './iris/js/views/Contacts.js';
|
||||
import Torrent from './iris/js/views/Torrent.js';
|
||||
|
||||
import VideoCall from './iris/js/components/VideoCall.js';
|
||||
import Identicon from './iris/js/components/Identicon.js';
|
||||
import MediaPlayer from './iris/js/components/MediaPlayer.js';
|
||||
import Footer from './iris/js/components/Footer.js';
|
||||
import State from './iris/js/State.js';
|
||||
import Icons from './iris/js/Icons.js';
|
||||
|
||||
const userAgent = navigator.userAgent.toLowerCase();
|
||||
const isElectron = (userAgent.indexOf(' electron/') > -1);
|
||||
if (!isElectron && ('serviceWorker' in navigator)) {
|
||||
window.addEventListener('load', function() {
|
||||
navigator.serviceWorker.register('iris/serviceworker.js')
|
||||
.catch(function(err) {
|
||||
// registration failed :(
|
||||
console.log('ServiceWorker registration failed: ', err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
State.init();
|
||||
Session.init({autologin: true});
|
||||
PeerManager.init();
|
||||
|
||||
Helpers.checkColorScheme();
|
||||
|
||||
const APPLICATIONS = [ // TODO: move editable shortcuts to State.local gun
|
||||
{url: '/', text: t('home'), icon: Icons.home},
|
||||
{url: '/feed', text: t('feed'), icon: Icons.feed},
|
||||
{url: '/media', text: t('media'), icon: Icons.play},
|
||||
{url: '/settings', text: t('settings'), icon: Icons.settings},
|
||||
{url: '/store', text: t('store'), icon: Icons.store},
|
||||
{url: '/explorer', text: t('explorer'), icon: Icons.folder},
|
||||
{url: '/chat', text: t('messages'), icon: Icons.chat},
|
||||
// {url: '/store', text: t('store'), icon: Icons.store}, // restore when it works!
|
||||
{},
|
||||
{url: '../stats.html', text: 'Gun node stats'},
|
||||
{url: '../iris/index.html', text: 'Iris', icon: html`<img src="iris/img/icon128.png" width=24/>`},
|
||||
{url: '../infinite-scroll/index.html', text: 'Infinite scroll'},
|
||||
{url: '../chat/index.html', text: 'Chat'},
|
||||
{url: '../game/space.html', text: 'Space'},
|
||||
{},
|
||||
{url: 'https://gun.eco/docs/', text: 'Gun documentation'},
|
||||
{url: 'https://examples.iris.to/components/', text: 'Iris web components'}
|
||||
];
|
||||
|
||||
const HomeView = () => {
|
||||
return html`
|
||||
<div class="main-view">
|
||||
<div class="centered-container public-messages-view">
|
||||
<h1>Hello, world!</h1>
|
||||
<p>Here you can find sample applications and utilities for <a href="https://github.com/amark/gun">GUN</a>.</p>
|
||||
<p>If you need any help, please feel free to join the GUN community chat: <a href="http://chat.gun.eco">http://chat.gun.eco</a></p>
|
||||
<a href="/explorer" class="msg"><div class="msg-content">
|
||||
<b>Explorer</b>
|
||||
<p>Explore the data saved on the GUN database. Open to the side while using an application and see the data change in real-time.</p>
|
||||
</div></a>
|
||||
<a class="msg" href="game/space.html"><div class="msg-content">
|
||||
<div class="img-container"><img src="iris/img/space-game.jpg"/></div>
|
||||
<b>Space</b>
|
||||
<p>Spaceflight game. Open in 2 or more browser windows.</p>
|
||||
</div></a>
|
||||
<a class="msg" href="/iris/index.html"><div class="msg-content">
|
||||
<div class="img-container"><img src="iris/img/screenshot.png"/></div>
|
||||
<b>Iris</b>
|
||||
<p>Decentralized Twitter/Instagram. Provides modular components that can be reused in other applications (including this one).</p>
|
||||
</div></a>
|
||||
<a native class="msg" href="/chat/index.html"><div class="msg-content">
|
||||
<div class="img-container"><img src="iris/img/gun-chat.jpg"/></div>
|
||||
<b>Chat</b>
|
||||
<p>Shoutbox!</p>
|
||||
</div></a>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
};
|
||||
|
||||
class MenuView extends Component {
|
||||
componentDidMount() {
|
||||
State.local.get('showMenu').on(showMenu => this.setState({showMenu}));
|
||||
}
|
||||
|
||||
render() {
|
||||
const pub = Session.getPubKey();
|
||||
return html`
|
||||
<div class="application-list ${this.state.showMenu ? 'menu-visible-xs' : ''}">
|
||||
<a href="/profile/${pub}">
|
||||
<span class="icon"><${Identicon} str=${pub} width=40/></span>
|
||||
<span class="text" style="font-size: 1.2em;border:0;margin-left: 7px;"><iris-text user="${pub}" path="profile/name" editable="false"/></span>
|
||||
</a>
|
||||
<br/><br/>
|
||||
${APPLICATIONS.map(a => {
|
||||
if (a.url) {
|
||||
return html`
|
||||
<a href=${a.url}>
|
||||
<span class="icon">${a.icon || Icons.circle}</span>
|
||||
<span class="text">${a.text}</span>
|
||||
</a>`;
|
||||
} else {
|
||||
return html`<br/><br/>`;
|
||||
}
|
||||
})}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
};
|
||||
|
||||
class Main extends Component {
|
||||
constructor() {
|
||||
super();
|
||||
this.showMenu = false;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
State.local.get('loggedIn').on(loggedIn => this.setState({loggedIn}));
|
||||
}
|
||||
|
||||
handleRoute(e) {
|
||||
let activeRoute = e.url;
|
||||
if (!activeRoute && window.location.hash) {
|
||||
return route(window.location.hash.replace('#', '')); // bubblegum fix back navigation
|
||||
}
|
||||
document.title = 'Iris';
|
||||
if (activeRoute && activeRoute.length > 1) { document.title += ' - ' + Helpers.capitalize(activeRoute.replace('/', '')); }
|
||||
State.local.get('activeRoute').put(activeRoute);
|
||||
QRScanner.cleanupScanner();
|
||||
}
|
||||
|
||||
onClickOverlay() {
|
||||
if (this.state.showMenu) {
|
||||
this.setState({showMenu: false});
|
||||
}
|
||||
}
|
||||
|
||||
toggleMenu(show) {
|
||||
this.setState({showMenu: typeof show === 'undefined' ? !this.state.showMenu : show});
|
||||
}
|
||||
|
||||
render() {
|
||||
const content = this.state.loggedIn ? html`
|
||||
<div class="visible-xs-flex" style="border-bottom:var(--sidebar-border-right)">
|
||||
<svg onClick=${() => State.local.get('showMenu').put(this.showMenu = !this.showMenu)} style="padding: 5px;cursor:pointer;" viewBox="0 -53 384 384" width="40px"><path d="m368 154.667969h-352c-8.832031 0-16-7.167969-16-16s7.167969-16 16-16h352c8.832031 0 16 7.167969 16 16s-7.167969 16-16 16zm0 0"/><path d="m368 32h-352c-8.832031 0-16-7.167969-16-16s7.167969-16 16-16h352c8.832031 0 16 7.167969 16 16s-7.167969 16-16 16zm0 0"/><path d="m368 277.332031h-352c-8.832031 0-16-7.167969-16-16s7.167969-16 16-16h352c8.832031 0 16 7.167969 16 16s-7.167969 16-16 16zm0 0"/></svg>
|
||||
</div>
|
||||
<section class="main" style="flex-direction: row;">
|
||||
<${MenuView}/>
|
||||
<div style="flex: 3; display: flex">
|
||||
<${Router} history=${createHashHistory()} onChange=${e => this.handleRoute(e)}>
|
||||
<${HomeView} path="/"/>
|
||||
<${Feed} path="/feed"/>
|
||||
<${Feed} path="/search/:term?/:type?"/>
|
||||
<${Feed} path="/media" index="media"/>
|
||||
<${Login} path="/login"/>
|
||||
<${Chat} path="/chat/:id?"/>
|
||||
<${Message} path="/post/:hash"/>
|
||||
<${Torrent} path="/torrent/:id"/>
|
||||
<${About} path="/about"/>
|
||||
<${Settings} path="/settings"/>
|
||||
<${LogoutConfirmation} path="/logout"/>
|
||||
<${Profile} path="/profile/:id?" tab="profile"/>
|
||||
<${Profile} path="/replies/:id?" tab="replies"/>
|
||||
<${Profile} path="/likes/:id?" tab="likes"/>
|
||||
<${Profile} path="/media/:id" tab="media"/>
|
||||
<${Group} path="/group/:id?"/>
|
||||
<${Store} path="/store/:store?"/>
|
||||
<${Checkout} path="/checkout/:store?"/>
|
||||
<${Product} path="/product/:product/:store"/>
|
||||
<${Product} path="/product/new" store=Session.getPubKey()/>
|
||||
<${Explorer} path="/explorer/:node"/>
|
||||
<${Explorer} path="/explorer"/>
|
||||
<${Follows} path="/follows/:id"/>
|
||||
<${Follows} followers=${true} path="/followers/:id"/>
|
||||
<${Contacts} path="/contacts"/>
|
||||
</${Router}>
|
||||
</div>
|
||||
</section>
|
||||
<${VideoCall}/>
|
||||
` : '';
|
||||
return html`
|
||||
<div id="main-content">
|
||||
${content}
|
||||
</div>
|
||||
`;
|
||||
}
|
||||
}
|
||||
|
||||
render(html`<${Main}/>`, document.body);
|
||||
|
||||
$('body').css('opacity', 1); // use opacity because setting focus on display: none elements fails
|
@ -22,8 +22,8 @@
|
||||
"@angular/router": "^4.1.0",
|
||||
"core-js": "^2.4.1",
|
||||
"express-http-proxy": "^1.0.1",
|
||||
"gun": "https://github.com/amark/gun.git#master",
|
||||
"ngx-pipes": "^2.0.5",
|
||||
"gun": "^0.7.4",
|
||||
"ngx-pipes": "^1.5.10",
|
||||
"rxjs": "^5.3.0",
|
||||
"underscore": "^1.8.3",
|
||||
"zone.js": "^0.8.9"
|
2
examples/angular/server.js
vendored
@ -1,4 +1,4 @@
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765;
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
||||
var host = process.env.OPENSHIFT_NODEJS_HOST || process.env.VCAP_APP_HOST || process.env.HOST || 'localhost';
|
||||
|
||||
var express = require('express');
|
||||
|
@ -5,7 +5,7 @@ import { pick } from 'underscore';
|
||||
export function on$(node, cleanup = true): Observable<any> {
|
||||
return Observable.fromEventPattern(
|
||||
h => {
|
||||
// there is no way to off() an on() until at least one value is triggered
|
||||
// there is no way to off() an on() until at least one value is trigerred
|
||||
// so that we can access the event listener to off() it
|
||||
const signal = { stop: false };
|
||||
node.on((data, key, at, ev) => {
|
||||
|
5318
examples/angular/yarn.lock
Normal file
@ -1,46 +0,0 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0" />
|
||||
<title>Testing AXE</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h3 id="pid"></h3>
|
||||
<script src="../gun.js"></script>
|
||||
<script src="../axe.js"></script>
|
||||
<script src="../lib/radix.js"></script>
|
||||
<script src="../lib/webrtc.js"></script>
|
||||
<!-- <script src="../sea.js"></script> -->
|
||||
<script>
|
||||
var pid = location.hash.slice(1);
|
||||
|
||||
var opt = ({
|
||||
peers: [`${location.origin}/gun`]
|
||||
});
|
||||
|
||||
if (pid) { opt.pid = pid; }
|
||||
|
||||
Gun.on('opt', function(ctx) {
|
||||
this.to.next(ctx);
|
||||
ctx.on('hi', function(opt) {
|
||||
// console.log('HI!! PEER', new Date(), opt.pid);
|
||||
setTimeout(function() {
|
||||
document.getElementById('pid').innerHTML = gun._.opt.pid;
|
||||
});
|
||||
});
|
||||
// if (pid) {
|
||||
// ctx.on('out', function(msg) {
|
||||
// msg.pid = pid;
|
||||
// this.to.next(msg);
|
||||
// });
|
||||
// }
|
||||
});
|
||||
|
||||
var gun = Gun(opt);
|
||||
//var user = gun.user();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,21 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<ul id='list'></ul>
|
||||
<form id='form'>
|
||||
<input id='who' placeholder='name'>
|
||||
<input id='what' placeholder='say'>
|
||||
<input type='submit' value='send'>
|
||||
</form>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/axe.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/emojione@4.0.0/lib/js/emojione.min.js"></script>
|
||||
<script>
|
||||
gun = GUN(), chat = gun.get("note" + location.hash.replace('#','/')), view = document;
|
||||
form.onsubmit = (eve) => { chat.set(who.value+': '+what.value), eve.preventDefault(what.value = "") }
|
||||
chat.map().on(function show(data, id){
|
||||
(view.line = view.getElementById(id) || view.createElement("li")).id = id;
|
||||
list.appendChild(view.line).innerText = emojione.shortnameToUnicode(data);
|
||||
window.scroll(0, list.offsetHeight);
|
||||
(list.beep = new SpeechSynthesisUtterance()).text = "new";
|
||||
list.beep.rate = 10, list.beep.pitch = 2, window.speechSynthesis.speak(list.beep);
|
||||
});
|
||||
</script>
|
@ -1,2 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<p>Moved to <a href="./chat.html">./chat.html</a>!</p>
|
@ -1,38 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<center>must press play or unmute on new videos to accept meeting</center>
|
||||
<center id="videos">
|
||||
<video id="me" width="100%" controls autoplay playsinline muted></video>
|
||||
</center>
|
||||
<center>Stream <select id="select"><option id="from">from</option></select></center>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
<script src="../../../gun/lib/webrtc.js"></script>
|
||||
|
||||
<script>;(async function(){
|
||||
streams = {}, gun = Gun(location.origin + '/gun'); //gun = GUN();
|
||||
mesh = gun.back('opt.mesh');
|
||||
|
||||
(await (me.stream = navigator.mediaDevices).enumerateDevices()).forEach((device,i) => {
|
||||
if('videoinput' !== device.kind){ return }
|
||||
var opt = $(from).clone().prependTo('select').get(0);
|
||||
$(opt).text(opt.id = device.label || 'Camera '+i);
|
||||
opt.value = device.deviceId;
|
||||
});
|
||||
|
||||
$('select').on('change', async eve => { $(from).text('Off'); // update label
|
||||
if('Off' == select.value){ return me.srcObject.getTracks()[0].stop() }
|
||||
mesh.hi(me.srcObject = await me.stream.getUserMedia({ audio: true,
|
||||
video: (select.value && {deviceId: {exact: select.value}}) || {facingMode: "environment"}
|
||||
}));
|
||||
});
|
||||
|
||||
gun.on('rtc', async function(eve){ var ui, src;
|
||||
console.log("?RTC?", eve.peer && eve.peer.connectionState, eve);
|
||||
if(!(src = eve.streams)){ return }
|
||||
ui = $('#v'+(src=src[0]).id).get(0) || $(me).clone().attr('id', 'v'+src.id).prependTo('#videos').get(0); // reuse or create video element
|
||||
ui.srcObject = src;
|
||||
});
|
||||
}());</script>
|
@ -1,9 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<style>html, body, textarea { width: 100%; height: 100%; padding: 0; margin: 0; }</style>
|
||||
<textarea id="view" placeholder="write here..."></textarea>
|
||||
<script src="../../../gun/gun.js"></script><script>
|
||||
gun = GUN(location.origin + '/gun');
|
||||
note = gun.get('note').get(location.hash.replace('#','')||1);
|
||||
view.oninput = () => { note.put(view.value) };
|
||||
note.on((data) => { view.value = data });
|
||||
</script>
|
@ -1,2 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<p>Moved to <a href="./note.html">./note.html</a>!</p>
|
@ -1,148 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
<!-- script src="../../../gun/axe.js"></script -->
|
||||
<script> // main init!
|
||||
var app = {
|
||||
view: $, // replace with not jquery!
|
||||
data: GUN('http://localhost:8765/gun'), // peer-to-peer database!
|
||||
};
|
||||
app.user = app.data.user().recall({sessionStorage: true});
|
||||
</script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="login" class="center pad">
|
||||
<style>
|
||||
#login input {
|
||||
max-width: 6em;
|
||||
}
|
||||
</style>
|
||||
<form id="sign" onsubmit="app.login(event)">
|
||||
<input id="alias" placeholder="username" class="jot rim">
|
||||
<input id="pass" type="password" placeholder="passphrase" class="jot rim">
|
||||
<input id="in" type="submit" value="sign in" class="green whitet act gap sap rim">
|
||||
<input id="up" type="button" value="sign up" onclick="app.register()" class="act gap sap rim">
|
||||
</form>
|
||||
<script>
|
||||
app.login = function(eve){
|
||||
if(app.error(eve)){ return }
|
||||
app.data.user().auth(
|
||||
app.view('#alias').val(),
|
||||
app.view('#pass').val(),
|
||||
app.error
|
||||
);
|
||||
};
|
||||
|
||||
app.register = function(eve){
|
||||
app.data.user().create(
|
||||
app.view('#alias').val(),
|
||||
app.view('#pass').val(),
|
||||
app.login
|
||||
);
|
||||
};
|
||||
|
||||
app.data.on('auth', function(eve){
|
||||
app.view('#sign').hide(); // hide login form upon logging in.
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="poll" class="pad">
|
||||
<style>
|
||||
#poll {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
#poll div {
|
||||
margin: 1%;
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
(window.onhashchange = async function(){
|
||||
app.poll = app.data.get(location.hash.slice(1));
|
||||
app.poll.map().on(function(data, id){
|
||||
app.render(id = 'p'+String.hash(id), '.q', '#poll', data).css({order: data.how}).data('as',{$:this});
|
||||
console.log("poll?", id, data);
|
||||
});
|
||||
})();
|
||||
app.render = function(id, model, onto, data){
|
||||
var ui = $(
|
||||
$('#'+id).get(0) ||
|
||||
$('.model').find(model).clone(true).attr('id', id).appendTo(onto)
|
||||
);
|
||||
$.each(data, function(field, val){
|
||||
if($.isPlainObject(val)){ return }
|
||||
ui.find("[name='" + field + "']").val(val).text(val);
|
||||
});
|
||||
return ui;
|
||||
}
|
||||
</script>
|
||||
<div class="model">
|
||||
<div class="q">
|
||||
<span name="what"></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="make" class="pad">
|
||||
<style>
|
||||
#make #add {
|
||||
border-radius: 100%;
|
||||
width: 2em;
|
||||
height: 2em;
|
||||
line-height: 0em;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
<button id="add" onclick="app.add()" class="green whitet act">+</button>
|
||||
<span class="hint">add new title, text, question...</span>
|
||||
<script>
|
||||
app.add = async function(){
|
||||
if(app.error(app.user)){ return }
|
||||
var tmp = await (app.poll = app.poll || app.data.get(location.hash.slice(1)));
|
||||
if(!tmp){ app.poll = app.user.get('poll').set({}) }
|
||||
app.poll.set({how: tmp = Object.keys(tmp||'').length || 1, what: "Question " + tmp });
|
||||
if(!location.hash){ location.hash = (await app.poll)._['#'] }
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<span id="error">
|
||||
<span id="err"></span>
|
||||
<script>
|
||||
app.error = function(eve){
|
||||
app.view('#err').text('').hide();
|
||||
if(!eve){ return }
|
||||
if(eve.preventDefault){
|
||||
eve.preventDefault();
|
||||
return;
|
||||
}
|
||||
if(eve._ && !eve.is){ eve = {err: "Not signed in!"} }
|
||||
if(!eve.err){ return }
|
||||
app.view('#err').text(eve.err).show();
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
</span>
|
||||
|
||||
<style>
|
||||
#error { position: fixed; top: 0; width: 100%; text-align: center; background: white; }
|
||||
</style>
|
||||
<link rel="stylesheet" href="../style.css"/>
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css?family=Oxygen');
|
||||
html, body { font-family: "Oxygen", sans-serif; }
|
||||
</style>
|
||||
</body>
|
||||
</html>
|
@ -1,45 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<h1>Posts</h1>
|
||||
|
||||
<form id="sign">
|
||||
<input id="alias" placeholder="username">
|
||||
<input id="pass" type="password" placeholder="passphrase">
|
||||
<input id="in" type="submit" value="sign in">
|
||||
<input id="up" type="button" value="sign up">
|
||||
</form>
|
||||
|
||||
<form id="said">
|
||||
<input id="say" placeholder="write here...">
|
||||
<input id="speak" type="submit" value="say">
|
||||
</form>
|
||||
|
||||
<ul></ul>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
<script src="../../../gun/axe.js"></script>
|
||||
|
||||
<script>
|
||||
gun = GUN(), user = gun.user().recall({sessionStorage: true});
|
||||
|
||||
$('#sign').on('submit', login);
|
||||
$('#up').on('click', () => { user.create($('#alias').val(), $('#pass').val(), login) });
|
||||
function login(eve){
|
||||
eve.preventDefault();
|
||||
user.auth($('#alias').val(), $('#pass').val());
|
||||
};
|
||||
|
||||
gun.on('auth', () => { $('#sign').hide(), user.get('said').map().on(show) });
|
||||
function show(data, id){
|
||||
return ($('#' + id).get(0) || $('<li>').attr('id', id).prependTo('ul')).text(data);
|
||||
};
|
||||
|
||||
$('#said').on('submit', (eve) => {
|
||||
eve.preventDefault();
|
||||
if(!user.is){ return }
|
||||
user.get('said').set($('#say').val());
|
||||
$('#say').val("");
|
||||
});
|
||||
</script>
|
@ -1,235 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<style>
|
||||
html, body {
|
||||
background: rgb(245, 245, 245);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
div {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
#top {
|
||||
background: #283e4a;
|
||||
height: 52px;
|
||||
width: 100%;
|
||||
}
|
||||
.box {
|
||||
border-radius: 3px;
|
||||
box-shadow: 0px 0px 3px #777;
|
||||
background: white;
|
||||
max-width: 36em;
|
||||
margin: 0 auto;
|
||||
min-height: 10em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
.color {
|
||||
background: #2977b5;
|
||||
height: 7em;
|
||||
width: 100%;
|
||||
}
|
||||
.pad {
|
||||
margin: 1em;
|
||||
}
|
||||
.none { display: none; }
|
||||
input {
|
||||
font-size: 1em;
|
||||
margin: 0.1em;
|
||||
}
|
||||
</style>
|
||||
<div id="top">
|
||||
<center>
|
||||
<input id="search" placeholder="search by pub or DID">
|
||||
</center>
|
||||
</div>
|
||||
|
||||
<div class="box">
|
||||
<div class="color"></div>
|
||||
<div class="pad">
|
||||
<form id="sign">
|
||||
<h1>Login</h1>
|
||||
<input id="alias" placeholder="username">
|
||||
<input id="pass" type="password" placeholder="passphrase">
|
||||
<input id="in" type="submit" value="sign in">
|
||||
<input id="up" type="button" value="sign up">
|
||||
</form>
|
||||
|
||||
|
||||
<form id="profile" class="none">
|
||||
<h1>Profile</h1>
|
||||
<p>Data is privately encrypted by default. "+" to grant access, "x" to revoke access.</p>
|
||||
<input id="name" placeholder="name"> <button>+</button><br/>
|
||||
<input id="born" placeholder="born"> <button>+</button><br/>
|
||||
<input id="edu" placeholder="education"> <button>+</button><br/>
|
||||
<input id="skills" placeholder="skills"> <button>+</button><br/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="box"><div class="pad">
|
||||
Public Key: <input id="pub">
|
||||
</div></div>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
// extend SEA functions to base64 encode encrypted data
|
||||
// workaround for https://github.com/amark/gun/issues/783
|
||||
|
||||
(() => {
|
||||
const _encrypt = SEA.encrypt;
|
||||
SEA.encrypt = function(...args) {
|
||||
return _encrypt.apply(this, args).then(enc => btoa(JSON.stringify(enc)));
|
||||
}
|
||||
|
||||
const _decrypt = SEA.decrypt;
|
||||
SEA.decrypt = function(data, ...args) {
|
||||
try { data = JSON.parse(atob(data)); }
|
||||
finally { return _decrypt.apply(this, [data, ...args]); }
|
||||
}
|
||||
})();
|
||||
|
||||
// override User functions to fix several issues
|
||||
// see https://github.com/amark/gun/issues/808
|
||||
|
||||
SEA.Gun.User.prototype.grant = function grant(to, cb) {
|
||||
const gun = this; const user = gun.back(-1).user();
|
||||
const pair = user._.sea; let path = '';
|
||||
|
||||
gun.back(at => { if (at.has) { path += at.get; } });
|
||||
|
||||
(async () => {
|
||||
let enc, sec;
|
||||
|
||||
if (sec = await user.get('trust').get(pair.pub).get(path).then()) {
|
||||
sec = await SEA.decrypt(sec, pair);
|
||||
|
||||
} else {
|
||||
sec = SEA.random(24).toString();
|
||||
enc = await SEA.encrypt(sec, pair);
|
||||
|
||||
user.get('trust').get(pair.pub).get(path).put(enc);
|
||||
}
|
||||
|
||||
let pub = to.get('pub') .then();
|
||||
let epub = to.get('epub').then();
|
||||
|
||||
pub = await pub; epub = await epub;
|
||||
|
||||
const dh = await SEA.secret (epub, pair);
|
||||
enc = await SEA.encrypt(sec, dh);
|
||||
|
||||
// if pub is not already in trust, first put an empty node
|
||||
// workaround for https://github.com/amark/gun/issues/844
|
||||
|
||||
if (!await user.get('trust').get(pub).then()) {
|
||||
await user.get('trust').get(pub).get(path).put({}).then();
|
||||
}
|
||||
|
||||
user.get('trust').get(pub).get(path).put(enc, cb);
|
||||
})();
|
||||
|
||||
return gun;
|
||||
}
|
||||
|
||||
SEA.Gun.User.prototype.secret = function(data, cb) {
|
||||
const gun = this; const user = gun.back(-1).user();
|
||||
const pair = user._.sea; let path = '';
|
||||
|
||||
gun.back(at => { if (at.has) { path += at.get; } });
|
||||
|
||||
(async () => {
|
||||
let enc, sec;
|
||||
|
||||
if (sec = await user.get('trust').get(pair.pub).get(path).then()) {
|
||||
sec = await SEA.decrypt(sec, pair);
|
||||
|
||||
} else {
|
||||
sec = SEA.random(24).toString();
|
||||
enc = await SEA.encrypt(sec, pair);
|
||||
|
||||
user.get('trust').get(pair.pub).get(path).put(enc);
|
||||
}
|
||||
|
||||
enc = await SEA.encrypt(data, sec);
|
||||
gun.put(enc, cb);
|
||||
})();
|
||||
|
||||
return gun;
|
||||
}
|
||||
|
||||
var gun = Gun('http://localhost:8765/gun');
|
||||
var user = gun.user();
|
||||
var LI = {};
|
||||
|
||||
user.recall({sessionStorage: true});
|
||||
|
||||
$('#up').on('click', function(e){
|
||||
user.create($('#alias').val(), $('#pass').val());
|
||||
});
|
||||
|
||||
$('#sign').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
user.auth($('#alias').val(), $('#pass').val());
|
||||
});
|
||||
|
||||
gun.on('auth', function(){
|
||||
$('#sign').hide();
|
||||
$('#profile').show();
|
||||
var pub = user._.sea.pub;
|
||||
$('#pub').val(pub);
|
||||
return;
|
||||
$("#search").val(pub).trigger('blur');
|
||||
});
|
||||
|
||||
$('#profile input').on('keyup', function(e){
|
||||
if(!user.is){ return }
|
||||
var id = LI.busy = $(this).attr('id');
|
||||
user.get('profile').get(id).secret($(this).val());
|
||||
}).on('blur', function(){ LI.busy = false })
|
||||
|
||||
$('#profile button').on('click', async function(e){
|
||||
e.preventDefault();
|
||||
if(!user.is){ return }
|
||||
var b = $(this);
|
||||
var id = b.prev().attr('id');
|
||||
var pub = prompt("What is the Public Key or DID you want to give read access to?");
|
||||
var to = gun.user(pub);
|
||||
var who = await to.get('alias').then();
|
||||
if(!confirm("You want to give access to " + who + "?")){ return }
|
||||
user.get('profile').get(id).grant(to);
|
||||
});
|
||||
|
||||
$('#search').on('blur', function(e){
|
||||
var s = LI.search = $(this).val();
|
||||
var find = gun.user(s);
|
||||
find.get('profile').on(function(data, key, at, ev){
|
||||
if(s !== LI.search){
|
||||
ev.off();
|
||||
return;
|
||||
}
|
||||
|
||||
Gun.node.is(data, async (enc, id) => {
|
||||
if (id === LI.busy) { return; }
|
||||
|
||||
const pair = user._.sea;
|
||||
let key, val;
|
||||
|
||||
if (key =
|
||||
await find.get('trust').get(pair.pub).get(id + 'profile').then()) {
|
||||
const mix = await Gun.SEA.secret(await find.get('epub').then(), pair);
|
||||
|
||||
key = await Gun.SEA.decrypt(key, mix);
|
||||
val = await Gun.SEA.decrypt(enc, key);
|
||||
|
||||
// decode encrypted data to show 'SEA{...}'
|
||||
} else { val = JSON.parse(atob(enc)); }
|
||||
|
||||
$('#' + id).val(val);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
@ -1,121 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
|
||||
<link href='https://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1><button id="left">←</button> <span id="date"></span> Schedule <button id="right">→</button></h1>
|
||||
|
||||
<form id="add">
|
||||
<style>input[type="number"]{ width: 4em; }</style>
|
||||
<input id="what" placeholder="What?">
|
||||
<input id="where" placeholder="Where?">
|
||||
<input type="number" id="hour"><script>hour.value = new Date().getHours() % 12 || 12</script> :
|
||||
<input type="number" id="min" value="0">
|
||||
<select id="ampm">
|
||||
<option value="">am</option>
|
||||
<option value="1">pm</option>
|
||||
<script>ampm.children[new Date().getHours() < 12? 0 : 1].selected='selected'</script>
|
||||
</select>
|
||||
<input id="id" type="hidden">
|
||||
<input id="go" type="submit" value="add">
|
||||
<div id="err"></div>
|
||||
</form>
|
||||
|
||||
<style>
|
||||
.none { display: none; }
|
||||
p, ul, li { list-style-type: none; margin: 0; padding: 0; }
|
||||
</style>
|
||||
|
||||
<ul></ul>
|
||||
|
||||
<div class="model none">
|
||||
<li>
|
||||
<b class="when"></b>
|
||||
<span class="what"></span>
|
||||
<u class="where"></u>
|
||||
<span class="sort none">0</span>
|
||||
<button class="edit"><</button>
|
||||
</li>
|
||||
</div>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/nts.js"></script>
|
||||
<script src="../../../gun/lib/webrtc.js"></script>
|
||||
|
||||
<script>
|
||||
var name = 'schedule/' + location.hash.slice(1);
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
//var gun = Gun('http://localhost:8765/gun');
|
||||
//var gun = Gun();
|
||||
|
||||
$('#add').on('submit', function(event){
|
||||
event.preventDefault();
|
||||
event = {};
|
||||
if(!schedule.on){ return err.innerText = "No date!" }
|
||||
event.when = new Date(schedule.on.getFullYear(), schedule.on.getMonth(), schedule.on.getDate(), hour.value % 12 + (ampm.value? 12 : 0), min.value).getTime();
|
||||
if(!(event.what = what.value)){ return err.innerText = "No description!" }
|
||||
if(!(event.where = where.value)){ return err.innerText = "No location!" }
|
||||
var day = gun.get(name+now(event.when));
|
||||
day.get(id.value || String.random(9)).put(event);
|
||||
what.value = where.value = id.value = err.innerText = '';
|
||||
go.value = 'add';
|
||||
schedule(event.when);
|
||||
});
|
||||
|
||||
function schedule(ms){
|
||||
var day = new Date(ms);
|
||||
if(schedule.on && schedule.on.toLocaleDateString() === day.toLocaleDateString()){ return } schedule.on = day;
|
||||
$('#date').text(day.getFullYear()+' '+ day.toString().split(' ')[1] +' '+day.getDate());
|
||||
day = gun.get(name+now(ms));
|
||||
$('ul').empty();
|
||||
day.map().on(UI);
|
||||
}
|
||||
schedule(+new Date());
|
||||
|
||||
$('#left').on('click', function(){ schedule(+new Date(schedule.on.getFullYear(), schedule.on.getMonth(), schedule.on.getDate() - 1)) });
|
||||
$('#right').on('click', function(){ schedule(+new Date(schedule.on.getFullYear(), schedule.on.getMonth(), schedule.on.getDate() + 1)) });
|
||||
|
||||
function UI(event, id){
|
||||
if(!event){ return }
|
||||
var when = new Date(event.when);
|
||||
if(schedule.on && when.toLocaleDateString() !== schedule.on.toLocaleDateString()){ return }
|
||||
var ul = $('ul')
|
||||
var li = $("#cal-" + id)[0]; // grab if exists
|
||||
if(!li){
|
||||
li = $('.model li').clone(true) // else create it
|
||||
.attr('id', 'cal-' + id);
|
||||
}
|
||||
li = (UI.last = sort(event.when, ul.children('li').last())[0])? $(li).insertAfter(UI.last) : $(li).prependTo(ul);
|
||||
li.find('.what').text(event.what);
|
||||
li.find('.where').text(event.where);
|
||||
li.find('.sort').text(event.when);
|
||||
li.find('.edit').val(id);
|
||||
|
||||
var time = when.toLocaleTimeString();
|
||||
li.find('.when').text(time.split(':').slice(0,2).join(':') + time.slice(-2));
|
||||
};
|
||||
|
||||
$(document).on('click', '.edit', function(){
|
||||
go.value = 'update';
|
||||
id.value = this.value;
|
||||
what.value = $(this).parent().find('.what').text();
|
||||
where.value = $(this).parent().find('.where').text();
|
||||
var when = new Date(parseFloat($(this).parent().find('.sort').text()));
|
||||
hour.value = when.getHours() % 12 || 12;
|
||||
min.value = when.getMinutes();
|
||||
ampm.value = when.getHours() < 12? '' : 1;
|
||||
what.focus();
|
||||
});
|
||||
|
||||
function now(t){
|
||||
return new Date(t || Gun.state()).toLocaleDateString().split('/').reverse().join('/')
|
||||
}
|
||||
|
||||
function sort(num, li){ return parseFloat(num) >= parseFloat($(li).find('.sort').text() || -Infinity)? li : sort(num, li.prev()) }
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,59 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<video id="video" width="100%"></video>
|
||||
<center>
|
||||
<button id="record">Record</button>
|
||||
<button id="play">Play</button>
|
||||
</center>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
var record = {recorder: null, recording: false};
|
||||
|
||||
$('#record').on('click', ()=>{
|
||||
if(!record.ing){ return record.stream() }
|
||||
$('#record').text("Record");
|
||||
if(record.ing.stop){ record.ing.stop() }
|
||||
record.ing = false;
|
||||
})
|
||||
|
||||
record.stream = function(){
|
||||
navigator.mediaDevices.getDisplayMedia({ video: true }).then(stream => {
|
||||
var chunks = []; // we have a stream, we can record it
|
||||
record.ing = new MediaRecorder(stream);
|
||||
record.ing.ondataavailable = eve => chunks.push(eve.data);
|
||||
record.ing.onstop = eve => record.save(new Blob(chunks));
|
||||
record.ing.start()
|
||||
$('#record').text("End");
|
||||
}, err => { console.log(err) });
|
||||
}
|
||||
|
||||
record.save = function(data){
|
||||
record.file = record.file || new FileReader();
|
||||
record.file.readAsDataURL(data);
|
||||
record.file.onloadend = function(){
|
||||
var b64 = record.file.result;
|
||||
b64 = "data:video/webm" + b64.slice(b64.indexOf(';'));
|
||||
gun.get('test').get('screen').put(b64);
|
||||
}
|
||||
}
|
||||
|
||||
$('#play').on('click', ()=>{
|
||||
if(record.playing){
|
||||
$('#play').text("Play")
|
||||
$('#video').get(0).stop();
|
||||
record.playing = false;
|
||||
return;
|
||||
}
|
||||
$('#play').text("Stop");
|
||||
record.playing = true;
|
||||
gun.get('test').get('screen').once((data)=>{
|
||||
if(!data){ return }
|
||||
$('#video').get(0).src = data;
|
||||
$('#video').get(0).play()
|
||||
})
|
||||
})
|
||||
</script>
|
@ -1,55 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<center>
|
||||
<img id="img" width="100%"><br/>
|
||||
Stream <select id="select"><option id="from">from</option></select>
|
||||
add <input id="pass" placeholder="password" type="password">
|
||||
resolution <input id="res" value="240" step="32" max="1080" type="number" style="width:3em;">
|
||||
or <input id="upload" type="file">
|
||||
</center>
|
||||
<video id="video" width="100%" controls autoplay style="display: none;"></video>
|
||||
<canvas id="canvas" width="0" style="display: none;"></canvas>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
<script src="../../../gun/lib/webrtc.js"></script>
|
||||
|
||||
<script>;(async function(){
|
||||
gun = Gun(location.origin + '/gun'); //gun = GUN();
|
||||
|
||||
stream = canvas.getContext('2d'), stream.from = navigator.mediaDevices;
|
||||
|
||||
(await stream.from.enumerateDevices()).forEach((device,i) => {
|
||||
if('videoinput' !== device.kind){ return }
|
||||
var opt = $(from).clone().prependTo('select').get(0);
|
||||
$(opt).text(opt.id = device.label || 'Camera '+i);
|
||||
opt.value = device.deviceId;
|
||||
});
|
||||
|
||||
$('select').on('change', async eve => { $(from).text('Off'); // update label
|
||||
if('Off' == select.value){ return video.srcObject.getTracks()[0].stop() }
|
||||
video.srcObject = await stream.from.getUserMedia({ audio: false,
|
||||
video: (select.value && {deviceId: {exact: select.value}}) || {facingMode: "environment"}
|
||||
});
|
||||
});
|
||||
$('#upload').on('change', async eve => { console.log("Check ./upload.html") })
|
||||
|
||||
setInterval(async tmp => {
|
||||
if(!(video.srcObject||'').active){ return }
|
||||
var size = parseInt(res.value);
|
||||
stream.drawImage(video, 0,0,
|
||||
canvas.width = size || video.videoWidth * 0.1,
|
||||
canvas.height = (size * (video.videoHeight/video.videoWidth)) || video.videoHeight * 0.1
|
||||
);
|
||||
var b64 = canvas.toDataURL('image/jpeg');
|
||||
if(pass.value){ b64 = await SEA.encrypt(b64, pass.value) }
|
||||
gun.get('test').get('video').put(b64);
|
||||
}, 99);
|
||||
|
||||
gun.get('test').get('video').on(async data => {
|
||||
if(pass.value){ data = await SEA.decrypt(data, pass.value) }
|
||||
img.src = data; // Beware: Some browsers memory leak fast src updates.
|
||||
});
|
||||
|
||||
}());</script>
|
@ -1,132 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<h1>Tables</h1>
|
||||
|
||||
<form id="sign">
|
||||
<input id="alias" placeholder="username">
|
||||
<input id="pass" type="password" placeholder="passphrase">
|
||||
<input id="in" type="submit" value="sign in">
|
||||
<input id="up" type="button" value="sign up">
|
||||
</form>
|
||||
|
||||
<button id="tadd">+ table</button>
|
||||
<ul></ul><br/>
|
||||
|
||||
<div id="table"></div>
|
||||
<button id="radd">+ row</button>
|
||||
<button id="cadd">+ col</button>
|
||||
|
||||
<style>
|
||||
div {
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
.cell {
|
||||
width: 5em;
|
||||
height: 5em;
|
||||
border: 1px solid black;
|
||||
float: left;
|
||||
}
|
||||
.item {
|
||||
float: left;
|
||||
min-width: 5em;
|
||||
}
|
||||
</style>
|
||||
<div class="model" style="display: none;">
|
||||
<div class="item"></div>
|
||||
<div class="cell"></div>
|
||||
<div class="row"></div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/examples/jquery.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/lib/open.js"></script>
|
||||
|
||||
<script>
|
||||
//var gun = Gun(['http://localhost:8080/gun']);
|
||||
var gun = Gun();
|
||||
var user = gun.user();
|
||||
|
||||
$('#up').on('click', function(e){
|
||||
user.create($('#alias').val(), $('#pass').val());
|
||||
});
|
||||
|
||||
$('#sign').on('submit', function(e){
|
||||
e.preventDefault();
|
||||
user.auth($('#alias').val(), $('#pass').val());
|
||||
});
|
||||
|
||||
user.recall({sessionStorage: true});
|
||||
|
||||
gun.on('auth', function(){
|
||||
$('#sign').hide();
|
||||
user.get('tables').map().once(list);
|
||||
});
|
||||
|
||||
$('#tadd').on('click', function(e){
|
||||
if(!user.is){ return alert("login first") }
|
||||
var cell = user.get('cells').set({what: "Edit me!", sort: 1});
|
||||
var row = user.get('rows').set({sort: 1});
|
||||
row.get('cells').set(cell);
|
||||
var name = prompt("What do you want to call this table?")
|
||||
var table = user.get('tables').set({name: name});
|
||||
table.get('rows').set(row);
|
||||
choose(table);
|
||||
});
|
||||
|
||||
$(document).on('click', '.item', function(){
|
||||
choose($(this).data('$'));
|
||||
});
|
||||
|
||||
function choose(table){
|
||||
choose.table = table;
|
||||
table.open(render);
|
||||
}
|
||||
|
||||
function render(data){
|
||||
console.log(data);
|
||||
$('#table').empty(); // BAD! Write DOM-diffing!
|
||||
Gun.obj.map(data.rows, function(row, id){
|
||||
var $r = grab(id, '.model .row', '#table');
|
||||
Gun.obj.map(row.cells, function(cell, id){
|
||||
var $c = grab(id, '.model .cell', $r);
|
||||
$c.text(cell.what);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(document).on('click', '.cell', function(e){
|
||||
var id = $(this).data('id'), ref = gun.get(id);
|
||||
var what = prompt("What should be in this cell?");
|
||||
ref.get('what').put(what);
|
||||
});
|
||||
|
||||
$('#radd').on('click', function(){
|
||||
if(!user.is){ return alert("login first") }
|
||||
choose.table.get('rows').set();
|
||||
|
||||
var cell = user.get('cells').set({what: "Edit me!", sort: 1});
|
||||
var row = user.get('rows').set({sort: 1});
|
||||
row.get('cells').set(cell);
|
||||
choose.table.get('rows').set(row);
|
||||
});
|
||||
|
||||
$('#cadd').on('click', function(){
|
||||
if(!user.is){ return alert("login first") }
|
||||
choose.table.get('rows').map().once(function(){
|
||||
var cell = user.get('cells').set({what: "Edit me!", sort: 1});
|
||||
this.get('cells').set(cell);
|
||||
});
|
||||
});
|
||||
|
||||
function grab(id, $model, $to){
|
||||
var did = btoa(id).replace(/[\+\-\=\.]/ig,'');
|
||||
return $('#' + did).get(0) || $($model).clone(true, true).attr('id', did).appendTo($to).data('id', id);
|
||||
};
|
||||
|
||||
function list(table, id, $model, $to){
|
||||
var li = grab(id, '.model .item', 'ul');
|
||||
$(li).text(table.name).data('$', this);
|
||||
};
|
||||
</script>
|
@ -1,35 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<div class="model" style="display: none;">
|
||||
<video width="100%" controls autoplay></video>
|
||||
<audio width="100%" controls autoplay></audio>
|
||||
<img style="max-width: 100%;">
|
||||
</div>
|
||||
<center>
|
||||
<p>Drag & drop videos, songs, or images! <input id="upload" type="file" multiple></p>
|
||||
</center>
|
||||
|
||||
<script src="../../../gun/lib/yson.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/lib/dom.js"></script>
|
||||
<script src="../../../gun/lib/upload.js"></script>
|
||||
|
||||
<script>
|
||||
gun = GUN(location.origin + '/gun');
|
||||
|
||||
$('html, #upload').upload(function resize(eve, up){
|
||||
if(up){ return up.shrink(eve, resize, 1024) }
|
||||
var b64 = (eve.base64 || ((eve.event || eve).target || eve).result || eve); // which one? try all!
|
||||
gun.get('test').get((eve.id+(new Date).getUTCSeconds()) % 60).put(b64); // limit uploads to 1 of 60 slots.
|
||||
});
|
||||
|
||||
gun.get('test').map().once(function(data){
|
||||
if("string" != typeof data){ return }
|
||||
var type = data.split(';')[0], ui;
|
||||
if(type.indexOf('image') + 1){ ui = $("img").get(0) }
|
||||
if(type.indexOf('video') + 1){ ui = $('video').get(0) }
|
||||
if(type.indexOf('audio') + 1){ ui = $('audio').get(0) }
|
||||
if(!ui){ return }
|
||||
$(ui).clone().prependTo('center').get(0).src = data;
|
||||
});
|
||||
</script>
|
@ -1,2 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<p>Moved to <a href="./post.html">./post.html</a>!</p>
|
@ -1,62 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<video id="video" width="100%" controls autoplay></video>
|
||||
<center>
|
||||
<input id="pass" placeholder="password">
|
||||
Record <button class="record">Camera</button> or <button class="record">Screen</button>
|
||||
</center>
|
||||
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<script src="../../../gun/sea.js"></script>
|
||||
|
||||
<script>
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
|
||||
gun.get('test').get('video').on(async function(data){
|
||||
if($('#pass').val()){ data = await SEA.decrypt(data, $('#pass').val()) }
|
||||
$('#video').get(0).src = data;
|
||||
})
|
||||
|
||||
$('.record').on('click', function(){
|
||||
if(record.ing){
|
||||
if(record.ing.stop){ record.ing.stop() }
|
||||
$(this).text(record.type);
|
||||
record.ing = false;
|
||||
return;
|
||||
}
|
||||
record(record.type = $(this).text());
|
||||
$(this).text("End");
|
||||
})
|
||||
|
||||
function record(type){
|
||||
if('Camera' === type){
|
||||
navigator.getMedia({ video: true, audio: true }, load, error);
|
||||
}
|
||||
if('Screen' === type){
|
||||
navigator.mediaDevices.getDisplayMedia({ video: true, audio: true }).then(load, error);
|
||||
}
|
||||
function load(media){
|
||||
var chunks = [];
|
||||
record.ing = new MediaRecorder(media);
|
||||
record.ing.ondataavailable = function(eve){ chunks.push(eve.data) }
|
||||
record.ing.onstop = function(eve){record.save(new Blob(chunks)) }
|
||||
record.ing.start();
|
||||
}
|
||||
function error(err){ console.log(err) }
|
||||
}
|
||||
|
||||
record.save = function(data){
|
||||
record.file = record.file || new FileReader();
|
||||
record.file.readAsDataURL(data);
|
||||
record.file.onloadend = async function(){
|
||||
var b64 = record.file.result, pass;
|
||||
b64 = $('#video').get(0).src = "data:video/webm" + b64.slice(b64.indexOf(';'));
|
||||
if($('#pass').val()){ b64 = await SEA.encrypt(b64, $('#pass').val()) }
|
||||
gun.get('test').get('video').put(b64);
|
||||
}
|
||||
}
|
||||
|
||||
navigator.getMedia = (navigator.getUserMedia || navigator.webkitGetUserMedia
|
||||
|| navigator.mozGetUserMedia || navigator.msGetUserMedia);
|
||||
</script>
|
@ -1,213 +1,104 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Converse</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="converse" class="hue2 page">
|
||||
<link href='https://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
|
||||
<style>
|
||||
.chat__heading {
|
||||
position: fixed;
|
||||
text-align: center;
|
||||
z-index: 1;
|
||||
width: 100%;
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
#converse {
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
.chat__form-container {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
width: 100%;
|
||||
padding: 10px 20px;
|
||||
position: fixed;
|
||||
z-index: 1;
|
||||
bottom: 0;
|
||||
#converse .box {
|
||||
margin-bottom: 0.2em;
|
||||
padding: 1em;
|
||||
border-radius: 0.1em;
|
||||
}
|
||||
|
||||
.chat__form {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
height: 50px;
|
||||
background-color: white;
|
||||
border: 2px solid white;
|
||||
max-width: 900px;
|
||||
width: 100%;
|
||||
border-radius: 5px;
|
||||
#converse b:after {
|
||||
content: " ";
|
||||
}
|
||||
|
||||
.chat__name-input {
|
||||
flex: 1;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.chat__message-input {
|
||||
flex: 5;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
.chat__submit {
|
||||
padding: 10px;
|
||||
color: white;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.chat__submit:hover::after {
|
||||
background-color: rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.chat__submit:focus::after {
|
||||
background-color: rgba(0,0,0,0.2);
|
||||
}
|
||||
|
||||
.chat__submit::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
left: 0;
|
||||
top: 0;
|
||||
border-radius: 5px;
|
||||
transition: background-color 0.3s;
|
||||
background-color: rgba(0,0,0,0);
|
||||
}
|
||||
|
||||
.chat__message-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 60px 20px;
|
||||
width: 100%;
|
||||
background-color: rgba(0, 0, 0, 0.2);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
.chat__message {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
margin-bottom: 10px;
|
||||
padding: 10px;
|
||||
border-radius: 5px;
|
||||
width: 100%;
|
||||
position: relative;
|
||||
max-width: 900px;
|
||||
}
|
||||
|
||||
.chat__name {
|
||||
margin-right: 20px;
|
||||
}
|
||||
|
||||
.chat__when {
|
||||
#converse li .when {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 2em;
|
||||
padding: 10px;
|
||||
right: -2em;
|
||||
padding: 0.5em 1em;
|
||||
background: rgba(100%,100%,100%,0.9);
|
||||
opacity: 0;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.chat__message:hover .chat__when {
|
||||
#converse li:hover .when {
|
||||
opacity: 1;
|
||||
right: 0em;
|
||||
}
|
||||
|
||||
@media (max-width: 567px) {
|
||||
.chat__heading {
|
||||
font-size: 30px;
|
||||
.poiret {
|
||||
font-family: 'Poiret One', sans-serif;
|
||||
}
|
||||
.large {
|
||||
font-size: 200%;
|
||||
}
|
||||
#converse .what, #converse .who {
|
||||
cursor: text;
|
||||
outline: none;
|
||||
display: inline;
|
||||
min-width: 1em;
|
||||
padding-left: 1px;
|
||||
}
|
||||
[contentEditable=true]:empty:not(:focus):before{
|
||||
content:attr(data-text)
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="chat hue2 page">
|
||||
<h2 id='title' class="chat__heading hue2 whitet">Have a Conversation...</h2>
|
||||
<ul class="chat__message-list">
|
||||
<div class="pad">
|
||||
<div class="poiret large rubric whitet" style="margin-bottom: 0.5em;">Have a Conversation...</div>
|
||||
<div>
|
||||
<ul>
|
||||
<li class="none"></li>
|
||||
</ul>
|
||||
|
||||
<div class="chat__form-container hue2">
|
||||
<form class="chat__form">
|
||||
<label for="name-input" class="visually-hidden">Name</label>
|
||||
<input id="name-input" class="chat__name-input" placeholder="Name"></input>
|
||||
<label for="message-input" class="visually-hidden">Message</label>
|
||||
<input id="message-input" class="chat__message-input" placeholder="Write a message..."></input>
|
||||
<button class="chat__submit say hue2">say</button>
|
||||
<form class="white huet2 box">
|
||||
<div>
|
||||
<div class="send hue2 right whitet box act" style="margin: 0 0 0.4em 0.4em; padding: 0.2em 0.5em;">send</div>
|
||||
<b class="jot left who" contenteditable="true" data-text="Name" style="margin-top: 0.5em; margin-right: 0.5em;"></b>
|
||||
<p class="jot left what" contenteditable="true" data-text="Write a message..." style="margin-top: 0.5em;"></p>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="model">
|
||||
<li class="chat__message white huet2 box">
|
||||
<b class="chat__name"></b>
|
||||
<p class="chat__message-text"></p>
|
||||
<span class="sort none">0</span>
|
||||
<div class="chat__when"></div>
|
||||
</li>
|
||||
<li class="white huet2 box"><b class="who"></b><p class="what"></p><span class="sort none">0</span><div class="when"></div></li>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="/gun/nts.js"></script>
|
||||
<script>
|
||||
var gun = Gun(location.origin+'/gun');
|
||||
var chat = gun.get('converse/' + location.hash.slice(1));
|
||||
|
||||
$(".chat__submit").on('click', submit);
|
||||
$(".chat_form").on('keydown', enter);
|
||||
function enter(e) {
|
||||
if (e.which !== 13) { return }
|
||||
submit(e);
|
||||
}
|
||||
var chat = gun.get('converse');
|
||||
chat.map().val(function(msg, field){
|
||||
var ul = $('ul'), last = sort(field, ul.children('li').last()), li;
|
||||
li = $($("#msg-" + field)[0] || $('.model li').clone(true).attr('id', 'msg-'+field).insertAfter(last));
|
||||
li.find('.who').text(msg.who);
|
||||
li.find('.what').text(msg.what);
|
||||
li.find('.sort').text(field);
|
||||
var time = new Date(msg.when);
|
||||
li.find('.when').text(time.toDateString() +', '+ time.toLocaleTimeString());
|
||||
$('body').stop(true, true).animate({scrollTop: ul.height()});
|
||||
});
|
||||
$("form .send").on('click', submit);
|
||||
$("form .what").on('keydown', function(e){
|
||||
if(e.which == 13){ submit(e) }
|
||||
});
|
||||
function submit(e){
|
||||
e.preventDefault();
|
||||
|
||||
var msg = { when: Gun.state() };
|
||||
|
||||
msg.who = $('.chat__name-input').val();
|
||||
if (!msg.who) {
|
||||
msg.who = 'user' + String.random(3);
|
||||
$('.chat__name-input').val(msg.who);
|
||||
}
|
||||
|
||||
msg.what = $('.chat__message-input').val();
|
||||
var msg = {when: Gun.time.is()};
|
||||
msg.who = $('form .who').text();
|
||||
if(!msg.who){ $('form .who').text(msg.who = 'user'+Gun.text.random(3)) }
|
||||
msg.what = $('form .what').text();
|
||||
if(!msg.what){ return }
|
||||
|
||||
chat.set(msg);
|
||||
$('.chat__message-input').val('').focus();
|
||||
chat.get(msg.when+'r'+Gun.text.random(3)).put(msg);
|
||||
$('form .what').text('');
|
||||
}
|
||||
|
||||
chat.map().once(function (msg, id) {
|
||||
if (!msg) { return }
|
||||
var messageList = $('.chat__message-list');
|
||||
var last = sort(msg.when, messageList.children('li').last());
|
||||
|
||||
var li = $("#msg-" + id)[0]; // grab if exists
|
||||
if (!li) {
|
||||
li = $('.model li').clone(true) // else create it
|
||||
.attr('id', 'msg-' + id)
|
||||
.insertAfter(last);
|
||||
function sort(g, e){
|
||||
return (parseFloat(g) >= parseFloat($(e).find('.sort').text() || -Infinity))? e : sort(g, e.prev());
|
||||
}
|
||||
|
||||
// bind the message data into the UI
|
||||
li = $(li);
|
||||
li.find('.chat__name').text(msg.who);
|
||||
li.find('.chat__message-text').text(msg.what);
|
||||
li.find('.sort').text(msg.when);
|
||||
|
||||
var time = new Date(msg.when);
|
||||
li.find('.chat__when').text(time.toDateString() + ', ' + time.toLocaleTimeString());
|
||||
|
||||
$('html, body').stop(true, true)
|
||||
.animate({ scrollTop: messageList.height() });
|
||||
});
|
||||
|
||||
function sort(num, li) { return parseFloat(num) >= parseFloat($(li).find('.sort').text() || -Infinity) ? li : sort(num, li.prev()) }
|
||||
</script>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -1,330 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="sign" class="hue page">
|
||||
<style>
|
||||
input, button {
|
||||
margin: 1em 0;
|
||||
padding: 1em;
|
||||
}
|
||||
.or {
|
||||
display: inline-block;
|
||||
width: 15%;
|
||||
}
|
||||
</style>
|
||||
<form id="inup" class="sign pad center">
|
||||
<div class="loud">Welcome,</div>
|
||||
<div class="mid row col">
|
||||
<input name="alias" class="huet jot sap" placeholder="alias">
|
||||
Enter your public username.
|
||||
</div>
|
||||
<div class="mid row col">
|
||||
<input name="pass" class="huet jot sap" type="password" placeholder="passphrase">
|
||||
And a long private passphrase.
|
||||
</div>
|
||||
<div class="mid row col go">
|
||||
<button class="huet sap act symbol">sign in</button>
|
||||
<div class="or">or</div>
|
||||
<button class="huet sap act symbol">sign up</button>
|
||||
</div>
|
||||
<a href="info">more info</a>
|
||||
</form>
|
||||
</div id="sign">
|
||||
|
||||
<div id="people" class="hue2 page">
|
||||
<ul name="users" class="pad">
|
||||
<h3>Here is a list of people:</h3>
|
||||
<li name="#">
|
||||
<!-- <h3 name="."></h3> -->
|
||||
<ul>
|
||||
<a href="person" name="#" class="whitet act">
|
||||
<li>
|
||||
<span name="who">
|
||||
<b name="name"></b>
|
||||
</span>
|
||||
<i>~</i><i name="alias" class="sort"></i>
|
||||
<input name="pub">
|
||||
</li>
|
||||
</a>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div id="people">
|
||||
|
||||
<div id="converse" class="page">
|
||||
<ul>
|
||||
</ul>
|
||||
<div class="model">
|
||||
<li class="msg">
|
||||
<span name="fro">Alias</span>: <span name="what"></span>
|
||||
</li>
|
||||
</div>
|
||||
<form>
|
||||
<input placeholder="to" name="to">
|
||||
<textarea name="what"></textarea>
|
||||
<input type="submit" value="submit">
|
||||
<div class="status"></div>
|
||||
</form>
|
||||
</div id="converse">
|
||||
|
||||
<div id="person" class="hue3 page">
|
||||
<style>
|
||||
#person .back {
|
||||
position: absolute;
|
||||
top: 0.3em;
|
||||
left: 0.5em;
|
||||
width: 2em;
|
||||
height: 2em;
|
||||
z-index: 99999;
|
||||
}
|
||||
</style>
|
||||
<a href="people" class="whitet act back">←</a>
|
||||
<div class="pad">
|
||||
<div name="who">
|
||||
<!-- img src="" -->
|
||||
<h2 name="name" contenteditable="true">Name</h2>
|
||||
<i name="born"></i>
|
||||
<span name="bio" contenteditable="true">bio</span>
|
||||
<form id="say" class="center none">
|
||||
<input class="jot" placeholder="Say something!" style="width: 80%;">
|
||||
<input type="submit" id="speak" class="huet2 sap act symbol" style="min-width: 5em; width: 10%;" value="speak">
|
||||
</form>
|
||||
<div>
|
||||
<ul name="said">
|
||||
<li name="#" class="sit sort shade rim"><div name="what" class="rim"></div></li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<input name="pub">
|
||||
</div>
|
||||
</div id="person">
|
||||
|
||||
<div id="info" class="page">
|
||||
<p>A mysterious new example app has appeared! It is not finished/ready yet.</p>
|
||||
</div id="info">
|
||||
|
||||
<div id="tell" class="center">
|
||||
<style>
|
||||
#tell {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 0;
|
||||
overflow: visible;
|
||||
}
|
||||
#tell p {
|
||||
top: -2em;
|
||||
width: 50%;
|
||||
border: solid #222 0.2em;
|
||||
border-top: none;
|
||||
padding: 1%;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: visibility 2s, all 1s ease-in;
|
||||
}
|
||||
#tell .notify {
|
||||
top: 0em;
|
||||
opacity: 0.8;
|
||||
visibility: visible;
|
||||
transition: visibility 0s, all 0.25s ease-out;
|
||||
}
|
||||
</style>
|
||||
<p class="mid black">Hello world!</p>
|
||||
</div>
|
||||
|
||||
<!-- script src="/Users/mark/Dropbox/Public/gun/db/examples/jquery.js"></script>
|
||||
<script src="/Users/mark/Dropbox/Public/gun/db/gun.js"></script>
|
||||
<script src="/Users/mark/Dropbox/Public/gun/db/lib/cryptomodules.js"></script>
|
||||
<script src="/Users/mark/Dropbox/Public/gun/db/sea.js"></script>
|
||||
<script src="/Users/mark/Dropbox/Public/gun/db/as.js"></script -->
|
||||
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="/gun/sea.js"></script>
|
||||
<script src="/gun/as.js"></script>
|
||||
<script src="/gun/nts.js"></script>
|
||||
<script>
|
||||
// Check out the interactive tutorial
|
||||
// for how to build a simplified version
|
||||
// of this example: https://scrimba.com/c/c2gBgt4
|
||||
var gun = Gun(location.origin+'/gun');
|
||||
var app = gun.get('example/contacts/7');
|
||||
var user = gun.user();
|
||||
var c = window.c = {};
|
||||
(function(){
|
||||
c.hash = location.hash.slice(1);
|
||||
gun.on('auth', function(at){
|
||||
if('sign' === c.hash){ c.hash = '' }
|
||||
as.route(c.hash || 'people');
|
||||
});
|
||||
gun.on('secure', function(at){
|
||||
/* enforce some rules about shared app level data */
|
||||
if(!at.put || !at.put.users){ return }
|
||||
var no;
|
||||
Gun.node.is(at.put.users, function(val, key){
|
||||
Gun.SEA.verify(val, false, function(val){
|
||||
//Gun.SEA.read(val, false, function(val){
|
||||
if('~@'+key === Gun.val.link.is(val)){ return }
|
||||
no = true;
|
||||
})
|
||||
if(no){ return no }
|
||||
});
|
||||
if(no){ return }
|
||||
this.to.next(at);
|
||||
});
|
||||
$(document).on('keyup', "form.sign input:first", as.wait(function(){
|
||||
/*
|
||||
var form = $(this).closest('form'), data = {alias: $(this).val()};
|
||||
if(!data.alias || data.alias.length < 5){
|
||||
return;
|
||||
}
|
||||
var exist = gun.path('alias').path(data.alias);
|
||||
exist.get(function(at){
|
||||
form.find('.or').addClass('none');
|
||||
form.find('button:first').toggleClass('none', at.put? false : true);
|
||||
form.find('button:last').toggleClass('none', at.put? true : false);
|
||||
});
|
||||
*/
|
||||
})).on('click','form.sign button:last', function(){
|
||||
var but = $(this), form = $(this).closest('form'), data = {alias: form.find('input:first').val(), pass: form.find('input:last').val()};
|
||||
data.born = Gun.time.is();
|
||||
if(!data.alias || data.alias.length < 5){
|
||||
c.tell("Alias needs to be longer than 5 characters.");
|
||||
return;
|
||||
}
|
||||
if(!data.pass || data.pass.length < 9){
|
||||
c.tell("Passphrase needs to be longer than 9 characters.");
|
||||
return;
|
||||
}
|
||||
but.addClass('pulse');
|
||||
data.alias = data.alias.toLowerCase();
|
||||
user.create(data.alias, data.pass, function(ack){
|
||||
if(!ack.wait){ but.removeClass('pulse') }
|
||||
if(ack.err){ c.tell(ack.err); return }
|
||||
if(ack.pub){
|
||||
gun.get('users').get(data.alias).put(gun.get('~@'+data.alias));
|
||||
}
|
||||
session(data);
|
||||
user.auth(data.alias, data.pass);
|
||||
});
|
||||
}).on('click','form.sign button:first', become);
|
||||
function become(){
|
||||
var form = $('#sign').find('form'), data = {alias: form.find('input:first').val(), pass: form.find('input:last').val()};
|
||||
data.alias = data.alias || sessionStorage.alias;
|
||||
data.pass = data.pass || sessionStorage.tmp;
|
||||
if(!data.alias || data.alias.length < 5){
|
||||
c.tell("Alias needs to be longer than 5 characters.");
|
||||
return;
|
||||
}
|
||||
if(!data.pass || data.pass.length < 9){
|
||||
c.tell("Passphrase needs to be longer than 9 characters.");
|
||||
return;
|
||||
}
|
||||
var but = form.find('button:first');
|
||||
but.addClass('pulse');
|
||||
data.alias = data.alias.toLowerCase();
|
||||
user.auth(data.alias, data.pass, function(ack){
|
||||
if(!ack.wait){ but.removeClass('pulse') }
|
||||
if(ack.err){ c.tell(ack.err); return }
|
||||
session(data);
|
||||
});
|
||||
}
|
||||
if(!location.hash){
|
||||
as.route('sign');
|
||||
}
|
||||
if(!window.sessionStorage){ window.sessionStorage = {clear:function(){}} }
|
||||
if(sessionStorage.tmp){
|
||||
become();
|
||||
}
|
||||
function session(data){
|
||||
if(!sessionStorage){ return }
|
||||
sessionStorage.alias = data.alias;
|
||||
sessionStorage.tmp = data.pass;
|
||||
}
|
||||
c.tell = function(what, n){
|
||||
var e = $('#tell').find('p');
|
||||
e.addClass('notify').text(what);
|
||||
clearTimeout(c.tell.to);
|
||||
c.tell.to = setTimeout(function(){e.removeClass('notify')}, n || 2500);
|
||||
}
|
||||
}());
|
||||
(function(){
|
||||
$(document).on('submit', '#say', function(e){
|
||||
e.preventDefault();
|
||||
user.get('who').get('said').set({
|
||||
what: $(this).find('.jot').val()
|
||||
});
|
||||
$(this).find('.jot').val('');
|
||||
});
|
||||
}());
|
||||
as.route.page('sign', function(){
|
||||
$(document.forms.inup.alias).focus();
|
||||
});
|
||||
as.route.page('people', function(){
|
||||
if(!user.is){ return as.route('sign') }
|
||||
as('#people', gun, function(data, key, el){
|
||||
if('pub' !== key){ return }
|
||||
el.closest('a').attr('href', '#person/' + data);
|
||||
});
|
||||
});
|
||||
as.route.page('person', function(){
|
||||
if(!user.is){ return as.route('sign') }
|
||||
var pub = location.hash.split('/').slice(-1)[0];
|
||||
(pub === user._.pub? $('#say').show() : $('#say').hide());
|
||||
as('#person', window.PUB = gun.get('~'+pub));
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(function(converse){
|
||||
as.route.page('converse', function(){
|
||||
if(!c.me){ return as.route('sign') }
|
||||
converse.lock = false;
|
||||
var alias = location.hash.split('/').slice(-1);
|
||||
$('#converse form').find('input:first').val(alias);
|
||||
function inbox(msg, id){
|
||||
if(!sign.verify(msg.pub, msg.what, msg.sig)){ return }
|
||||
msg.fro = (msg.to === c.me.alias? alias : c.me.alias);
|
||||
as.route.render(id, '.msg', $('#converse ul'), msg);
|
||||
}
|
||||
sign.is(alias, function(acc){
|
||||
sign.is(c.me.alias).path('msgs').path(acc.pub).map(inbox);
|
||||
}).path('msgs').path(c.me.pub).map(inbox);
|
||||
});
|
||||
$(document).on('submit', '#converse form', function(e){
|
||||
e.preventDefault();
|
||||
if(converse.lock){ return console.log('message sending already') }
|
||||
converse.lock = true; // prevent duplicate sends.
|
||||
var form = $(this), msg = {};
|
||||
msg.to = form.find('input:first').val();
|
||||
msg.what = form.find('textarea').val();
|
||||
sign.is(msg.to, function(to){
|
||||
if(!priv){
|
||||
form.find('.status').text("Failed to send. Please sign in again.");
|
||||
converse.lock = false;
|
||||
return;
|
||||
}
|
||||
msg.sig = sign.sig(msg.what, priv);
|
||||
msg.pub = c.me.pub;
|
||||
msg.when = Gun.time.is();
|
||||
console.log("sending msg", msg);
|
||||
sign.is(c.me.alias).path('msgs').path(to.pub).set(gun.put(msg));
|
||||
converse.lock = false;
|
||||
}, function(){
|
||||
form.attr('disabled', false).find('.status').text(msg.to + " cannot be found! Alias is case sensitive.");
|
||||
converse.lock = false;
|
||||
});
|
||||
});
|
||||
}({}));
|
||||
//}());</script>
|
||||
</body>
|
||||
</html>
|
@ -1,379 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!-- always start with these two lines to set a clean baseline for different devices -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="style.css">
|
||||
<script src="jquery.js"></script>
|
||||
|
||||
<title>Docs</title>
|
||||
</head>
|
||||
<body class="black whitet">
|
||||
<style>
|
||||
/*
|
||||
Choose white text on a black background so you can add color in.
|
||||
Pick your favorite font and choose a font size.
|
||||
*/
|
||||
@import url('https://fonts.googleapis.com/css?family=Oxygen');
|
||||
html, body {
|
||||
font-family: "Oxygen", sans-serif;
|
||||
}
|
||||
|
||||
[contenteditable]:focus {
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.meta-on, div:hover, ul:hover, ol:hover, li:hover, p:hover, span:hover, form:hover, button:hover, input:hover, textarea:hover, img:hover {
|
||||
outline: 1px solid;
|
||||
animation: meta-on 3s infinite;
|
||||
transition: none !important;
|
||||
} @keyframes meta-on {
|
||||
0% {outline-color: magenta;}
|
||||
33% {outline-color: cyan;}
|
||||
66% {outline-color: yellow;}
|
||||
100% {outline-color: magenta;}
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="hold full hue2">
|
||||
<div id="page" class="max focus gap" style="margin-top: 9%;"></div>
|
||||
</div>
|
||||
|
||||
<script src="../../gun/gun.js"></script>
|
||||
<script src="../../gun/lib/monotype.js"></script>
|
||||
<script src="../../gun/lib/meta.js"></script>
|
||||
<script src="../../gun/lib/normalize.js"></script>
|
||||
<script async src="../../gun/lib/fun.js"></script>
|
||||
|
||||
<script async src="../../gun/lib/wave.js"></script>
|
||||
<!-- script async src="https://edide.io/music.lib"></script -->
|
||||
|
||||
<script>
|
||||
var gun = Gun();
|
||||
var page = {};
|
||||
//var gun = Gun(['https://guntest.herokuapp.com/gun', 'http://localhost:8765/gun']);
|
||||
|
||||
;(window.onhashchange = function(){
|
||||
var file = (location.hash||'').slice(1);
|
||||
var S = +new Date;
|
||||
$('#page').empty().attr('contenteditable', 'false');
|
||||
gun.get('test/gun/docs/'+file).get('what').map().on(function render(data, i, msg, eve){
|
||||
var tmp = page[i] || '';
|
||||
var last = Gun.state.is(gun._.root.graph[msg.put['#']], i);
|
||||
if(last < tmp.last){ return }
|
||||
//});
|
||||
//if(window.LOCK){ return }
|
||||
var p = $('#page').children().get(i);
|
||||
if(!p){
|
||||
$('#page').append('<p>');
|
||||
setTimeout(function(){ render(data, i, msg, eve) },0);
|
||||
return;
|
||||
}
|
||||
var DBG = {s: +new Date};
|
||||
var r = monotype(p);
|
||||
DBG.mono = +new Date;
|
||||
var safe = $.normalize(data);
|
||||
DBG.norm = +new Date;
|
||||
p.outerHTML = data;
|
||||
DBG.html = +new Date;
|
||||
r.restore();
|
||||
DBG.rest = +new Date;
|
||||
//console.log("mono:", DBG.mono - DBG.s, "norm:", DBG.norm - DBG.mono, 'html:', DBG.html - DBG.norm, 'rest:', DBG.rest - DBG.html, ':::', msg, eve);
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
window.requestAnimationFrame = window.requestAnimationFrame || setTimeout;
|
||||
window.requestAnimationFrame(function frame(){
|
||||
window.requestAnimationFrame(frame, 16);
|
||||
|
||||
}, 16);
|
||||
|
||||
document.execCommand('defaultParagraphSeparator', false, 'p');
|
||||
meta.edit({
|
||||
name: "Edit",
|
||||
combo: ['E'],
|
||||
use: function(eve){
|
||||
console.log('on');
|
||||
}, on: function(eve){
|
||||
if($(eve.target).closest('p').length){ return }
|
||||
var edit = this;
|
||||
setTimeout(function(){ meta.flip(false) },1);
|
||||
edit.init();
|
||||
$(document).on('keydown.tmp', '[contenteditable]', function(eve){
|
||||
if(eve.which != 13){ return }
|
||||
eve.preventDefault();
|
||||
var r = window.getSelection().getRangeAt(0);
|
||||
var c = r.commonAncestorContainer, p;
|
||||
r.deleteContents();
|
||||
var p = c.splitText? $(c.splitText(r.startOffset)).parent() : $(c);
|
||||
var n = $("<"+p.get(0).tagName+">"), f;
|
||||
p.contents().each(function(){
|
||||
if(this === c){ return f = true }
|
||||
if(!f){ return }
|
||||
n.append(this);
|
||||
});
|
||||
p.after(n);
|
||||
edit.select(n.get(0));
|
||||
// make sure we re-save & sync each changed paragraph.
|
||||
edit.save(p);
|
||||
p.nextAll().each(function(){
|
||||
edit.save(this);
|
||||
});
|
||||
}).on('keyup.tmp', '[contenteditable]', function(eve){
|
||||
//$('#debug').val(doc.html());
|
||||
var p = $(window.getSelection().anchorNode).closest('p'), tmp;
|
||||
(tmp = page[p.index()] || (page[p.index()] = {})).last = (+new Date) + 99;
|
||||
clearTimeout(tmp.to); tmp.to = setTimeout(function(){
|
||||
var DBG = {s: +new Date};
|
||||
var r = monotype(p);
|
||||
DBG.m = +new Date;
|
||||
var html = p.html() || '';
|
||||
DBG.g = +new Date;
|
||||
if(!html && !p.prev().length && !p.next().length && !$('#page').html()){
|
||||
edit.init();
|
||||
}
|
||||
DBG.i = +new Date;
|
||||
var safe = $.normalize(html);
|
||||
DBG.n = +new Date;
|
||||
p.html(safe);
|
||||
DBG.h = +new Date;
|
||||
r.restore();
|
||||
DBG.r = +new Date;
|
||||
edit.save(p);
|
||||
DBG.p = +new Date;
|
||||
//console.log("save:", DBG.p - DBG.r, "rest:", DBG.r - DBG.h, "html:", DBG.h - DBG.n, "norm:", DBG.n - DBG.i, 'init:', DBG.i - DBG.g, 'grab:', DBG.g - DBG.m, 'mono:', DBG.m - DBG.s);
|
||||
},50)});
|
||||
},
|
||||
up: function(){
|
||||
console.log("UP");
|
||||
$('[contenteditable=true]').off('.tmp');
|
||||
},
|
||||
init: function(){
|
||||
var edit = this;
|
||||
var doc = $('#page').attr('contenteditable', 'true');
|
||||
if(!doc.text()){
|
||||
doc.html('<p class="loud crack"></p>');
|
||||
}
|
||||
edit.select(doc.children().first().get(0));
|
||||
},
|
||||
save: function(p){
|
||||
p = $(p);
|
||||
var i = p.index();// = Array.prototype.indexOf.call(parent.children, child);
|
||||
var file = (location.hash||'').slice(1);
|
||||
var data = (p.get(0)||{}).outerHTML||'';
|
||||
//data = $.normalize(data); // GOOD TO DO SECURITY ON SENDING SIDE TOO!!!
|
||||
window.LOCK = true;
|
||||
gun.get('test/gun/docs/'+file).get('what').get(i).put(data);
|
||||
window.LOCK = false;
|
||||
},
|
||||
select: function(p){
|
||||
var s = window.getSelection(),
|
||||
r = document.createRange();
|
||||
if(p.innerHTML){
|
||||
r.setStart(p, 0);
|
||||
r.collapse(true);
|
||||
s.removeAllRanges();
|
||||
s.addRange(r);
|
||||
return;
|
||||
}
|
||||
p.innerHTML = '\u00a0';
|
||||
r.selectNodeContents(p);
|
||||
s.removeAllRanges();
|
||||
s.addRange(r);
|
||||
document.execCommand('delete', false, null);
|
||||
}
|
||||
});
|
||||
|
||||
;(function(){
|
||||
|
||||
meta.edit({name: "Design", combo: ['D']});
|
||||
meta.edit({name: "Fill", combo: ['D','F'], // TODO!
|
||||
use: function(eve){},
|
||||
on: function(eve){
|
||||
var on = meta.tap();
|
||||
meta.ask('Color name, code, or URL?', function(color){
|
||||
on.css('background', color);
|
||||
}, true);
|
||||
},
|
||||
up: function(eve){}
|
||||
});
|
||||
|
||||
meta.edit({name: "Add", combo: ['D','A']});
|
||||
meta.edit({name: "Row", combo: ['D','A', 'R'],
|
||||
on: function(eve){
|
||||
meta.tap().append('<div style="min-height: 9em; padding: 2%;">');
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Columns", combo: ['D','A','C'],
|
||||
on: function(eve){
|
||||
var on = meta.tap().addClass('center'), tmp, c;
|
||||
var html = '<div class="unit col" style="min-height: 9em; padding: 2%;"></div>';
|
||||
if(!on.children('.col').length){ html += html }
|
||||
c = (tmp = on.append(html).children('.col')).length;
|
||||
tmp.each(function(){
|
||||
$(this).css('width', (100/c)+'%');
|
||||
})
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Text", combo: ['D','A','T'],
|
||||
on: function(eve){
|
||||
var tag = $('<p>text</p>');
|
||||
meta.tap().append(tag);
|
||||
tag.focus();
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Delete", combo: ['D','A','D'],
|
||||
on: function(eve){
|
||||
meta.tap().remove();
|
||||
}
|
||||
});
|
||||
|
||||
meta.edit({name: "Turn", combo: ['D','T']});
|
||||
meta.edit({name: "Size", combo: ['D','S']});
|
||||
meta.edit({name: "X", combo: ['D','S','X'],
|
||||
on: function(eve){
|
||||
var on = this.a = meta.tap().addClass('meta-on'), was = on.width();
|
||||
$(document).on('mousemove.tmp', function(eve){
|
||||
var be = was + ((eve.pageX||0) - was);
|
||||
on.css({'max-width': be, width: '100%'});
|
||||
});
|
||||
meta.ask('Width in px, %, or other unit?', function(w){
|
||||
if(!w){ return }
|
||||
on.css({'max-width': w, width: '100%'});
|
||||
}, true);
|
||||
}, up: function(){
|
||||
$(document).off('mousemove.tmp');
|
||||
this.a.removeClass('meta-on');
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Y", combo: ['D','S','Y'],
|
||||
//on: function(eve){ console.log('on Y') },
|
||||
on: function(eve){ console.log('use Y')
|
||||
var on = this.a = meta.tap().addClass('meta-on'), was = on.height();
|
||||
$(document).on('mousemove.tmp', function(eve){
|
||||
var be = was + ((eve.pageY||0) - was);
|
||||
on.css({'min-height': be});
|
||||
})
|
||||
}, up: function(){ console.log('up Y')
|
||||
$(document).off('mousemove.tmp');
|
||||
this.a.removeClass('meta-on');
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
;(function(){
|
||||
var logic = {};
|
||||
|
||||
meta.edit({name: "Logic", combo: ['L']});
|
||||
|
||||
meta.edit({name: "Symbol", combo: ['L','S'],
|
||||
on: function(eve){
|
||||
console.log(1);
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Action", combo: ['L','A'],
|
||||
on: function(eve){
|
||||
console.log(2);
|
||||
}
|
||||
});
|
||||
meta.edit({name: "Data", combo: ['L','D'],
|
||||
on: function(eve){
|
||||
console.log(3);
|
||||
}
|
||||
});
|
||||
}());
|
||||
|
||||
;(function(){
|
||||
var song = {};
|
||||
// TODO:
|
||||
// 1. Manually OR automatically load music.js API, dependencies, and modules. - FINE for now
|
||||
// 2. only export music API, not meta, not dom, not mouselock system, not UI/html, etc. better module isolation and export.
|
||||
// 3. `var wave = Wave('a').play()` // also on `Music.now`
|
||||
// defaults... instrument: pure tones, volume curve: |\_ , speed curve: 0.5
|
||||
// 4. `wave.blur(0.5).itch(0.5);`
|
||||
// 5. wave.long(2); // how long in seconds each note plays, optionally: wave.pace(60) is bpm
|
||||
// 6. wave.loud(0.5); // 0% to 100% volume loudness of device output.
|
||||
// 7. wave.vary(0.5); // slows down or speeds up wiggle per harmonic
|
||||
// 8:
|
||||
// wave structure, does ToneJS allow us to change the sine wave smoothness/type continuously or is it a pre-fixed type?
|
||||
// wave structure: /\/\/, |_|, /|/, \|\| do some research with ToneJS whether these are dynamic or fixed
|
||||
// wave.itch(); // changes the shape of the wiggle from smooth sine to square or triangle
|
||||
// wave.blur(220hz); // blur may not apply/work on pure notes other than filtering them.
|
||||
|
||||
meta.edit({name: "Music", combo: ['M']});
|
||||
|
||||
meta.edit({name: "Play", combo: ['M','P'],
|
||||
on: function(eve){
|
||||
// TODO: We still need to add to meta API ability to change name.
|
||||
if(song.play){
|
||||
music.stop();
|
||||
song.play = false;
|
||||
return;
|
||||
}
|
||||
song.play = true;
|
||||
music.stop();
|
||||
setTimeout(function(){
|
||||
song.now = wave($('#page').text()).play();
|
||||
},250);
|
||||
}
|
||||
});
|
||||
|
||||
meta.edit({name: "Blur", combo: ['M','B'],
|
||||
on: function(eve){
|
||||
$(document).on('mousemove.tmp', function(eve){
|
||||
var x = eve.pageX;
|
||||
song.now.loud(x/$('body').innerWidth());
|
||||
});
|
||||
},
|
||||
up: function(){
|
||||
$(document).off('.tmp');
|
||||
}
|
||||
});
|
||||
|
||||
$(document).on('keydown', function(eve){
|
||||
if(eve.which === music.which){ return }
|
||||
music.play(String.fromCharCode(music.which = eve.which));
|
||||
});
|
||||
|
||||
}());
|
||||
;(function(){
|
||||
/*
|
||||
Edit
|
||||
Bold
|
||||
Italic
|
||||
Link
|
||||
?
|
||||
Left
|
||||
Middle
|
||||
Right
|
||||
Justify
|
||||
?
|
||||
Small
|
||||
Normal
|
||||
Header
|
||||
Title
|
||||
Design
|
||||
Add
|
||||
Row
|
||||
Column
|
||||
Text
|
||||
Delete
|
||||
Turn
|
||||
Grab
|
||||
Size
|
||||
X
|
||||
Y
|
||||
Fill
|
||||
Logic
|
||||
Symbol
|
||||
Action
|
||||
Data
|
||||
*/
|
||||
/*
|
||||
|
||||
*/
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,17 +1,13 @@
|
||||
console.log("If module not found, install express globally `npm i express -g`!");
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8765;
|
||||
console.log("If modules not found, run `npm install` in /example folder!"); // git subtree push -P examples heroku master // OR // git subtree split -P examples master && git push heroku [['HASH']]:master --force
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
||||
var express = require('express');
|
||||
var Gun = require('..');
|
||||
require('../axe');
|
||||
|
||||
var app = express();
|
||||
app.use(Gun.serve);
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
var server = app.listen(port);
|
||||
var gun = Gun({ file: 'data', web: server });
|
||||
|
||||
global.Gun = Gun; /// make global to `node --inspect` - debug only
|
||||
global.gun = gun; /// make global to `node --inspect` - debug only
|
||||
Gun({ file: 'data.json', web: server });
|
||||
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
||||
|
@ -1,439 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!-- always start with these two lines to set a clean baseline for different devices -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
<!-- link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/gun/examples/style.css" -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/examples/jquery.js"></script>
|
||||
|
||||
<title>Furball</title>
|
||||
</head>
|
||||
<body class="black whitet">
|
||||
<style>
|
||||
/*
|
||||
Choose white text on a black background so you can add color in.
|
||||
Pick your favorite font and choose a font size.
|
||||
*/
|
||||
@import url('https://fonts.googleapis.com/css?family=Mali');
|
||||
html, body {
|
||||
font-family: "Mali", sans-serif;
|
||||
}
|
||||
|
||||
.huef {
|
||||
background: #4D79D8;
|
||||
-webkit-animation: huef 9s infinite;
|
||||
animation: huef 9s infinite;
|
||||
} @keyframes huef {
|
||||
0% {background-color: #4D79D8;}
|
||||
25% {background-color: #33cc33;}
|
||||
50% {background-color: #f2b919;}
|
||||
75% {background-color: #ea3224;}
|
||||
100% {background-color: #4D79D8;}
|
||||
} @-webkit-keyframes huef {
|
||||
0% {background-color: #4D79D8;}
|
||||
25% {background-color: #33cc33;}
|
||||
50% {background-color: #f2b919;}
|
||||
75% {background-color: #ea3224;}
|
||||
100% {background-color: #4D79D8;}
|
||||
}
|
||||
|
||||
button, input {
|
||||
padding: 1em;
|
||||
background: transparent;
|
||||
border: 1px solid white;
|
||||
border-radius: 1.5em;
|
||||
color: white;
|
||||
margin: 0.5em;
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover, input:hover {
|
||||
background: white;
|
||||
color: black;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.air { padding-top: 9%; }
|
||||
.yak button { font-size: 80%; }
|
||||
|
||||
.wag {
|
||||
-webkit-animation: wag 3s infinite;
|
||||
animation: wag 3s infinite;
|
||||
} @keyframes wag {
|
||||
0% {transform: rotate(0deg);}
|
||||
50% {transform: rotate(-1deg);}
|
||||
100% {transform: rotate(0deg);}
|
||||
}
|
||||
|
||||
@keyframes print {
|
||||
0% { overflow: hidden; height: 0vh; }
|
||||
99% { overflow: hidden; height: 100vh; }
|
||||
100% { overflow: visible; height: auto; }
|
||||
}
|
||||
input {
|
||||
outline: none;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
<!-- for educational sites, consider starting with a nice full screen welcome message -->
|
||||
<div class="home hold full huef center air">
|
||||
<div class="focus row">
|
||||
<p><i>Neon ERA presents</i></p>
|
||||
<p class="shout wag">Furball Forces</p>
|
||||
<!-- just like in real life, say who you are and give a concise reason why you add value to someone's life and then make a call to action, if they want to learn more they can always scroll to learn more -->
|
||||
<div>
|
||||
<!-- a class="unit hold" href="#fullscreen"><button>WATCH TRAILER</button></a -->
|
||||
<a class="unit yak" href="#choose"><button>PLAY GAME</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="focus center row leak">
|
||||
<!-- just like in real life, looking pretty attracts attention, so show off and look glamorous! -->
|
||||
<img class="unit blink" src="file:///Users/mark/Pictures/supercatdog.png" style="min-width: 10em; width: 80%;">
|
||||
</div>
|
||||
<script>location.hash = ''</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/lib/fun.js"></script>
|
||||
<script>;(function(){
|
||||
// OPTIONAL MUSIC:
|
||||
$('.home button').on('click', function(){
|
||||
if(window.screen.height > window.screen.width){ return }
|
||||
$('body').append("<div id='audio' onclick='$(this).remove();'><iframe width='0' height='0' src='https://www.youtube-nocookie.com/embed/LLPoZGX0qZk?autoplay=1' frameborder='0'></iframe></div>");
|
||||
})
|
||||
}());
|
||||
</script>
|
||||
<style>#audio { padding: 0.5em; position: fixed; bottom: 0; left: 0; } #audio:before { content: '\25BA'; } #audio:hover:before { content: '\25FC'; }</style>
|
||||
</div>
|
||||
|
||||
<div id="choose" class="hold full hue4 center air">
|
||||
<div class="focus row">
|
||||
<p class="shout wag fur">Choose Team:</p>
|
||||
<div>
|
||||
<a class="unit yak" href="#automecha"><button style="background: white; color: black;">#AutoMecha</button></a>
|
||||
<a class="unit yak" href="#cyberninjas"><button style="background: black; color: white; border-color: black;">#CyberNinjas</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="focus center row leak">
|
||||
<img class="unit blink" src="file:///Users/mark/Pictures/supercatdog.png" style="transform: scaleX(-1); filter: invert(1); min-width: 10em; width: 80%;">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas" class="hold full black">
|
||||
<style>
|
||||
#cyberninjas:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Episode 1: Waking</p>
|
||||
<p>"How long until they're online?"</p>
|
||||
<p>"We're copying the soul files, almost done."</p>
|
||||
<p>"Monsters are on the bridge, we do not have time!"</p>
|
||||
<p>"The new body is printing now, it'll be able to outrun them all, just hold on."</p>
|
||||
<p>"It won't know where to run! We're risking ruining the whole resistance, I need to talk to it now."</p>
|
||||
<p>"95% done." The voice behind the glass turns to the soul in the body, "My cub, can you hear me?"</p>
|
||||
<p>...</p>
|
||||
<a class="unit yak" href="#cyberninjas2"><button>Reply "Yes, Mom?"</button></a>
|
||||
</div>
|
||||
<script>
|
||||
;(function(){
|
||||
$('#cyberninjas a').on('click', function(){
|
||||
$('#hud .life').removeClass('down');
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas2" class="hold full red">
|
||||
<style>
|
||||
#cyberninjas2:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
|
||||
#hud {
|
||||
opacity: 0.4;
|
||||
font-family: 'Audiowide', cursive;
|
||||
z-index: 999999999999;
|
||||
transition: all 3s;
|
||||
}
|
||||
#hud .life {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: 0px;
|
||||
padding: 0.25em 1em 0.1em;
|
||||
border-radius: 0.5em 0.5em 0 0;
|
||||
transform: translateX(-50%);
|
||||
background: black;
|
||||
text-shadow: 0em -0.125em 0.75em white;
|
||||
}
|
||||
#hud .score {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 0px;
|
||||
padding: 0.1em 1em 0.25em;
|
||||
border-radius: 0 0 0.5em 0.5em;
|
||||
transform: translateX(-50%);
|
||||
background: black;
|
||||
text-shadow: 0em 0.1em 0.75em white;
|
||||
}
|
||||
#hud .down {
|
||||
bottom: -2em !important;
|
||||
}
|
||||
#hud .up {
|
||||
top: -2em !important;
|
||||
}
|
||||
</style>
|
||||
<div id="hud">
|
||||
<div class="score shade up">
|
||||
SCORE: <span id="hudscore">0</span>%
|
||||
</div>
|
||||
<div class="life shade down">
|
||||
LIFE: <span id="hudlife">50</span>%
|
||||
</div>
|
||||
</div>
|
||||
<div class="story pad">
|
||||
<p>A fire explodes in the room behind the glass as an AutoMecha blows the door open.</p>
|
||||
<p>The floor shakes and the bed crashes through the wall, flying out of the building.</p>
|
||||
<p class="center">"Mom!!!"</p>
|
||||
<p>There is a total free fall from 10 levels up, water down below.</p>
|
||||
<p>...</p>
|
||||
<a class="unit yak" href="#cyberninjas3"><button>Dive or Die</button></a>
|
||||
</div>
|
||||
<script>
|
||||
;(function(){
|
||||
$('#cyberninjas2 a').on('click', function(){
|
||||
$('#hudlife').text($('#hudlife').data().is = 50);
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas3" class="hold full blue">
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css?family=Audiowide');
|
||||
|
||||
#cyberninjas3:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p>The water splashes, swelling and swirling all around.</p>
|
||||
<p>...</p>
|
||||
<p class="center">Rapidly tap to swim up to air:</p>
|
||||
<a class="unit yak"><button>Swim</button></a>
|
||||
</div>
|
||||
<script>
|
||||
;(function(){
|
||||
var go, life = $('#hudlife').data();
|
||||
$('#cyberninjas3 a').on('click', function(){
|
||||
$('#hudlife').text(life.is += 5);
|
||||
if(100 <= life.is){
|
||||
location.hash = 'cyberninjas4';
|
||||
clearInterval(go);
|
||||
go = false;
|
||||
return;
|
||||
}
|
||||
if(go){ return }
|
||||
go = setInterval(function(){
|
||||
if(0 >= life.is){
|
||||
location.hash = 'cyberninjas2';
|
||||
$('#hudlife').text(life.is = 50);
|
||||
clearInterval(go);
|
||||
go = false;
|
||||
return;
|
||||
}
|
||||
$('#hudlife').text(life.is -= 5);
|
||||
}, 1000); // 1 second
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas4" class="hold full black">
|
||||
<style>
|
||||
#cyberninjas4:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Episode 2: Who Am I?</p>
|
||||
<p>"Grab on!" A voice calls out from the darkness.</p>
|
||||
<p>A life vest hits the water and floats within arm's distance.</p>
|
||||
<p>The shivering body is pulled up onto the boat.</p>
|
||||
<p>"Wow, you're heavier than you look. Are you OK? What's your name?"</p>
|
||||
<p>...</p>
|
||||
<p class="center">Write your reply & hit enter:</p>
|
||||
<form class="center">
|
||||
<input class="loud" style="width: 60%;">
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
;(function(){
|
||||
$('form').on('submit', function(eve){ eve.preventDefault() });
|
||||
$('#cyberninjas4').on('submit', function(){
|
||||
var name = $(this).find('input').val();
|
||||
if(!name.length){ return }
|
||||
$('.story-name').text(' '+(window.NAME = name));
|
||||
$('#hud .score').removeClass('up');
|
||||
location.hash = 'cyberninjas5';
|
||||
})
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas5" class="hold full green">
|
||||
<style>
|
||||
#cyberninjas5:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p>"Well<span class="story-name"></span>, it's a miracle you did not die in the building explosion or from that fall."</p>
|
||||
<p>"What is going on? What happened?"</p>
|
||||
<p>"You can't remember? Your brain must be knocked up pretty hard."</p>
|
||||
<p>"No, I was mid copy into this body and now my memories are glitching."</p>
|
||||
<p>"Woah, you're one of those pro elite AREION revolutionaries? All flesh & blood! Dense, too. I would've assumed they were stealing AutoMecha tech for that instead."</p>
|
||||
<p>"I was about to be told vital data for the resistance, but then they blew up the build--"</p>
|
||||
<p>...</p>
|
||||
<p>"Hey, what's the matter?"</p>
|
||||
<p>"My mom. She was in there. I need to go back. Please, help me and tell me everything you know."</p>
|
||||
<p>"I'm so sorry. I can only get so close with the boat, you're gonna have to jump over a lot of broken bits. You ready?"</p>
|
||||
<p>...</p>
|
||||
<a class="unit yak" href="#cyberninjas6"><button>GO!</button></a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="cyberninjas6" class="hold full green">
|
||||
<style>
|
||||
#cyberninjas6:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="center">... to be continued ...</p>
|
||||
<div id="player" style="position: fixed; width: 1em; height: 1em; background: white; left: 50%; top: 50%; border-radius: 100%;"></div>
|
||||
<!-- jumping game ? like offline dinosaur ? -->
|
||||
</div>
|
||||
<script src="../../../gun/lib/meta.js"></script>
|
||||
<script>
|
||||
;(function(){
|
||||
var p = $('#player');
|
||||
p.x = 50;
|
||||
p.y = 50;
|
||||
meta.edit({
|
||||
name: "Up",
|
||||
combo: ["W"],
|
||||
on: function(){
|
||||
console.log("up");
|
||||
this.to = this.to || setInterval(this.on, 100);
|
||||
$("html, body").stop().animate({ scrollTop: $(window).scrollTop()-100 }, 100);
|
||||
p.css({top: --p.y +'%'});
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ clearTimeout(this.to); this.to = 0 }
|
||||
});
|
||||
meta.edit({
|
||||
name: "Left",
|
||||
combo: ["A"],
|
||||
on: function(){
|
||||
console.log("left");
|
||||
this.to = this.to || setInterval(this.on, 100);
|
||||
p.css({left: --p.x +'%'});
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ clearTimeout(this.to); this.to = 0 }
|
||||
});
|
||||
meta.edit({
|
||||
name: "Down",
|
||||
combo: ["S"],
|
||||
on: function on(){
|
||||
console.log("down");
|
||||
this.to = this.to || setInterval(this.on, 100);
|
||||
$("html, body").stop().animate({ scrollTop: $(window).scrollTop()+100 }, 100);
|
||||
p.css({top: ++p.y +'%'});
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ clearTimeout(this.to); this.to = 0 }
|
||||
});
|
||||
meta.edit({
|
||||
name: "Right",
|
||||
combo: ["D"],
|
||||
on: function(){
|
||||
console.log("right");
|
||||
this.to = this.to || setInterval(this.on, 100);
|
||||
p.css({left: ++p.x +'%'});
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ clearTimeout(this.to); this.to = 0 }
|
||||
});
|
||||
meta.edit({
|
||||
name: "Jump",
|
||||
combo: [32],
|
||||
on: function(){ console.log("jump") },
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Crouch",
|
||||
combo: [16],
|
||||
on: function(){ console.log("crouch") },
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Use",
|
||||
combo: ["E"],
|
||||
on: function(){ console.log("use") },
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Fire",
|
||||
combo: ["F"],
|
||||
on: function(){ console.log("fire") },
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Switch",
|
||||
combo: [9],
|
||||
on: function(){ console.log("Switch") },
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
window.requestAnimationFrame = window.requestAnimationFrame || setTimeout;
|
||||
window.requestAnimationFrame(function frame(){
|
||||
window.requestAnimationFrame(frame, 16);
|
||||
|
||||
}, 16);
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="automecha" class="hold full white blackt">
|
||||
<style>
|
||||
#automecha:target .story {
|
||||
animation: print 3s steps(50, end);
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Episode 1: Training</p>
|
||||
<p>...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="hold black center">
|
||||
<div class="pad">
|
||||
<div class="left">
|
||||
<p class="loud">For <i>You</i>,</p>
|
||||
<p>Crafted with love, <span class="redt">♥</span> by ERA.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<img src="https://era.eco/media/world.png" class="row">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -3,7 +3,7 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body style="text-align: center;">
|
||||
<h1 id="when" style="font-size: 7vw; margin-top: 43vh; font-family: monospace;"></h1>
|
||||
<h1 id="when" style="font-size: 7vw; margin-top: 43vh;"></h1>
|
||||
</body>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="/gun/nts.js"></script>
|
||||
|
@ -7,15 +7,13 @@
|
||||
<div class="laser"></div>
|
||||
</div>
|
||||
</div>
|
||||
<p id="debug" style="position: fixed; bottom: 0px; color: white; height: 1em;"></p>
|
||||
<script src="../jquery.js"></script>
|
||||
<script src="../../../gun/gun.js"></script>
|
||||
<!-- script src="../../../gun/nts.js"></script -->
|
||||
<script src="../../../gun/lib/webrtc.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="/gun/nts.js"></script>
|
||||
<script>
|
||||
// Thanks to https://github.com/dmcinnes/HTML5-Asteroids
|
||||
//var gun = Gun();
|
||||
var gun = GUN(location.origin + '/gun');
|
||||
var gun = Gun(location.origin+'/gun');
|
||||
var game = {gun: gun.get('example/game/space'), area: {}, ships: {}};
|
||||
game.keys = {38: 'up', 37: 'left', 39: 'right', 40: 'down', 32: 'space'};
|
||||
$(document).on('keydown', function(e){
|
||||
@ -50,7 +48,7 @@
|
||||
}
|
||||
game.ship = function(d, el){
|
||||
if(!d){ // spawn our ship
|
||||
var id = String.random(1, 'abcdefghijklmno');
|
||||
var id = Gun.text.random(1, 'abcdefghijklmno');
|
||||
game.me = game.ships[id] = {data: d = {id: id, t: game.now}};
|
||||
game.me.gun = game.gun.get('players').get(d.id).put(d);
|
||||
return;
|
||||
@ -101,8 +99,7 @@
|
||||
s.ay = 0;
|
||||
}
|
||||
|
||||
Object.keys(game.ships).forEach(function(key, ship){
|
||||
ship = game.ships[key];
|
||||
Gun.obj.map(game.ships, function(ship){
|
||||
if(ship.gun){ return }
|
||||
if(!ship.l){ return }
|
||||
if(ship.x-50 <= s.x && s.x <= ship.x+50
|
||||
@ -132,7 +129,7 @@
|
||||
var d = s.data;
|
||||
var dt = (now - d.t) || 0;
|
||||
if(dt > 30 * 1000){
|
||||
delete game.ships[d.id];
|
||||
Gun.obj.del(game.ships, d.id);
|
||||
s.$.remove();
|
||||
return true;
|
||||
}
|
||||
@ -160,13 +157,13 @@
|
||||
}
|
||||
return s;
|
||||
}
|
||||
localStorage.clear();
|
||||
game.sync = function(shoot){
|
||||
var me = game.me;
|
||||
if(!me || me.boom){ return }
|
||||
var keys = game.keys;
|
||||
if(shoot || keys.up || keys.right || keys.left || keys.down){
|
||||
var data = {};
|
||||
Object.keys(me.data).forEach(function(k){ data[k] = me.data[k] }); // 1 layer clone.
|
||||
var data = Gun.obj.to(me.data);
|
||||
data.x = data.x / game.area.x;
|
||||
data.y = data.y / game.area.y;
|
||||
me.gun.put(data);
|
||||
@ -181,14 +178,14 @@
|
||||
game.start = function(){
|
||||
game.now = Gun.state();
|
||||
game.resize();
|
||||
game.ship();
|
||||
game.gun.get('players').map().on(function(data, id){
|
||||
data = JSON.parse(JSON.stringify(data)); // clone object, this is bad perf tho.
|
||||
data = Gun.obj.copy(data);
|
||||
data.x = data.x * game.area.x;
|
||||
data.y = data.y * game.area.y;
|
||||
data.id = data.id || id;
|
||||
game.ship(data);
|
||||
});
|
||||
game.ship();
|
||||
var frame = game.frame, ships = game.ships;
|
||||
var last = game.now, now, diff, delta;
|
||||
setInterval(game.sync, 99);
|
||||
@ -197,8 +194,7 @@
|
||||
now = game.now = Gun.state();
|
||||
diff = now - last;
|
||||
last = now;
|
||||
Object.keys(ships).forEach(function(key, ship){
|
||||
ship = ships[key];
|
||||
Gun.obj.map(ships, function(ship){
|
||||
if(!ship.frame){ return }
|
||||
ship.frame(diff, now);
|
||||
});
|
||||
@ -207,29 +203,6 @@
|
||||
$(function(){
|
||||
game.start();
|
||||
});
|
||||
|
||||
// test WebRTC
|
||||
gun.on('hi', function(peer){
|
||||
console.log("hi!", peer);
|
||||
if(peer.url){ return }
|
||||
var peers = gun.back('opt.peers');
|
||||
Object.keys(peers).forEach(function(id, peer){
|
||||
peer = peers[id];
|
||||
if(!peer.url || !peer.wire){ return }
|
||||
peer.wire._send = peer.wire.send;
|
||||
peer.wire.send = send;
|
||||
var tmp = 'GOBBLE GOBBLE: Not sending any non-WebRTC messages to ' + peer.url;
|
||||
console.log(tmp);
|
||||
$('#debug').text(tmp);
|
||||
});
|
||||
});
|
||||
function send(raw){
|
||||
if(!raw){ return }
|
||||
if(raw.indexOf('rtc') >= 0){
|
||||
if(!this._send){ return }
|
||||
return this._send(raw);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
html, body {
|
||||
|
@ -1,331 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!-- always start with these two lines to set a clean baseline for different devices -->
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="../style.css">
|
||||
<!-- link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/gun/examples/style.css" -->
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/examples/jquery.js"></script>
|
||||
|
||||
<title>Win</title>
|
||||
</head>
|
||||
<body class="black whitet">
|
||||
<style>
|
||||
/*
|
||||
Choose white text on a black background so you can add color in.
|
||||
Pick your favorite font and choose a font size.
|
||||
*/
|
||||
@import url('https://fonts.googleapis.com/css?family=Montserrat');
|
||||
html, body {
|
||||
font-family: "Montserrat", sans-serif;
|
||||
}
|
||||
|
||||
button, input {
|
||||
padding: 1em;
|
||||
background: transparent;
|
||||
border: 1px solid white;
|
||||
border-radius: 1.5em;
|
||||
color: white;
|
||||
margin: 0.5em;
|
||||
margin-bottom: 0;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover, input:hover {
|
||||
background: white;
|
||||
color: black;
|
||||
transform: scale(1.1);
|
||||
}
|
||||
|
||||
.air { padding-top: 9%; }
|
||||
.yak button { font-size: 80%; }
|
||||
.wag {
|
||||
-webkit-animation: wag 3s infinite;
|
||||
animation: wag 3s infinite;
|
||||
} @keyframes wag {
|
||||
0% {transform: rotate(0deg);}
|
||||
50% {transform: rotate(-1deg);}
|
||||
100% {transform: rotate(0deg);}
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
<!-- for educational sites, consider starting with a nice full screen welcome message -->
|
||||
<div class="home hold full huef center air">
|
||||
<div class="focus row">
|
||||
<p><i>how to</i></p>
|
||||
<p class="shout wag">Win at Life!</p>
|
||||
<p><i>success, fame, power.</i></p>
|
||||
<p><i>sex, ethics, & integrity.</i></p>
|
||||
<!-- just like in real life, say who you are and give a concise reason why you add value to someone's life and then make a call to action, if they want to learn more they can always scroll to learn more -->
|
||||
<div>
|
||||
<!-- a class="unit hold" href="#fullscreen"><button>WATCH TRAILER</button></a -->
|
||||
<a class="unit yak gap" href="#breathe"><button>PLAY GAME</button></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="focus center row leak">
|
||||
<!-- just like in real life, looking pretty attracts attention, so show off and look glamorous! -->
|
||||
<img class="unit blink" src="" style="min-width: 10em; width: 80%;">
|
||||
</div>
|
||||
<script>location.hash = ''</script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gun/lib/fun.js"></script>
|
||||
</div>
|
||||
|
||||
<div id="breathe" class="hold full green">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Step 1: Breathe</p>
|
||||
<a class="unit yak" href="#water"><button>Yupe</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="water" class="hold full blue">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Step 2: Drink Water</p>
|
||||
<p></p>
|
||||
<a class="unit yak" href="#eat"><button>Next</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="eat" class="hold full red">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Step 3: Eat Once a Day</p>
|
||||
<p>If you do not want to be eaten, do not eat things that would not want to be eaten.</p>
|
||||
<a class="unit yak" href="#babies"><button>Got It</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="babies" class="hold full red">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Step 4: Babymaking* 😉</p>
|
||||
<p>Find a willing player.</p>
|
||||
<p><small> * This does not always make babies.</small></p>
|
||||
<a class="unit yak" href="#make"><button>How?</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="make" class="hold full hue">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Step 5: Make Dance</p>
|
||||
<p>Moving your body is how you express your thoughts.</p>
|
||||
<p>What you do with your body is what others will come to know you for. So do well.</p>
|
||||
<p>You can make art, songs, or stories; You can make science, tools, or discoveries.</p>
|
||||
<p>Who are you?</p>
|
||||
<a class="unit yak" href="#science"><button>I am a Scientist!</button></a>
|
||||
<a class="unit yak" href="#art"><button>I am an Artist!</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="science" class="hold full hue">
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Science: Knowing Games</p>
|
||||
<p>If you must win one game, it should be the game of making games.</p>
|
||||
<p>If you can make any game, then you will know how to win any game.</p>
|
||||
<a class="unit yak" href="#games"><button>Games?</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="games" class="hold full hue">
|
||||
<div class="story pad">
|
||||
<p>Games have goals and play.</p>
|
||||
<p>Play is a safe space to try new dances.</p>
|
||||
<p>Goals try to get players to do a type of dance.</p>
|
||||
<a class="unit yak" href="#swim"><button>Start</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="swim" class="hold full blue">
|
||||
<style>
|
||||
@import url('https://fonts.googleapis.com/css?family=Audiowide');
|
||||
#hud {
|
||||
opacity: 0.4;
|
||||
font-family: 'Audiowide', cursive;
|
||||
z-index: 999999999999;
|
||||
transition: all 3s;
|
||||
}
|
||||
#hud .life {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
bottom: 0px;
|
||||
padding: 0.25em 1em 0.1em;
|
||||
border-radius: 0.5em 0.5em 0 0;
|
||||
transform: translateX(-50%);
|
||||
background: black;
|
||||
text-shadow: 0em -0.125em 0.75em white;
|
||||
}
|
||||
#hud .score {
|
||||
position: fixed;
|
||||
left: 50%;
|
||||
top: 0px;
|
||||
padding: 0.1em 1em 0.25em;
|
||||
border-radius: 0 0 0.5em 0.5em;
|
||||
transform: translateX(-50%);
|
||||
background: black;
|
||||
text-shadow: 0em 0.1em 0.75em white;
|
||||
}
|
||||
#hud .down {
|
||||
bottom: -2em !important;
|
||||
}
|
||||
#hud .up {
|
||||
top: -2em !important;
|
||||
}
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p>The simplest goal is to not "die" in the game.</p>
|
||||
<p>Oh look, you've fallen into water and cannot breathe.</p>
|
||||
<p>If you do not push the button to swim to the top, you'll lose the game.</p>
|
||||
<a class="unit yak"><button>Swim</button></a>
|
||||
</div>
|
||||
<div id="hud">
|
||||
<div class="score shade up">
|
||||
SCORE: <span id="hudscore">0</span>%
|
||||
</div>
|
||||
<div class="life shade down">
|
||||
LIFE: <span id="hudlife">100</span>%
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
;(function(){
|
||||
var go, life = $('#hudlife').data();
|
||||
$(window).on('hashchange', function(){
|
||||
if(location.hash != '#swim'){ return }
|
||||
$('#hudlife').text($('#hudlife').data().is = 100);
|
||||
$('#hud .life').removeClass('down');
|
||||
go = setInterval(function(){
|
||||
if(0 >= life.is){
|
||||
location.hash = 'die';
|
||||
clearInterval(go);
|
||||
go = false;
|
||||
return;
|
||||
}
|
||||
$('#hudlife').text(life.is -= 1);
|
||||
}, 100);
|
||||
})
|
||||
$('#swim a').on('click', function(){
|
||||
$('#hudlife').text((life.is += 5) < 100? life.is : 100);
|
||||
if(100 <= life.is){
|
||||
location.hash = 'won';
|
||||
clearInterval(go);
|
||||
go = false;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}());
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="won" class="hold full hue">
|
||||
<div class="story pad">
|
||||
<p>You won your first game! 🎉</p>
|
||||
<p>See? I told you breathing is important.</p>
|
||||
<p>You also learned the most basic dance: rapid poking.</p>
|
||||
<p>The goal of the next game is to make the game you just won.</p>
|
||||
<a class="unit yak" href="#won" style="z-index: 999999;"><button>Make</button></a>
|
||||
</div>
|
||||
<script src="https://cdn.jsdelivr.net/gh/amark/gun/lib/meta.js"></script>
|
||||
<script>
|
||||
meta.edit({name: "Add", combo: ['A']});
|
||||
meta.edit({
|
||||
name: "Timer",
|
||||
combo: ['A','T'],
|
||||
on: function(){
|
||||
console.log("up");
|
||||
this.to = this.to || setInterval(this.on, 100);
|
||||
$("html, body").stop().animate({ scrollTop: $(window).scrollTop()-100 }, 100);
|
||||
p.css({top: --p.y +'%'});
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ clearTimeout(this.to); this.to = 0 }
|
||||
});
|
||||
meta.edit({
|
||||
name: "Delete",
|
||||
combo: ['A','D'],
|
||||
on: function(){
|
||||
$(meta.tap.on).remove();
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Button",
|
||||
combo: ['A','B'],
|
||||
on: function(){
|
||||
$(meta.tap.on).append("<a class='unit yak'><button>Button</button></a>")
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){}
|
||||
});
|
||||
meta.edit({
|
||||
name: "Edit",
|
||||
combo: ['E'],
|
||||
on: function(){
|
||||
$('body').attr('contenteditable', 'true' == $('body').attr('contenteditable')? false : true);
|
||||
},
|
||||
use: function(){},
|
||||
up: function(){ }
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
window.requestAnimationFrame(function frame(){
|
||||
return;
|
||||
window.requestAnimationFrame(frame);
|
||||
if(location.hash != '#won'){ return }
|
||||
var p = $('#won a').offset();
|
||||
var bx = p.left, by = p.top, mx = meta.tap.x, my = meta.tap.y;
|
||||
bx = mx - bx; by = my - by;
|
||||
var d = Math.sqrt(bx*bx + by*by);
|
||||
console.log(bx, by, mx, my, d);
|
||||
if(d > 250){ return }
|
||||
$('#won a').css({position: 'fixed', left: bx + (Math.random()*100), top: by + (Math.random()*100)});
|
||||
})
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="rules" class="hold full white blackt">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">Bend these Rules if it is more Moral to do so</p>
|
||||
<p></p>
|
||||
<a class="unit yak" href="#water"><button>Next</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="die" class="hold full red">
|
||||
<style>
|
||||
</style>
|
||||
<div class="story pad">
|
||||
<p class="loud crack">GAME OVER</p>
|
||||
<p></p>
|
||||
<a class="unit yak" href="#make"><button>Start Over</button></a>
|
||||
</div>
|
||||
<script>
|
||||
</script>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,11 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Where</title>
|
||||
<title>GPS by GUN</title>
|
||||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.0.3/dist/leaflet.css"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.0.3/dist/leaflet.js"></script>
|
||||
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.0.3/dist/leaflet.css"/>
|
||||
<script src="https://unpkg.com/leaflet@1.0.3/dist/leaflet.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
@ -29,7 +29,7 @@
|
||||
height: 100%;
|
||||
font-family: Arial;
|
||||
font-size: 16pt;
|
||||
z-index: 1;
|
||||
z-index: -1;
|
||||
}
|
||||
.stick {
|
||||
position: absolute;
|
||||
@ -42,7 +42,6 @@
|
||||
opacity: .5;
|
||||
background: blue;
|
||||
color: white;
|
||||
z-index: 7;
|
||||
transition: .25s all;
|
||||
}
|
||||
.button:hover {
|
||||
@ -60,7 +59,6 @@
|
||||
bottom: 2em;
|
||||
background: white;
|
||||
overflow: scroll;
|
||||
z-index: 9;
|
||||
}
|
||||
#follow {
|
||||
background: #EEE;
|
||||
@ -68,8 +66,8 @@
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
|
||||
<script src="https://gunjs.herokuapp.com/gun.js"></script>
|
||||
<script>
|
||||
function Where(opt, cb){
|
||||
// a small wrapper around Leaflet for map tracking.
|
||||
@ -96,7 +94,7 @@
|
||||
where.map.on('zoomlevelschange', where.opt.zoom.ing, where.opt.err);
|
||||
|
||||
where.update = function(latlng){
|
||||
if((+new Date) - where.update.last < 400){
|
||||
if(new Date().getTime() - where.update.last < 1000){
|
||||
clearTimeout(where.update.to);
|
||||
where.update.to = setTimeout(function(){
|
||||
where.update(latlng);
|
||||
@ -106,7 +104,7 @@
|
||||
where.map.setView(latlng, where.opt.zoom.level, {animate: true});
|
||||
where.marker = where.marker || L.marker().setLatLng(latlng).addTo(where.map);
|
||||
where.marker.setLatLng(latlng).update();
|
||||
where.update.last = (+new Date);
|
||||
where.update.last = new Date().getTime();
|
||||
}
|
||||
|
||||
if(where.opt.track){
|
||||
@ -131,7 +129,7 @@
|
||||
<script>
|
||||
;(function(){
|
||||
// the actual GPS tracking app!
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
var gun = Gun('https://gunjs.herokuapp.com/gun');
|
||||
var gps = {};
|
||||
gps.opt = {
|
||||
continuous: true, // get location just once uses `getCurrentPosition()` while continuously uses `watchPosition()`
|
||||
@ -149,7 +147,7 @@
|
||||
//$('#debug').value = 'track ' + JSON.stringify(latlng);
|
||||
gps.where.update(latlng);
|
||||
});
|
||||
$('#share').addClass("hide");
|
||||
$('#share').toggleClass("hide");
|
||||
} else {
|
||||
document.cookie = 'gps=' + (gps.track = (document.cookie.match(/gps\=(.*?)(\&|$|\;)/i)||[])[1] || Gun.text.random(5)); // trick with cookies!
|
||||
gps.ref = gun.get('gps/' + gps.track);
|
||||
@ -165,8 +163,8 @@
|
||||
//$('#debug').value = JSON.stringify(gps.last);
|
||||
}
|
||||
gps.where = gps.where || Where(gps.opt);
|
||||
$('#follow').text(("where.gunDB.io/" || (location.origin + location.pathname)) + '#' + gps.track);
|
||||
$('#share').removeClass("hide");
|
||||
$('#follow').text(("gps.gunDB.io/" || (location.origin + location.pathname)) + '#' + gps.track);
|
||||
$('#share').toggleClass("hide");
|
||||
$('#share').on('click', function(){
|
||||
$('#link').toggleClass("hide");
|
||||
});
|
@ -1,42 +1,17 @@
|
||||
console.log("If module not found, install hapi globally `npm i hapi inert -g`!")
|
||||
|
||||
const Hapi = require('hapi')
|
||||
const Inert = require('inert')
|
||||
const Gun = require('..')
|
||||
|
||||
const server = new Hapi.Server({
|
||||
port: 8765,
|
||||
host: 'localhost',
|
||||
routes: {
|
||||
files: {
|
||||
relativeTo: require('path').join(__dirname, '..')
|
||||
}
|
||||
}
|
||||
})
|
||||
const server = new Hapi.Server
|
||||
server.connection({ port: 8080 })
|
||||
server.connections.forEach(c => Gun({ web: c.listener, file: 'data.json' }))
|
||||
|
||||
async function runtime() {
|
||||
|
||||
const db = new Gun({
|
||||
web: server.listener,
|
||||
file: 'data.json'
|
||||
})
|
||||
|
||||
await server.register(Inert)
|
||||
server.register(Inert, () => {});
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/gun.js',
|
||||
handler: {
|
||||
file: 'gun.min.js'
|
||||
}
|
||||
})
|
||||
|
||||
server.route({
|
||||
method: 'GET',
|
||||
path: '/gun/nts.js',
|
||||
handler: {
|
||||
file: 'nts.js'
|
||||
}
|
||||
handler: (request, reply) => reply.file('../gun.js', { confine: false })
|
||||
})
|
||||
|
||||
server.route({
|
||||
@ -51,8 +26,4 @@ async function runtime() {
|
||||
}
|
||||
})
|
||||
|
||||
await server.start()
|
||||
console.log('Server running at:', server.info.uri)
|
||||
}
|
||||
|
||||
runtime()
|
||||
server.start()
|
||||
|
19
examples/hello-world.js
Normal file
@ -0,0 +1,19 @@
|
||||
var Gun = require('../');
|
||||
var gun = Gun({
|
||||
file: 'data.json',
|
||||
s3: {
|
||||
key: '', // AWS Access Key
|
||||
secret: '', // AWS Secret Token
|
||||
bucket: '' // The bucket you want to save into
|
||||
}
|
||||
});
|
||||
gun.put({ hello: 'world' }).key('my/first/data');
|
||||
|
||||
var http = require('http');
|
||||
http.createServer(function(req, res){
|
||||
gun.get('my/first/data', function(err, data){
|
||||
res.writeHead(200, {'Content-Type': 'application/json'});
|
||||
res.end(JSON.stringify(data));
|
||||
});
|
||||
}).listen(1337, '127.0.0.1');
|
||||
console.log('Server running at http://127.0.0.1:1337/');
|
66
examples/http-external-ws.js
Normal file
@ -0,0 +1,66 @@
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
||||
|
||||
var Gun = require('../');
|
||||
|
||||
// have to do this before instancing gun(?)
|
||||
Gun.on('out', function(msg){
|
||||
this.to.next( msg );
|
||||
msg = JSON.stringify(msg);
|
||||
gunPeers.forEach( function(peer){ peer.send( msg ) })
|
||||
})
|
||||
|
||||
var gun = Gun({
|
||||
file: 'data.json'
|
||||
});
|
||||
|
||||
var server = require('http').createServer(function(req, res){
|
||||
var insert = "";
|
||||
if( req.url.endsWith( "gun.js" ) )
|
||||
insert = "../";
|
||||
|
||||
require('fs').createReadStream(require('path').join(__dirname, insert, req.url)).on('error',function(){ // static files!
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(require('fs').readFileSync(require('path').join(__dirname, 'index.html'))); // or default to index
|
||||
}).pipe(res); // stream
|
||||
});
|
||||
|
||||
// do not do this to attach server... instead pull websocket provider and use that.
|
||||
// gun.wsp(server);
|
||||
|
||||
var ws = require( 'ws' ); // default websocket provider gun used...
|
||||
var WebSocketServer = ws.Server;
|
||||
|
||||
var wss = new WebSocketServer( {
|
||||
server: server, // 'ws' npm
|
||||
autoAcceptConnections : false // want to handle the request (websocket npm?)
|
||||
});
|
||||
|
||||
wss.on('connection',acceptConnection )
|
||||
|
||||
var gunPeers = []; // used as a list of connected clients.
|
||||
|
||||
function acceptConnection( connection ) {
|
||||
// connection.upgradeReq.headers['sec-websocket-protocol'] === (if present) protocol requested by client
|
||||
// connection.upgradeReq.url === url request
|
||||
console.log( "connect?", connection.upgradeReq.headers, connection.upgradeReq.url )
|
||||
gunPeers.push( connection );
|
||||
connection.on( 'error',function(error){console.log( "WebSocket Error:", error) } );
|
||||
|
||||
connection.on('message', function (msg) {
|
||||
msg = JSON.parse(msg)
|
||||
if ("forEach" in msg) msg.forEach(m => gun.on('in', JSON.parse(m)));
|
||||
else gun.on('in', msg)
|
||||
})
|
||||
|
||||
connection.on( 'close', function(reason,desc){
|
||||
// gunpeers gone.
|
||||
var i = gunPeers.findIndex( function(p){return p===connection} );
|
||||
if( i >= 0 )
|
||||
gunPeers.splice( i, 1 );
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
server.listen(port);
|
||||
|
||||
console.log('Server started on port ' + port + ' with ');
|
@ -1,34 +1,30 @@
|
||||
;(function(){
|
||||
var cluster = require('cluster');
|
||||
if(cluster.isMaster){
|
||||
return cluster.fork() && cluster.on('exit',function(){ cluster.fork(); require('../lib/crashed') });
|
||||
}
|
||||
var port = process.env.OPENSHIFT_NODEJS_PORT || process.env.VCAP_APP_PORT || process.env.PORT || process.argv[2] || 8080;
|
||||
|
||||
var fs = require('fs'), env = process.env;
|
||||
var GUN = require('../'); // require('gun');
|
||||
var opt = {
|
||||
port: env.PORT || process.argv[2] || 8765,
|
||||
peers: env.PEERS && env.PEERS.split(',') || []
|
||||
};
|
||||
var Gun = require('../');
|
||||
|
||||
if(fs.existsSync((opt.home = require('os').homedir())+'/cert.pem')){
|
||||
env.HTTPS_KEY = env.HTTPS_KEY || opt.home+'/key.pem';
|
||||
env.HTTPS_CERT = env.HTTPS_CERT || opt.home+'/cert.pem';
|
||||
}
|
||||
if(env.HTTPS_KEY){
|
||||
opt.port = 443;
|
||||
opt.key = fs.readFileSync(env.HTTPS_KEY);
|
||||
opt.cert = fs.readFileSync(env.HTTPS_CERT);
|
||||
opt.server = require('https').createServer(opt, GUN.serve(__dirname));
|
||||
require('http').createServer(function(req, res){
|
||||
res.writeHead(301, {"Location": "https://"+req.headers['host']+req.url });
|
||||
res.end();
|
||||
}).listen(80);
|
||||
} else {
|
||||
opt.server = require('http').createServer(GUN.serve(__dirname));
|
||||
}
|
||||
var server = require('http').createServer(function(req, res){
|
||||
if(Gun.serve(req, res)){ return } // filters gun requests!
|
||||
require('fs').createReadStream(require('path').join(__dirname, req.url)).on('error',function(){ // static files!
|
||||
res.writeHead(200, {'Content-Type': 'text/html'});
|
||||
res.end(require('fs')
|
||||
.readFileSync(require('path')
|
||||
.join(__dirname, 'index.html') // or default to index
|
||||
));
|
||||
}).pipe(res); // stream
|
||||
});
|
||||
|
||||
var gun = GUN({web: opt.server.listen(opt.port), peers: opt.peers});
|
||||
console.log('Relay peer started on port ' + opt.port + ' with /gun');
|
||||
module.exports = gun;
|
||||
}());
|
||||
var gun = Gun({
|
||||
file: 'data.json',
|
||||
web: server,
|
||||
s3: {
|
||||
key: '', // AWS Access Key
|
||||
secret: '', // AWS Secret Token
|
||||
bucket: '' // The bucket you want to save into
|
||||
}
|
||||
});
|
||||
// Sync everything
|
||||
gun.on('out', {get: {'#': {'*': ''}}});
|
||||
|
||||
server.listen(port);
|
||||
|
||||
console.log('Server started on port ' + port + ' with /gun');
|
||||
|
@ -1,8 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd ~
|
||||
git clone https://github.com/acmesh-official/acme.sh.git
|
||||
cd ~/acme.sh
|
||||
./acme.sh --install -m $EMAIL
|
||||
|
||||
bash ~/acme.sh/acme.sh --issue -d $DOMAIN -w $WEB
|
||||
bash ~/acme.sh/acme.sh --install-cert -d $DOMAIN --key-file ~/key.pem --fullchain-file ~/cert.pem --reloadcmd "service relay force-reload"
|
@ -1,4 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<p>This is the examples folder.
|
||||
<p>The most basic example is <a href="./basic/note.html">./basic/note.html</a>!</p>
|
||||
<p>Home page temporarily disabled.</p>
|
||||
<html>
|
||||
<head>
|
||||
<title>gun examples</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- h1>Examples Directory <button style="float: right;" onclick="localStorage.clear()">Clear Local Storage</button></h1 -->
|
||||
<style>
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
iframe {
|
||||
width: 100%;
|
||||
height: 50%;
|
||||
border: none;
|
||||
b-order-top: ridge 2em skyblue;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
<a href="/todo/index.html"><iframe src="/todo/index.html"></iframe></a>
|
||||
<!-- a href="/json/index.html"><iframe src="/json/index.html"></iframe></a -->
|
||||
<a href="/chat/index.html"><iframe src="/chat/index.html"></iframe></a>
|
||||
<!-- script src="../gun.js"></script -->
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,116 +0,0 @@
|
||||
const DEFAULT_OPTIONS = {
|
||||
size: 20,
|
||||
stickTo: 'top',
|
||||
};
|
||||
|
||||
class ScrollWindow {
|
||||
constructor(gunNode, opts = {}) {
|
||||
this.opts = Object.assign(DEFAULT_OPTIONS, opts);
|
||||
this.elements = new Map();
|
||||
this.node = gunNode;
|
||||
this.center = this.opts.startAt;
|
||||
this.updateSubscriptions();
|
||||
}
|
||||
|
||||
updateSubscriptions() {
|
||||
this.upSubscription && this.upSubscription.off();
|
||||
this.downSubscription && this.downSubscription.off();
|
||||
|
||||
const subscribe = params => {
|
||||
this.node.get({ '.': params}).map().on((val, key, a, eve) => {
|
||||
if (params['-']) {
|
||||
this.downSubscription = eve;
|
||||
} else {
|
||||
this.upSubscription = eve;
|
||||
}
|
||||
this._addElement(key, val);
|
||||
});
|
||||
};
|
||||
|
||||
if (this.center) {
|
||||
subscribe({ '>': this.center, '<': '\uffff' });
|
||||
subscribe({'<': this.center, '>' : '', '-': true});
|
||||
} else {
|
||||
subscribe({ '<': '\uffff', '>': '', '-': this.opts.stickTo === 'top' });
|
||||
}
|
||||
}
|
||||
|
||||
_getSortedKeys() {
|
||||
this.sortedKeys = this.sortedKeys || [...this.elements.keys()].sort();
|
||||
return this.sortedKeys;
|
||||
}
|
||||
|
||||
_upOrDown(n, up) {
|
||||
this.opts.stickTo = null;
|
||||
const keys = this._getSortedKeys();
|
||||
n = n || (keys.length / 2);
|
||||
n = up ? n : -n;
|
||||
const half = Math.floor(keys.length / 2);
|
||||
const newMiddleIndex = Math.max(Math.min(half + n, keys.length - 1), 0);
|
||||
if (this.center !== keys[newMiddleIndex]) {
|
||||
this.center = keys[newMiddleIndex];
|
||||
this.updateSubscriptions();
|
||||
}
|
||||
return this.center;
|
||||
}
|
||||
|
||||
up(n) {
|
||||
return this._upOrDown(n, true);
|
||||
}
|
||||
|
||||
down(n) {
|
||||
return this._upOrDown(n, false);
|
||||
}
|
||||
|
||||
_topOrBottom(top) {
|
||||
this.opts.stickTo = top ? 'top' : 'bottom';
|
||||
this.center = null;
|
||||
this.updateSubscriptions();
|
||||
}
|
||||
|
||||
top() {
|
||||
this._topOrBottom(true);
|
||||
}
|
||||
|
||||
bottom() {
|
||||
this._topOrBottom(false);
|
||||
}
|
||||
|
||||
_addElement(key, val) {
|
||||
if (!val || this.elements.has(key)) return;
|
||||
const add = () => {
|
||||
this.elements.set(key, val);
|
||||
this.sortedKeys = [...this.elements.keys()].sort();
|
||||
const sortedElements = this.sortedKeys.map(k => this.elements.get(k));
|
||||
this.opts.onChange && this.opts.onChange(sortedElements);
|
||||
};
|
||||
const keys = this._getSortedKeys();
|
||||
if (keys.length < this.opts.size) {
|
||||
add();
|
||||
} else {
|
||||
if (this.opts.stickTo === 'top' && key > keys[0]) {
|
||||
this.elements.delete(keys[0]);
|
||||
add();
|
||||
} else if (this.opts.stickTo === 'bottom' && key < keys[keys.length - 1]) {
|
||||
this.elements.delete(keys[keys.length - 1]);
|
||||
add();
|
||||
} else if (this.center) {
|
||||
if (keys.indexOf(this.center) < (keys.length / 2)) {
|
||||
if (key < keys[keys.length - 1]) {
|
||||
this.elements.delete(keys[keys.length - 1]);
|
||||
add();
|
||||
}
|
||||
} else {
|
||||
if (key > keys[0]) {
|
||||
delete this.elements.delete(keys[0]);
|
||||
add();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
getElements() {
|
||||
return this.elements;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Infinite scroll example</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
|
||||
<link rel="stylesheet" type="text/css" href="./style.css">
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script src="./ScrollWindow.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<form id="generate">
|
||||
<input type="text" id="number" placeholder="Number of posts"/>
|
||||
<button>Generate</button>
|
||||
</form>
|
||||
<div id="top-buttons">
|
||||
<button id="top">Top</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div id="top-sentinel" style="padding-top: 0px;"></div>
|
||||
<div id="container"></div>
|
||||
<div id="bottom-sentinel" style="padding-top: 0px;"></div>
|
||||
|
||||
<button id="bottom">Bottom</button>
|
||||
|
||||
<script src="./index.js"></script>
|
||||
</body>
|
||||
</html>
|
@ -1,167 +0,0 @@
|
||||
const gun = new Gun();
|
||||
|
||||
const size = 20;
|
||||
const gunNode = gun.get('posts');
|
||||
|
||||
function debounce(func, wait, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
var context = this, args = arguments;
|
||||
var later = function() {
|
||||
timeout = null;
|
||||
if (!immediate) func.apply(context, args);
|
||||
};
|
||||
var callNow = immediate && !timeout;
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(later, wait);
|
||||
if (callNow) func.apply(context, args);
|
||||
};
|
||||
};
|
||||
|
||||
let topSentinelPreviousY = 0;
|
||||
let topSentinelPreviousRatio = 0;
|
||||
let bottomSentinelPreviousY = 0;
|
||||
let bottomSentinelPreviousRatio = 0;
|
||||
let previousUpIndex = previousDownIndex = -1;
|
||||
|
||||
const render = elements => {
|
||||
const t = new Date();
|
||||
elements.reverse().forEach((data, j) => {
|
||||
var date = new Date(data.date);
|
||||
$('#date' + j).text(date.toLocaleDateString() + ' ' + date.toLocaleTimeString());
|
||||
$('#text' + j).text(data.text);
|
||||
$('#img' + j).attr('src', '');
|
||||
$('#img' + j).attr('src', _getCatImg(date.getTime()));
|
||||
$('#post' + j).css({visibility: 'visible'});
|
||||
});
|
||||
console.log('rendering took', new Date().getTime() - t.getTime(), 'ms');
|
||||
window.onRender && window.onRender(elements);
|
||||
};
|
||||
|
||||
const onChange = debounce(render, 20);
|
||||
|
||||
const scroller = new ScrollWindow(gunNode, {size, stickTo: 'top', onChange});
|
||||
|
||||
const initList = () => {
|
||||
for (var n = 0; n < size; n++) {
|
||||
var el = $("<div>").addClass('post').attr('id', 'post' + n).css({visibility: 'hidden'});
|
||||
el.append($('<b>').attr('id', 'date' + n));
|
||||
el.append($('<span>').attr('id', 'text' + n));
|
||||
el.append($('<img>').attr('id', 'img' + n).attr('height', 100).attr('width', 100));
|
||||
$('#container').append(el);
|
||||
}
|
||||
}
|
||||
|
||||
const _getCatImg = (n) => {
|
||||
const url = "https://source.unsplash.com/collection/139386/100x100/?sig=";
|
||||
return url + n % 999999;
|
||||
};
|
||||
|
||||
const getNumFromStyle = numStr => Number(numStr.substring(0, numStr.length - 2));
|
||||
|
||||
const adjustPaddings = isScrollDown => {
|
||||
const container = document.getElementById("container");
|
||||
const currentPaddingTop = getNumFromStyle(container.style.paddingTop);
|
||||
const currentPaddingBottom = getNumFromStyle(container.style.paddingBottom);
|
||||
const remPaddingsVal = 198 * (size / 2); // TODO: calculate actual element heights
|
||||
if (isScrollDown) {
|
||||
container.style.paddingTop = currentPaddingTop + remPaddingsVal + "px";
|
||||
container.style.paddingBottom = currentPaddingBottom === 0 ? "0px" : currentPaddingBottom - remPaddingsVal + "px";
|
||||
} else {
|
||||
container.style.paddingBottom = currentPaddingBottom + remPaddingsVal + "px";
|
||||
if (currentPaddingTop === 0) {
|
||||
$(window).scrollTop($('#post0').offset().top + remPaddingsVal);
|
||||
} else {
|
||||
container.style.paddingTop = currentPaddingTop - remPaddingsVal + "px";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const topSentCallback = entry => {
|
||||
const container = document.getElementById("container");
|
||||
|
||||
const currentY = entry.boundingClientRect.top;
|
||||
const currentRatio = entry.intersectionRatio;
|
||||
const isIntersecting = entry.isIntersecting;
|
||||
|
||||
// conditional check for Scrolling up
|
||||
if (
|
||||
currentY > topSentinelPreviousY &&
|
||||
isIntersecting &&
|
||||
currentRatio >= topSentinelPreviousRatio &&
|
||||
scroller.center !== previousUpIndex && // stop if no new results were received
|
||||
scroller.opts.stickTo !== 'top'
|
||||
) {
|
||||
previousUpIndex = scroller.center;
|
||||
adjustPaddings(false);
|
||||
scroller.up(size / 2);
|
||||
}
|
||||
topSentinelPreviousY = currentY;
|
||||
topSentinelPreviousRatio = currentRatio;
|
||||
}
|
||||
|
||||
const botSentCallback = entry => {
|
||||
const currentY = entry.boundingClientRect.top;
|
||||
const currentRatio = entry.intersectionRatio;
|
||||
const isIntersecting = entry.isIntersecting;
|
||||
|
||||
// conditional check for Scrolling down
|
||||
if (
|
||||
currentY < bottomSentinelPreviousY &&
|
||||
currentRatio > bottomSentinelPreviousRatio &&
|
||||
isIntersecting &&
|
||||
scroller.center !== previousDownIndex && // stop if no new results were received
|
||||
scroller.opts.stickTo !== 'bottom'
|
||||
) {
|
||||
previousDownIndex = scroller.center;
|
||||
adjustPaddings(true);
|
||||
scroller.down(size / 2);
|
||||
}
|
||||
bottomSentinelPreviousY = currentY;
|
||||
bottomSentinelPreviousRatio = currentRatio;
|
||||
}
|
||||
|
||||
const initIntersectionObserver = () => {
|
||||
const options = {
|
||||
//rootMargin: '190px',
|
||||
}
|
||||
|
||||
const callback = entries => {
|
||||
entries.forEach(entry => {
|
||||
if (entry.target.id === 'post0') {
|
||||
topSentCallback(entry);
|
||||
} else if (entry.target.id === `post${size - 1}`) {
|
||||
botSentCallback(entry);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var observer = new IntersectionObserver(callback, options); // TODO: It's possible to quickly scroll past the sentinels without them firing. Top and bottom sentinels should extend to page top & bottom?
|
||||
observer.observe(document.querySelector("#post0"));
|
||||
observer.observe(document.querySelector(`#post${size - 1}`));
|
||||
}
|
||||
|
||||
initList(size);
|
||||
initIntersectionObserver();
|
||||
|
||||
$('#top').click(() => {
|
||||
scroller.top();
|
||||
$('#container').css({'padding-top': 0, 'padding-bottom': 0});
|
||||
$(document.body).animate({ scrollTop: 0 }, 500);
|
||||
});
|
||||
$('#bottom').click(() => {
|
||||
scroller.bottom();
|
||||
$('#container').css({'padding-top': 0, 'padding-bottom': 0});
|
||||
$(document.body).animate({ scrollTop: $("#container").height() }, 500);
|
||||
});
|
||||
|
||||
$('#generate').submit(e => {
|
||||
e.preventDefault();
|
||||
const day = 24 * 60 * 60 * 1000;
|
||||
const year = 365 * day;
|
||||
const n = Number($('#number').val());
|
||||
for (let i = 0; i < n; i++) {
|
||||
const d = new Date(40 * year + i * day).toISOString();
|
||||
gunNode.get(d).put({text: 'Hello world!', date: d});
|
||||
}
|
||||
});
|
@ -1,77 +0,0 @@
|
||||
html, body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body {
|
||||
padding-top: 65px;
|
||||
}
|
||||
|
||||
header {
|
||||
background: rgba(255,255,255,0.75);
|
||||
padding: 15px;
|
||||
}
|
||||
|
||||
header {
|
||||
position: fixed;
|
||||
top: 0; left: 0; right: 0;
|
||||
}
|
||||
|
||||
#bottom {
|
||||
position: fixed;
|
||||
right: 15px;
|
||||
bottom: 15px;
|
||||
}
|
||||
|
||||
input {
|
||||
border: 0;
|
||||
background-color: #efefef;
|
||||
padding: 15px;
|
||||
border-radius: 50px;
|
||||
}
|
||||
|
||||
button {
|
||||
background-color: #4a4f9d;
|
||||
border: 0;
|
||||
padding: 15px;
|
||||
color: white;
|
||||
border-radius: 50px;
|
||||
}
|
||||
|
||||
input, button {
|
||||
outline: none;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
input:focus, button:focus, button:hover {
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
button:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
#top-buttons, form {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
#top-buttons {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.post {
|
||||
margin: 15px;
|
||||
padding: 15px;
|
||||
background-color: #9de1fe;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.post b {
|
||||
margin-right: 5;
|
||||
}
|
||||
|
||||
.post img {
|
||||
display: block;
|
||||
margin: 10px 0;
|
||||
}
|
@ -3,51 +3,25 @@
|
||||
# README
|
||||
# This will install nodejs and npm on your system,
|
||||
# should work on most places other than Windows.
|
||||
# For it to run on boot as a server, a recent OS is needed.
|
||||
# Set any environment variables before you run this,
|
||||
# like `export RAD=false` to disable storage, or
|
||||
# pass file paths of `HTTPS_CERT` & `HTTPS_KEY`, etc.
|
||||
# Copy paste and run each line into your terminal.
|
||||
# If you are on Windows, http://nodejs.org/download/ has
|
||||
# an installer that will automatically do it for you.
|
||||
# curl -o- https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash
|
||||
# wget -O - https://raw.githubusercontent.com/amark/gun/master/examples/install.sh | bash
|
||||
# a installer that will automatically do it for you.
|
||||
|
||||
#debian/ubuntu
|
||||
cd ~
|
||||
apt-get install sudo -y
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install curl git git-core systemd -y
|
||||
sudo apt-get install systemctl -y
|
||||
sudo apt-get install curl git git-core -y
|
||||
#fedora/openSUSE
|
||||
sudo yum check-update -y
|
||||
sudo yum install curl git git-core systemd -y
|
||||
sudo yum install systemctl -y
|
||||
|
||||
#screen -S install # You can safely CTRL+A+D to escape without stopping the process. `screen -R install` to resume. Stop all with `killall screen`. Note: May need to `sudo apt-get install screen`
|
||||
sudo yum install curl git git-core -y
|
||||
|
||||
# install nodejs
|
||||
git clone https://github.com/isaacs/nave.git
|
||||
./nave/nave.sh usemain stable
|
||||
|
||||
git clone http://github.com/isaacs/nave.git
|
||||
sudo ./nave/nave.sh usemain stable
|
||||
# If you just want nodejs and npm but not gun, stop here.
|
||||
#npm install gun@latest
|
||||
#cd ./node_modules/gun
|
||||
mkdir node_modules
|
||||
git clone https://github.com/amark/gun.git
|
||||
cd gun
|
||||
git checkout .
|
||||
git pull
|
||||
git checkout master
|
||||
git checkout $VERSION
|
||||
git pull
|
||||
npm install .
|
||||
|
||||
cp ./examples/relay.service /lib/systemd/system/relay.service
|
||||
echo $PWD >> /lib/systemd/system/relay.service
|
||||
echo "fs.file-max = 999999" >> /etc/sysctl.conf
|
||||
ulimit -u unlimited
|
||||
sysctl -p /etc/sysctl.conf
|
||||
systemctl daemon-reload
|
||||
systemctl enable relay
|
||||
systemctl restart relay
|
||||
npm install gun
|
||||
|
||||
# to run the gun examples:
|
||||
cd ./node_modules/gun/examples
|
||||
npm install .
|
||||
sudo /usr/local/bin/node ./express.js 80 # change `80` to `8080` for development purposes.
|
||||
|
@ -1 +0,0 @@
|
||||
../node_modules/iris-messenger/src
|
@ -58,7 +58,7 @@
|
||||
color: skyblue;
|
||||
background: transparent;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
cursor: poiner;
|
||||
}
|
||||
ul, li {
|
||||
list-style-type: none;
|
||||
|
@ -1,210 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<!--
|
||||
HELP WANTED!
|
||||
Build decentralized Open Source Uber/Lyft!
|
||||
Need people with experience on:
|
||||
- Leaflet API, zoom and tile coordinates for subscribing to surrounding area.
|
||||
- Creating cute little driving icons that animate with heading/direction.
|
||||
-->
|
||||
<title>Move by Neon ERA</title>
|
||||
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.0.3/dist/leaflet.css"/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.0.3/dist/leaflet.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="map"></div>
|
||||
<a id="share" class="hide"><div class="stick button">Request Ride</div></a>
|
||||
<div id="link" class="hide">
|
||||
<p>Copy and Paste this URL to your friends to share your location:</p>
|
||||
<center>
|
||||
<p id="follow">Location sharing not available!</p>
|
||||
</center>
|
||||
<p><b>Note</b>: Location may not sync when your device's screen is off or the tab is out of focus. You'd need to install this as an app for that to work.</p>
|
||||
<center>
|
||||
<a id="close"><div class="button">Close</div></a>
|
||||
</center>
|
||||
</div>
|
||||
<textarea style="display: none; position: fixed; top: 0; left: 0; width: 100%; height: 5em;" id="debug"></textarea>
|
||||
<style>
|
||||
html, body, #map {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
font-family: Arial;
|
||||
font-size: 16pt;
|
||||
z-index: 1;
|
||||
}
|
||||
.stick {
|
||||
position: absolute;
|
||||
bottom: 1em;
|
||||
right: 1em;
|
||||
}
|
||||
.button {
|
||||
display: inline-block;
|
||||
padding: 1em;
|
||||
opacity: .5;
|
||||
background: blue;
|
||||
color: white;
|
||||
z-index: 7;
|
||||
transition: .25s all;
|
||||
}
|
||||
.button:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
.hide {
|
||||
display: none;
|
||||
}
|
||||
#link {
|
||||
position: absolute;
|
||||
padding: 1em;
|
||||
top: 2em;
|
||||
left: 2em;
|
||||
right: 2em;
|
||||
bottom: 2em;
|
||||
background: white;
|
||||
overflow: scroll;
|
||||
z-index: 9;
|
||||
}
|
||||
#follow {
|
||||
background: #EEE;
|
||||
padding: .5em;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
</style>
|
||||
<script src="/jquery.js"></script>
|
||||
<script src="/gun.js"></script>
|
||||
<script>
|
||||
function Where(opt, cb){
|
||||
// a small wrapper around Leaflet for map tracking.
|
||||
var where = {};
|
||||
where.opt = opt || {};
|
||||
where.opt.zoom = where.opt.zoom || {};
|
||||
where.opt.err = where.opt.err || function(){};
|
||||
|
||||
where.map = L.map('map', { zoom: where.opt.zoom.level });
|
||||
|
||||
where.opt.tile = where.opt.tile || L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
|
||||
maxZoom: where.opt.zoom.max,
|
||||
minZoom: where.opt.zoom.min,
|
||||
detectRetina: true,
|
||||
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
|
||||
});
|
||||
where.map.addLayer(where.opt.tile);
|
||||
|
||||
L.GridLayer.DebugCoords = L.GridLayer.extend({
|
||||
createTile: function (coords) {
|
||||
var tile = document.createElement('div');
|
||||
tile.innerHTML = [coords.z, coords.x, coords.y].join(', ');
|
||||
tile.style.outline = '1px solid black';
|
||||
return tile;
|
||||
}
|
||||
});
|
||||
L.gridLayer.debugCoords = function(opts) {
|
||||
return new L.GridLayer.DebugCoords(opts);
|
||||
};
|
||||
where.map.addLayer( L.gridLayer.debugCoords() );
|
||||
|
||||
where.opt.zoom.ing = where.opt.zoom.ing || function(){
|
||||
where.opt.zoom.level = where.map.getZoom();
|
||||
}
|
||||
where.map.on('zoomstart', where.opt.zoom.ing, where.opt.err);
|
||||
where.map.on('zoomend', where.opt.zoom.ing, where.opt.err);
|
||||
where.map.on('zoomlevelschange', where.opt.zoom.ing, where.opt.err);
|
||||
|
||||
where.update = function(latlng){
|
||||
if((+new Date) - where.update.last < 400){
|
||||
clearTimeout(where.update.to);
|
||||
where.update.to = setTimeout(function(){
|
||||
where.update(latlng);
|
||||
});
|
||||
return;
|
||||
}
|
||||
var z = 12;
|
||||
var x = lng2tile(latlng.lng, z);
|
||||
var y = lat2tile(latlng.lat, z);
|
||||
console.log(x, y); //
|
||||
where.map.setView(latlng, where.opt.zoom.level, {animate: true});
|
||||
where.marker = where.marker || L.marker().setLatLng(latlng).addTo(where.map);
|
||||
where.marker.setLatLng(latlng).update();
|
||||
where.update.last = (+new Date);
|
||||
}
|
||||
|
||||
if(where.opt.track){
|
||||
where.map.on('locationfound', function(pos){
|
||||
where.update(pos.latlng);
|
||||
where.opt.track(pos);
|
||||
});
|
||||
|
||||
where.map.locate({
|
||||
setView: true,
|
||||
zoom: where.opt.zoom.level,
|
||||
watch: where.opt.continuous || true,
|
||||
timeout: where.opt.timeout || 10000,
|
||||
maximumAge: where.opt.maximumAge || 0,
|
||||
enableHighAccuracy: where.opt.enableHighAccuracy || false
|
||||
});
|
||||
}
|
||||
|
||||
function lng2tile(lng,z) { return (Math.floor((lng+180)/360*Math.pow(2,z))) }
|
||||
function lat2tile(lat,z) { return (Math.floor((1-Math.log(Math.tan(lat*Math.PI/180) + 1/Math.cos(lat*Math.PI/180))/Math.PI)/2 *Math.pow(2,z))) }
|
||||
|
||||
return where;
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
;(function(){
|
||||
// the actual GPS tracking app!
|
||||
var gun = Gun(location.origin + '/gun');
|
||||
var gps = {};
|
||||
gps.opt = {
|
||||
continuous: true, // get location just once uses `getCurrentPosition()` while continuously uses `watchPosition()`
|
||||
enableHighAccuracy: true, // HighAccuracy uses more resources, https://developer.mozilla.org/en-US/docs/Web/API/PositionOptions
|
||||
timeout: 5000, // have this long to get data before erring.
|
||||
maximumAge: 0, // set to 0 to actually track.
|
||||
zoom: {max: 18, level: 13, min: 12}
|
||||
}
|
||||
function start(){
|
||||
gps.follow = (window.location.hash || '').slice(1);
|
||||
if(gps.follow){
|
||||
gps.where = gps.where || Where(gps.opt);
|
||||
gps.ref = gun.get('gps/' + gps.follow);
|
||||
gps.ref.on(function(latlng){
|
||||
//$('#debug').value = 'track ' + JSON.stringify(latlng);
|
||||
gps.where.update(latlng);
|
||||
});
|
||||
$('#share').addClass("hide");
|
||||
} else {
|
||||
document.cookie = 'gps=' + (gps.track = (document.cookie.match(/gps\=(.*?)(\&|$|\;)/i)||[])[1] || String.random(5)); // trick with cookies!
|
||||
gps.ref = gun.get('gps/' + gps.track);
|
||||
gps.opt.track = function(pos){
|
||||
pos = pos.latlng;
|
||||
if(gps.follow
|
||||
|| Gun.state() - gps.when < 1000
|
||||
|| gps.last && gps.last.lat == pos.lat && gps.last.lng == pos.lng){
|
||||
return; // throttle!
|
||||
}
|
||||
gps.when = Gun.state();
|
||||
gps.ref.put(gps.last = pos);
|
||||
//$('#debug').value = JSON.stringify(gps.last);
|
||||
}
|
||||
gps.where = gps.where || Where(gps.opt);
|
||||
$('#follow').text((location.origin + location.pathname) + '#' + gps.track);
|
||||
$('#share').removeClass("hide");
|
||||
$('#share').on('click', function(){
|
||||
$('#link').toggleClass("hide");
|
||||
});
|
||||
$('#close').on('click', function(){
|
||||
$('#link').toggleClass("hide");
|
||||
});
|
||||
}
|
||||
}
|
||||
start();
|
||||
window.onhashchange = start;
|
||||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,758 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Party by Neon ERA</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="stylesheet" type="text/css" href="./style.css">
|
||||
<link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/css?family=Caveat" rel="stylesheet">
|
||||
<style>
|
||||
.write {
|
||||
font-family: 'Caveat', sans-serif;
|
||||
}
|
||||
.shout {
|
||||
font-size: 36pt;
|
||||
font-size: 6.5vmax;
|
||||
}
|
||||
.edit {
|
||||
border-bottom: 1px dashed white;
|
||||
cursor: pointer;
|
||||
}
|
||||
.back {
|
||||
position: absolute;
|
||||
top: 0.5%;
|
||||
left: 0.5em;
|
||||
width: 2em;
|
||||
height: 2em;
|
||||
z-index: 99999;
|
||||
}
|
||||
</style>
|
||||
<script src="./jquery.js"></script>
|
||||
<script src="../../gun/gun.js"></script>
|
||||
<script src="../../gun/sea.js"></script>
|
||||
<script src="../../gun/as.js"></script>
|
||||
<script src="../../gun/nts.js"></script>
|
||||
<script src="../../gun/lib/time.js"></script>
|
||||
<script src="../../gun/lib/upload.js"></script>
|
||||
<script>
|
||||
;(() => {
|
||||
function S(){};
|
||||
window.S = S;
|
||||
try{localStorage.clear();//sessionStorage.clear();
|
||||
}catch(e){}
|
||||
S.gun = Gun(location.host? location.origin+'/gun' : 'http://localhost:8765/gun');
|
||||
//S.gun = Gun('http://localhost:8765/gun');
|
||||
//S.gun = Gun();
|
||||
S.app = S.gun.get('examples/social/2');
|
||||
S.user = S.gun.user();
|
||||
S.tell = (what, n) => {
|
||||
var e = $('#tell').find('p');
|
||||
e.addClass('notify').text(what);
|
||||
clearTimeout(S.tell.to);
|
||||
S.tell.to = setTimeout(() => { e.removeClass('notify') }, n || 2500);
|
||||
return what;
|
||||
}
|
||||
this.S = S;
|
||||
})();
|
||||
</script>
|
||||
</head>
|
||||
<body class="whitet black">
|
||||
|
||||
<div id="hi" class="hue page">
|
||||
<style>
|
||||
#hi input {
|
||||
padding: 0.4em 0.8em;
|
||||
font-size: 1.5em;
|
||||
margin-left: 2%;
|
||||
margin-bottom: 2%;
|
||||
}
|
||||
#hi .faces img {
|
||||
w-idth: 5%;
|
||||
width: 3em;
|
||||
width: 7vh;
|
||||
}
|
||||
#hi .ton {
|
||||
border-radius: 1em;
|
||||
font-size: 150%;
|
||||
font-size: 2.25vmax;
|
||||
margin: 0 0.5em 0 0.5em;
|
||||
background: transparent;
|
||||
border: 1px solid white;
|
||||
color: white;
|
||||
font-family: 'Raleway', sans-serif;
|
||||
}
|
||||
#hi .ton:hover {
|
||||
background: white;
|
||||
color: black;
|
||||
}
|
||||
</style>
|
||||
<div class="loud write shout rim">Join the Private Party!</div>
|
||||
<div id="faces" class="flush faces">
|
||||
<div class="right" style="max-width: 30em;">
|
||||
<a href="chrome://extensions" target="_blank"><button class="ton">Install Now</button></a>
|
||||
<a href="#"><button class="ton">How It Works</button></a>
|
||||
<!-- input id="halias" class="write jot sap" placeholder="username">
|
||||
<input id="hpass" type="password" class="write jot sap" placeholder="passphrase" -->
|
||||
<script>
|
||||
$.as.route.page('hi', () => {
|
||||
$('#hpass').on('focus', () => {
|
||||
var alias = $("#halias").val();
|
||||
if(!alias){ return }
|
||||
$('#alias').val(alias);
|
||||
$.as.route('sign');
|
||||
$('#pass').focus();
|
||||
});
|
||||
setTimeout(() => {
|
||||
$('#halias').focus();
|
||||
window.faces('#faces', 100);
|
||||
window.faces('#faces2', 40);
|
||||
},1);
|
||||
});
|
||||
if(!location.hash){
|
||||
$.as.route('hi');
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
;(window.faces = function faces(id, lim, i){
|
||||
//return
|
||||
if(!$('#hi').is(':visible')){ return }
|
||||
if(!id){ return }
|
||||
if(!faces.on){ faces.on = id }
|
||||
if(faces.on != id){
|
||||
faces.was = faces.was || {};
|
||||
if(faces.was[id]){ return }
|
||||
(faces.next = faces.next || []).push([faces.was[id] = id, lim]);
|
||||
return;
|
||||
}
|
||||
if(i >= (lim || 100)){
|
||||
faces.on = null;
|
||||
var tmp = faces.next && faces.next.shift();
|
||||
tmp && faces(tmp[0], tmp[1]);
|
||||
return;
|
||||
}
|
||||
$.ajax({
|
||||
url: 'https://randomuser.me/api/',
|
||||
dataType: 'json',
|
||||
success: (data) => {
|
||||
faces(id, lim || 100, (i || 0) + 1);
|
||||
if(!data || !data.results){ return }
|
||||
var tmp = data.results[0];
|
||||
if(!tmp || !(tmp = tmp.picture)){ return }
|
||||
tmp = tmp.thumbnail;
|
||||
if(!tmp || faces[tmp]){ return }
|
||||
faces[tmp] = true;
|
||||
tmp = $('<img>').attr('src', tmp).fadeIn().appendTo(id || '#faces');
|
||||
|
||||
tmp = tmp.offset();
|
||||
var r = Math.random() * 30;
|
||||
window.fun && window.fun({x: tmp.left - r, y: tmp.top - $(window).scrollTop() - r});
|
||||
}
|
||||
});
|
||||
return faces;
|
||||
});
|
||||
</script>
|
||||
<div class="pad ditch">
|
||||
<p class="loud"><i>Your friend has invited you to add a privacy extension to your browser:</i></p>
|
||||
<p> - Decrypts your friends' messages across any site!</p>
|
||||
<p> - Stops tech monopolies from selling your private data to advertisers.</p>
|
||||
<p> - Gives you ownership and control over all your data online.</p>
|
||||
<p> - Creates a searchable history of your posts, friends, and more!</p>
|
||||
</div>
|
||||
<div id="faces2" class="flush faces"></div>
|
||||
<div class="pad ditch">
|
||||
<p class="loud"><i>Express your thoughts & connect with the world around you!</i></p>
|
||||
<p> - Discover new relationships.</p>
|
||||
<p> - Keep up with friends and news in realtime.</p>
|
||||
<p> - Watch fun videos and photos from people who share.</p>
|
||||
<p> - But this time, you own it: fully decentralized.</p>
|
||||
</div>
|
||||
<div class="pad ditch" style="margin-top: 1em;">
|
||||
<p><span class="loud write shout">Welcome,</span><!-- span class="write loud">, you are currently connected to <b id="peers" class="huet4">2</b> peers. <b>Why not try to sign up or log in?</b></span --></p>
|
||||
<p> - Your identity is created here, by you. Not on a server.</p>
|
||||
<p> - It uses secure <a href="https://gun.eco/docs/Cartoon-Cryptography">cryptographic</a> methods to protect you.</p>
|
||||
<p> - Only you have access to it, meaning even we cannot reset your password!</p>
|
||||
<p> - For added security, you can freely <a href="https://github.com/amark/gun">download</a> and run it on your own computer.</p>
|
||||
</div>
|
||||
<div class="black">
|
||||
<div class="pad huet">
|
||||
<div class="write center">Crafted with <span class="redt">♥</span> by <span class="loud">era</span>.</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="sign" class="hue page">
|
||||
<style>
|
||||
#sign input, button {
|
||||
margin: 0.2em 0;
|
||||
padding: 0.5em 1em;
|
||||
}
|
||||
#sign .sign {
|
||||
font-size: 30pt;
|
||||
}
|
||||
#sign .pow {
|
||||
margin: 0em 0;
|
||||
padding: 0em 1em;
|
||||
background: transparent;
|
||||
border-bottom: none;
|
||||
text-align: center;
|
||||
font-size: 5vmax;
|
||||
color: white;
|
||||
}
|
||||
#sign .act {
|
||||
padding: 0.7em 1em;
|
||||
width: 5em;
|
||||
}
|
||||
#sign .tos {
|
||||
font-size: 10pt;
|
||||
}
|
||||
</style>
|
||||
<form id="inup" class="pad center">
|
||||
<div class="shout write">Welcome,</div>
|
||||
<div class="mid row col">
|
||||
<input id="alias" class="write sign jot sap" placeholder="username">
|
||||
</div>
|
||||
<div class="mid row col">
|
||||
<input id="pass" class="write sign jot sap" type="password" placeholder="passphrase">
|
||||
</div>
|
||||
<div class="mid row col go">
|
||||
<input id="in" type="submit" class="huet sap act symbol" value="sign in">
|
||||
<input id="up" type="button" class="huet sap act symbol" value="or up">
|
||||
</div>
|
||||
<span class="tos">By logging in or up, you agree to the <a href="https://github.com/amark/gun/blob/master/LICENSE.md" class="tos" target="_blank">Terms of Service</a>.</span>
|
||||
<p class="tos"><a href="#forgot">Forgot password?</a></p>
|
||||
</form>
|
||||
<script>
|
||||
;(() => {
|
||||
S.route = location.hash.slice(1);
|
||||
$('#up').on('click', (e) => {
|
||||
var form = check();
|
||||
if(!form){ return }
|
||||
$("#up").addClass('pulse');
|
||||
S.user.create(form.alias, form.pass, (ack) => {
|
||||
if(!ack.wait){ $("#up").removeClass('pulse') }
|
||||
if(ack.err){ return S.tell(ack.err) }
|
||||
check.up = true;
|
||||
S.user.auth(form.alias, form.pass);
|
||||
});
|
||||
});
|
||||
$('#inup').on('submit', (e) => {
|
||||
var form = check();
|
||||
if(!form){ return }
|
||||
$("#in").addClass('pulse');
|
||||
S.user.auth(form.alias, form.pass, (ack) => {
|
||||
if(!ack.wait){ $("#in").removeClass('pulse') }
|
||||
if(ack.err){ return S.tell(ack.err) }
|
||||
});
|
||||
});
|
||||
$('#pass').on('focus', () => {
|
||||
$('#alias').addClass('pow');
|
||||
});
|
||||
$('#alias').on('focus', () => {
|
||||
$('#alias').removeClass('pow');
|
||||
});
|
||||
$.as.route.page('sign', () => {
|
||||
if(!$('#alias').val()){
|
||||
setTimeout(() => { $('#alias').focus() },1);
|
||||
}
|
||||
});
|
||||
var check = () => {
|
||||
var form = {alias: ($('#alias').val()||'').toLowerCase(), pass: $("#pass").val()||''};
|
||||
if(6 > form.alias.length){
|
||||
S.tell("Your username needs to be longer than 5 letters.");
|
||||
return;
|
||||
}
|
||||
if(9 > form.pass.length){
|
||||
S.tell("Your passphrase needs to be longer than 9 letters.");
|
||||
return;
|
||||
}
|
||||
return form;
|
||||
}
|
||||
S.gun.on('auth', (ack) => {
|
||||
if('hi' === S.route){ S.route = '' }
|
||||
if('sign' === S.route){ S.route = '' }
|
||||
if(check.up){ S.route = 'settings' }
|
||||
$.as.route(S.route = S.route || 'draft');
|
||||
});
|
||||
S.user.recall({sessionStorage: 1});
|
||||
})();
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="forgot" class="hue3 page">
|
||||
<style>
|
||||
#forgot .fill {
|
||||
padding: 0.5em;
|
||||
}
|
||||
</style>
|
||||
<a href="#sign" class="act back">←</a>
|
||||
<div class="pad">
|
||||
<p class="shout write">Forgot Password</p>
|
||||
<form>
|
||||
<ul class="rim">
|
||||
<li><input class="alias fill sap jot" placeholder="username"></li>
|
||||
<li>
|
||||
<p>What was your first pet's name, the type of animal they were, and your favorite quirk about them? <span class="pet let"></span> <span class="pet length"></span>
|
||||
<input class="pet fill sap jot" placeholder='"Bubbles was a goldfish, he played dead a lot." or "Fluffy is a cat, but she eats vegetables."'></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Where was your first kiss? Describe what they looked like. <span class="kiss let"></span> <span class="kiss length"></span>
|
||||
<input class="kiss fill sap jot" placeholder='"I kissed Alice in a tree, she was a redhead." or "Bob kissed me at the movies, he had green eyes."'></p>
|
||||
</li>
|
||||
<li class="loud write help"></li>
|
||||
<li class="center rim sit"><input type="submit" class="fill huet3 sap act symbol" value="go" style="width: 4em;"></li>
|
||||
</ul>
|
||||
</form>
|
||||
<script>
|
||||
$.as.route.page('forgot', () => {
|
||||
var _ = $('#forgot'), alias;
|
||||
$('.alias',_).on('blur', () => {
|
||||
alias = $('.alias',_).val();
|
||||
if(!alias){ return }
|
||||
$('.pet.length',_).val('');
|
||||
$('.kiss.length',_).val('');
|
||||
S.gun.get('alias/'+alias).once().map()
|
||||
.get('settings').once(add);
|
||||
}).focus();
|
||||
var add = (set) => {
|
||||
if(!set){ return }
|
||||
var tmp;
|
||||
(tmp = $('.pet.length',_)).text(tmp.text() +' '+ set.pet);
|
||||
(tmp = $('.kiss.length',_)).text(tmp.text() +' '+ set.kiss);
|
||||
}
|
||||
$('.jot.pet',_).on('keyup', function(){ $('.pet.let',_).text(this.value.length + ' /') });
|
||||
$('.jot.kiss',_).on('keyup', function(){ $('.kiss.let',_).text(this.value.length + ' /') });
|
||||
$('form',_).on('submit', () => {
|
||||
alias = alias || $('.alias',_).val();
|
||||
if(!alias){ return S.tell("You need a username.") }
|
||||
$('.act',_).addClass('pulse');
|
||||
S.gun.get('alias/' + alias)
|
||||
.once().map()
|
||||
.get('settings')
|
||||
.get('recover')
|
||||
.once(recover);
|
||||
});
|
||||
var recover = async (data) => {
|
||||
$('.act',_).removeClass('pulse');
|
||||
var pet = $('.jot.pet',_).val();
|
||||
var kiss = $('.jot.kiss',_).val();
|
||||
var hint;
|
||||
try{ hint = await Gun.SEA.decrypt(data, await Gun.SEA.work(pet, kiss));
|
||||
}catch(e){}
|
||||
if(!hint){ return S.tell("Nope. Try again!") }
|
||||
$('.write.help',_).text(hint);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="settings" class="hue2 page">
|
||||
<style>
|
||||
#settings .fill {
|
||||
padding: 0.5em;
|
||||
}
|
||||
#facedrop img {
|
||||
vertical-align: middle;
|
||||
border-radius: 100%;
|
||||
}
|
||||
</style>
|
||||
<a href="#draft" class="act back">←</a>
|
||||
<div class="pad">
|
||||
<p class="shout write">Settings</p>
|
||||
<p>Your username is <i name="alias"></i>.</p>
|
||||
<p id="facedrop">
|
||||
Drop in a new profile photo: <img class="none">
|
||||
</p>
|
||||
<form id="recovery">
|
||||
<p><b>Because no server can reset your password, you must fill out a "forgot password" recovery form.</b>
|
||||
We recommend you use simple, grammatically correct, memorable sentences for your answers.
|
||||
Keep each sentence less than 50 letters so that it will be easy for you to reconstruct -
|
||||
the length of your reply will be stored as a hint to help.</p>
|
||||
<ol class="rim">
|
||||
<li>
|
||||
<p>What was your first pet's name, the type of animal they were, and your favorite quirk about them? <span class="pet"></span>
|
||||
<input id="pet" class="fill sap jot" placeholder='"Bubbles was a goldfish, he played dead a lot." or "Fluffy is a cat, but she eats vegetables."'></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>Where was your first kiss? Describe what they looked like. <span class="kiss"></span>
|
||||
<input id="kiss" class="fill sap jot" placeholder='"I kissed Alice in a tree, she was a redhead." or "Bob kissed me at the movies, he had green eyes."'></p>
|
||||
</li>
|
||||
<li>
|
||||
<p>The reminder of what your password is:</p>
|
||||
<input id="pw-reminder" type="password" class="fill sap jot" placeholder='"Hint: Usual password + name of this app!"'></p>
|
||||
</li>
|
||||
<li class="center rim sit">
|
||||
<input type="submit" class="fill huet2 sap act symbol" value="set" style="width: 4em;">
|
||||
</li>
|
||||
</ol>
|
||||
</form>
|
||||
<form id="reset">
|
||||
<style>
|
||||
#settings .thin {
|
||||
max-width: 15em;
|
||||
margin-right: 0.1em;
|
||||
margin-bottom: 0.1em;
|
||||
}
|
||||
</style>
|
||||
<p>We recommend you use a memorable and grammatically correct sentence as your passphrase.
|
||||
Then write it down on paper and store it some place safe that will be easy for you to find. Here are some tips:</p>
|
||||
<ul class="rim">
|
||||
<li> - What gives you purpose and meaning in your life?</li>
|
||||
<li> - Say something nice about an important person in your life.</li>
|
||||
<li> - If you could work on your hobby full time, what goals would you have?</li>
|
||||
<li> - Try to combine all of them into a rhyme, or something funny that makes you laugh.</li>
|
||||
<li class="center rim">
|
||||
<input id="oldpass" type="password" class="center thin fill sap jot" placeholder="old passphrase">
|
||||
<input id="newpass" type="password" class="center thin fill sap jot" placeholder="new passphrase">
|
||||
<input id="oldnew" type="submit" class="fill huet2 sap act symbol" value="change" style="width: 5em;"></li>
|
||||
<li> - <i>Ex, "Uncle Ben taught me to fight for what is right, I might have a spider bite."</i></li>
|
||||
<li> - <i>Ex, "I am quite better than the Dark Knight, despite any Kryptonite."</i></li>
|
||||
<li> - <i>Ex, "Give me a cause for these claws, I have no paws and no laws."</i></li>
|
||||
<li> - <i>Ex, "My suite is made of red supplements, with hidden jet compartments."</i></li>
|
||||
</ul>
|
||||
</form>
|
||||
<p>You are currently connected to <i>2</i> peers.</p>
|
||||
|
||||
</div>
|
||||
<script>
|
||||
$.as.route.page('settings', () => {
|
||||
if(!S.user.is){ return $.as.route('hi') }
|
||||
$.as('#settings', S.user);
|
||||
|
||||
;(() => {
|
||||
$('#pet').on('keyup', function(){ $('.pet').text(this.value.length + ' letters.') });
|
||||
$('#kiss').on('keyup', function(){ $('.kiss').text(this.value.length + ' letters.') });
|
||||
|
||||
S.user.get('settings').get('pet').on(function(l){ $('#pet').val(Gun.text.random(l, '*')) });
|
||||
S.user.get('settings').get('kiss').on(function(l){ $('#kiss').val(Gun.text.random(l, '*')) });
|
||||
|
||||
$('#recovery').on('submit', async (e) => {
|
||||
var pet = $('#pet').val();
|
||||
var kiss = $('#kiss').val();
|
||||
var reminder = $('#pw-reminder').val(); // NOTE: THIS IS TEMPORARY!
|
||||
if(!pet){ return S.tell("Please fill out the pet question!") }
|
||||
if(!kiss){ return S.tell("Please fill out the first kiss question!") }
|
||||
if(!reminder){ return S.tell("You need a password reminder.") } // NOTE: THIS IS TEMPORARY!
|
||||
if(1+pet.indexOf('*') || 1+kiss.indexOf('*')){ return S.tell("Your answer should not have '*' in it.") }
|
||||
$('#recovery .act').addClass('pulse');
|
||||
var recover = await Gun.SEA.encrypt(reminder, await Gun.SEA.work(pet, kiss));
|
||||
// NOTE: We are currently doing this manually, in the future we want to
|
||||
// just automatically log the user back in based off the security questions
|
||||
// rather than only giving them a "reminder" of what theirold password is.
|
||||
S.user.get('settings').put({
|
||||
recover: recover,
|
||||
pet: pet.length,
|
||||
kiss: kiss.length
|
||||
}, (ack) => {
|
||||
$('#recovery .act').removeClass('pulse');
|
||||
S.tell(ack.err || "Saved!");
|
||||
$('#pw-reminder').val(''); // NOTE: THIS IS TEMPORARY!
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
;(() => {
|
||||
$('#reset').on('submit', (e) => {
|
||||
var old = $('#oldpass').val();
|
||||
var pass = $('#newpass').val() || '';
|
||||
if(9 > pass.length){ return S.tell("Your passphrase needs to be longer than 9 letters.") }
|
||||
if(!S.user.is){ return S.tell("You need to be logged in to do that.") }
|
||||
$('#oldnew').addClass('pulse');
|
||||
S.user.auth(S.user.is.alias, old, (ack) => {
|
||||
$('#oldnew').removeClass('pulse');
|
||||
S.tell(ack.err || "Saved!");
|
||||
$('#oldpass, #newpass').val('');
|
||||
}, {change: pass});
|
||||
});
|
||||
})();
|
||||
|
||||
;(async () => {
|
||||
$('#settings').upload(function resize(e, up){
|
||||
if(e.err){ return }
|
||||
$('#settings').addClass('pulse');
|
||||
if(up){ return up.shrink(e, resize, 64) }
|
||||
$('#settings').removeClass('pulse');
|
||||
$("#facedrop img").attr('src', e.base64).removeClass('none');
|
||||
S.user.get('who').get('face').get('small').put(e.base64);
|
||||
});
|
||||
var img = await S.user.get('who').get('face').get('small').then();
|
||||
if(img){ $('#facedrop img').attr('src', img).removeClass('none') }
|
||||
})();
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="out" class="hue page">
|
||||
<script>
|
||||
$.as.route.page('out', () => {
|
||||
S.user.leave();
|
||||
setTimeout(() => $.as.route('hi'), 1);
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="draft" class="hue page">
|
||||
<style>
|
||||
.draft {
|
||||
|
||||
}
|
||||
#speak {
|
||||
overflow: visible;
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
#speak .draft:empty:not(:focus):before{
|
||||
content:attr(data-text);
|
||||
}
|
||||
#speak input {
|
||||
position: absolute;
|
||||
bottom: -1.4em;
|
||||
right: -2%;
|
||||
width: auto;
|
||||
color: white;
|
||||
padding: 0.3em 1em;
|
||||
background: transparent;
|
||||
border: 1px solid white;
|
||||
border-radius: 1em;
|
||||
transition: all 0.2s ease-in;
|
||||
}
|
||||
#speak input:hover {
|
||||
background: white;
|
||||
color: #33cc33;
|
||||
}
|
||||
#draft ul .face {
|
||||
float: left;
|
||||
border-radius: 100%;
|
||||
vertical-align: middle;
|
||||
height: 1.5em;
|
||||
margin-right: 2%;
|
||||
}
|
||||
#draft ul, #draft li {
|
||||
overflow: visible;
|
||||
}
|
||||
#draft .what {
|
||||
}
|
||||
#draft .spoke {
|
||||
}
|
||||
</style>
|
||||
<p class="pad">Welcome!</p>
|
||||
<!--
|
||||
People:
|
||||
- stare
|
||||
- scroll
|
||||
- tap
|
||||
- type
|
||||
- talk
|
||||
- take
|
||||
-->
|
||||
<form id="speak" class="mid row col">
|
||||
<div id="d0" class="draft spoke gap tint sap editable" contenteditable="true" style="min-height: 1em;" data-text="Express yourself..."></div>
|
||||
<input type="submit" class="sap hide" value="speak!">
|
||||
</form>
|
||||
<ul class="mid row col">
|
||||
</ul>
|
||||
<div class="model">
|
||||
<li class="spoke tint sap gully">
|
||||
<div class="gap"><span class="sort none"></span><img class="face act none"><b class="name"></b><div class="what"></div></div>
|
||||
</li>
|
||||
</div>
|
||||
<div style="height: 10%;"></div>
|
||||
<script>
|
||||
$.as.route.page('draft', () => {
|
||||
if(!S.user.is){ return $.as.route('hi') }
|
||||
$('#speak').on('keyup', (e) => {
|
||||
var say = $('#speak .draft').text();
|
||||
if(!say){
|
||||
$('#speak input').addClass('hide');
|
||||
return;
|
||||
}
|
||||
$('#speak input').removeClass('hide');
|
||||
});
|
||||
window.user = S.user;
|
||||
$('#speak').on('submit', (e) => {
|
||||
var say = $('#speak .draft').text(); //.text(); // NO NO NO NO NO
|
||||
if(!say){ return }
|
||||
console.log('save!', say);
|
||||
var ref = S.user.get('who').get('all').set({what: say, when: Gun.state()});
|
||||
//ref.get('by').put(S.user.get('who'));
|
||||
//S.user.get('who').get('said').time(ref);
|
||||
S.user.get('who').get('said').set(ref);
|
||||
//S.gun.get('@').time(ref);
|
||||
$('#speak .draft').text('');
|
||||
});
|
||||
//S.gun.get('@').time(async (data, key, time) => {
|
||||
S.user.get('who').get('said').map().once(async (data, key, time) => {
|
||||
//var ref = S.gun.get(data), tmp;
|
||||
//var said = await ref.then();
|
||||
key = key.replace(/[^A-Za-z]/ig,'');
|
||||
var tmp, said = data, time = said.when;
|
||||
var $li = $($('#'+key)[0] || $('#draft .model .spoke').clone(true,true).attr('id', key)[(tmp = $.as.sort(time, $('#draft ul').children('li').first()))[0]?'insertBefore':'appendTo'](tmp[0] || '#draft ul'));
|
||||
tmp = said.what;
|
||||
if(tmp && tmp.ct){
|
||||
tmp = JSON.stringify(tmp);
|
||||
setTimeout(async function(){
|
||||
tmp = await SEA.decrypt(said.what, S.user._.sea);
|
||||
$li.find('.what').text(tmp);
|
||||
}, 750);
|
||||
}
|
||||
$li.find('.what').text(tmp); // NORMALIAZE!!!
|
||||
var by = S.user.get('who');// ref.get('by');
|
||||
by.get('face').get('small').on(data => {
|
||||
$li.find('.face').attr('src', data).removeClass('none');
|
||||
});
|
||||
by.get('name').on(data => {
|
||||
data && $li.find('b').text(data);
|
||||
});
|
||||
$li.find('.sort').text(time);
|
||||
var time = new Date(time);
|
||||
$li.find('i').text(time.toDateString() + ', ' + time.toLocaleTimeString());
|
||||
return;
|
||||
var who = ref.get('by');
|
||||
var face = await who.get('face').get('small').then();
|
||||
if(face){
|
||||
$li.find('.face').attr('src', face).removeClass('none');
|
||||
}
|
||||
});
|
||||
$(document).on('click', '#speak .act.face', (eve) => {
|
||||
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="contacts" class="hue2 page">
|
||||
<style>
|
||||
#contacts ul .face {
|
||||
float: left;
|
||||
border-radius: 100%;
|
||||
vertical-align: middle;
|
||||
height: 2.5em;
|
||||
margin-right: 5%;
|
||||
}
|
||||
#contacts ul, #contacts li {
|
||||
overflow: visible;
|
||||
}
|
||||
#contacts .who {
|
||||
display: inline-block;
|
||||
margin-right: 2%;
|
||||
min-width: 250px;
|
||||
width: 15em;
|
||||
text-align: left;
|
||||
padding: 2%;
|
||||
vertical-align: middle;
|
||||
}
|
||||
#contacts .what {
|
||||
}
|
||||
#contacts .spoke {
|
||||
}
|
||||
</style>
|
||||
<p class="pad">Contacts</p>
|
||||
<ul class="mid row col center">
|
||||
</ul>
|
||||
<div class="model">
|
||||
<li class="who tint sap gully">
|
||||
<div class="gap">
|
||||
<span class="sort none"></span>
|
||||
<img class="face act none" crossOrigin="Anonymous">
|
||||
<big class="name"></big><br/>
|
||||
<i class="alias"></i><br/>
|
||||
<small>FB ID:</small> <span class="fbid"></span>
|
||||
</div>
|
||||
</li>
|
||||
</div>
|
||||
<div style="height: 10%;"></div>
|
||||
<script>
|
||||
$.as.route.page('contacts', () => {
|
||||
if(!S.user.is){ return $.as.route('sign') }
|
||||
//S.gun.get('@').time(async (data, key, time) => {
|
||||
|
||||
// TODO: BUG!! switch from `on` to `once` to get Martti's {_} empty object bug.
|
||||
var $ul = $('#contacts ul');
|
||||
S.user.get('old').get('fb').map().on(async function(data){
|
||||
console.log('contact:', data);
|
||||
var key = data.fbid, tmp;
|
||||
if(!key){ return }
|
||||
var $li = $($('#fbid'+key)[0] || $('#contacts .model .who').clone(true,true).attr('id', 'fbid'+key)[(tmp = $.as.sort(data.name||1, $ul.children('li').first()))[0]?'insertBefore':'appendTo'](tmp[0] || $ul));
|
||||
|
||||
$li.find('.name').text(data.name);
|
||||
$li.find('.alias').text(data.alias);
|
||||
$li.find('.fbid').text(data.fbid);
|
||||
tmp = $li.find('img').attr('src', data.face || data.tmp);
|
||||
if(!data.face){
|
||||
var ref = this;
|
||||
$.fn.upload.shrink(data.tmp, function(b64){
|
||||
ref.get('face').put(b64);
|
||||
}, 100);
|
||||
}
|
||||
$('html, body').stop(true, true).animate({scrollTop: $ul.height()});
|
||||
});
|
||||
function img2b64(img, cb){
|
||||
var c = document.createElement('canvas');
|
||||
var ctx = c.getContext("2d");
|
||||
ctx.drawImage(img, 10, 10);
|
||||
cb(c.toDataURL());
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
|
||||
<div id="tell" class="center">
|
||||
<style>
|
||||
#tell {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 0;
|
||||
overflow: visible;
|
||||
}
|
||||
#tell p {
|
||||
top: -2em;
|
||||
width: 50%;
|
||||
border: solid #222 0.2em;
|
||||
border-top: none;
|
||||
padding: 1%;
|
||||
opacity: 0;
|
||||
visibility: hidden;
|
||||
transition: visibility 2s, all 1s ease-in;
|
||||
}
|
||||
#tell .notify {
|
||||
top: 0em;
|
||||
opacity: 0.8;
|
||||
visibility: visible;
|
||||
transition: visibility 0s, all 0.25s ease-out;
|
||||
}
|
||||
</style>
|
||||
<p class="mid black">Hello world!</p>
|
||||
</div>
|
||||
<!-- textarea id='debug' class="no-ne" style="position: fixed; bottom: 0; left: 0; width: 25%; height: 30%"></textarea -->
|
||||
|
||||
<script>
|
||||
$.as.route.page('person', () => {
|
||||
if(!user.is){ return $.as.route('hi') }
|
||||
var pub = location.hash.split('/').slice(-1)[0];
|
||||
(pub === user._.pub? $('#say').show() : $('#say').hide());
|
||||
as('#person', window.PUB = gun.get('pub/'+pub));
|
||||
});
|
||||
|
||||
$(document).upload(function resize(e, up){
|
||||
if(e.err){ return }
|
||||
var m = $($("#d"+e.id)[0] || $('#d0').clone(true,true).attr('id', 'd'+e.id).css('backgroundImage', '').appendTo('#draft')).addClass('pulse');
|
||||
if(up){ return up.shrink(e, resize, 1000) }
|
||||
//console.log(e.id, e.base64);
|
||||
m.removeClass('pulse').css({
|
||||
backgroundImage: 'url(' + e.base64 + ')',
|
||||
backgroundRepeat: 'no-repeat',
|
||||
backgroundPosition: 'center',
|
||||
backgroundSize: 'cover'
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script async src="../../gun/lib/fun.js"></script>
|
||||
<script async src="../../gun/lib/normalize.js"></script>
|
||||
<script async src="../../gun/lib/monotype.js"></script>
|
||||
<script async src="../../gun/lib/meta.js"></script>
|
||||
</body>
|
||||
</html>
|
BIN
examples/pop.png
Before Width: | Height: | Size: 29 KiB |
@ -1,3 +0,0 @@
|
||||
{
|
||||
"presets": ["module:metro-react-native-babel-preset"]
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
|
||||
[android]
|
||||
target = Google Inc.:Google APIs:23
|
||||
|
||||
[maven_repositories]
|
||||
central = https://repo1.maven.org/maven2
|
@ -1,70 +0,0 @@
|
||||
[ignore]
|
||||
; We fork some components by platform
|
||||
.*/*[.]android.js
|
||||
|
||||
; Ignore "BUCK" generated dirs
|
||||
<PROJECT_ROOT>/\.buckd/
|
||||
|
||||
; Ignore unexpected extra "@providesModule"
|
||||
.*/node_modules/.*/node_modules/fbjs/.*
|
||||
|
||||
; Ignore duplicate module providers
|
||||
; For RN Apps installed via npm, "Libraries" folder is inside
|
||||
; "node_modules/react-native" but in the source repo it is in the root
|
||||
.*/Libraries/react-native/React.js
|
||||
|
||||
; Ignore polyfills
|
||||
.*/Libraries/polyfills/.*
|
||||
|
||||
; Ignore metro
|
||||
.*/node_modules/metro/.*
|
||||
|
||||
[include]
|
||||
|
||||
[libs]
|
||||
node_modules/react-native/Libraries/react-native/react-native-interface.js
|
||||
node_modules/react-native/flow/
|
||||
node_modules/react-native/flow-github/
|
||||
|
||||
[options]
|
||||
emoji=true
|
||||
|
||||
esproposal.optional_chaining=enable
|
||||
esproposal.nullish_coalescing=enable
|
||||
|
||||
module.system=haste
|
||||
module.system.haste.use_name_reducers=true
|
||||
# get basename
|
||||
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
|
||||
# strip .js or .js.flow suffix
|
||||
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
|
||||
# strip .ios suffix
|
||||
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
|
||||
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
|
||||
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
|
||||
module.system.haste.paths.blacklist=.*/__tests__/.*
|
||||
module.system.haste.paths.blacklist=.*/__mocks__/.*
|
||||
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
|
||||
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*
|
||||
|
||||
munge_underscores=true
|
||||
|
||||
module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub'
|
||||
|
||||
module.file_ext=.js
|
||||
module.file_ext=.jsx
|
||||
module.file_ext=.json
|
||||
module.file_ext=.native.js
|
||||
|
||||
suppress_type=$FlowIssue
|
||||
suppress_type=$FlowFixMe
|
||||
suppress_type=$FlowFixMeProps
|
||||
suppress_type=$FlowFixMeState
|
||||
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(<VERSION>\\)? *\\(site=[a-z,_]*react_native[a-z,_]*\\)?)\\)?:? #[0-9]+
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
|
||||
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError
|
||||
|
||||
[version]
|
||||
^0.78.0
|
1
examples/react-native/.gitattributes
vendored
@ -1 +0,0 @@
|
||||
*.pbxproj -text
|
56
examples/react-native/.gitignore
vendored
@ -1,56 +0,0 @@
|
||||
# OSX
|
||||
#
|
||||
.DS_Store
|
||||
|
||||
# Xcode
|
||||
#
|
||||
build/
|
||||
*.pbxuser
|
||||
!default.pbxuser
|
||||
*.mode1v3
|
||||
!default.mode1v3
|
||||
*.mode2v3
|
||||
!default.mode2v3
|
||||
*.perspectivev3
|
||||
!default.perspectivev3
|
||||
xcuserdata
|
||||
*.xccheckout
|
||||
*.moved-aside
|
||||
DerivedData
|
||||
*.hmap
|
||||
*.ipa
|
||||
*.xcuserstate
|
||||
project.xcworkspace
|
||||
|
||||
# Android/IntelliJ
|
||||
#
|
||||
build/
|
||||
.idea
|
||||
.gradle
|
||||
local.properties
|
||||
*.iml
|
||||
|
||||
# node.js
|
||||
#
|
||||
node_modules/
|
||||
npm-debug.log
|
||||
yarn-error.log
|
||||
|
||||
# BUCK
|
||||
buck-out/
|
||||
\.buckd/
|
||||
*.keystore
|
||||
|
||||
# fastlane
|
||||
#
|
||||
# It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
|
||||
# screenshots whenever they are needed.
|
||||
# For more information about the recommended setup visit:
|
||||
# https://docs.fastlane.tools/best-practices/source-control/
|
||||
|
||||
*/fastlane/report.xml
|
||||
*/fastlane/Preview.html
|
||||
*/fastlane/screenshots
|
||||
|
||||
# Bundle artifact
|
||||
*.jsbundle
|
@ -1 +0,0 @@
|
||||
{}
|
@ -1,18 +0,0 @@
|
||||
# Gun on react-native!
|
||||
---
|
||||
### running the demo
|
||||
1. do `yarn install` on the directory of the demo `examples/react-native`
|
||||
2. run the demo with `react-native run-ios` or `react-native run-android`
|
||||
|
||||
### debugging
|
||||
i would recommend using [react-native-debugger](https://github.com/facebook/react-devtools/tree/master/packages/react-devtools) but you can use chrome's debugger as well
|
||||
|
||||
- ios: `cmd+D` then `Debug JS Remotely`
|
||||
- android: `cmd+M` then `Debug JS Remotely`
|
||||
|
||||
now you have access to the gun globals on the console which are
|
||||
`gun` -> the root gun
|
||||
`user` -> the gun user
|
||||
---
|
||||
# how it all of this is done
|
||||
since react-native doesnt provide the crypto module that we desire the most and all of the packages are incompatible with react-native/sea, and so to get `sea.js` working we use a webview(react-native browser) and bridge the crypto module from that browser to the global `window` and thats exactly what `webview-crypto` does, thanks to [webview-crypto repo](https://github.com/saulshanabrook/webview-crypto), the webview-crypto provided in this repo is somewhat the same but modified to get it working and mostly compatible with sea/react-native (even though there is a polyfiller for that but it just doesnt work ;/).
|
@ -1,65 +0,0 @@
|
||||
# To learn about Buck see [Docs](https://buckbuild.com/).
|
||||
# To run your application with Buck:
|
||||
# - install Buck
|
||||
# - `npm start` - to start the packager
|
||||
# - `cd android`
|
||||
# - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"`
|
||||
# - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck
|
||||
# - `buck install -r android/app` - compile, install and run application
|
||||
#
|
||||
|
||||
lib_deps = []
|
||||
|
||||
for jarfile in glob(['libs/*.jar']):
|
||||
name = 'jars__' + jarfile[jarfile.rindex('/') + 1: jarfile.rindex('.jar')]
|
||||
lib_deps.append(':' + name)
|
||||
prebuilt_jar(
|
||||
name = name,
|
||||
binary_jar = jarfile,
|
||||
)
|
||||
|
||||
for aarfile in glob(['libs/*.aar']):
|
||||
name = 'aars__' + aarfile[aarfile.rindex('/') + 1: aarfile.rindex('.aar')]
|
||||
lib_deps.append(':' + name)
|
||||
android_prebuilt_aar(
|
||||
name = name,
|
||||
aar = aarfile,
|
||||
)
|
||||
|
||||
android_library(
|
||||
name = "all-libs",
|
||||
exported_deps = lib_deps,
|
||||
)
|
||||
|
||||
android_library(
|
||||
name = "app-code",
|
||||
srcs = glob([
|
||||
"src/main/java/**/*.java",
|
||||
]),
|
||||
deps = [
|
||||
":all-libs",
|
||||
":build_config",
|
||||
":res",
|
||||
],
|
||||
)
|
||||
|
||||
android_build_config(
|
||||
name = "build_config",
|
||||
package = "com.gundemo",
|
||||
)
|
||||
|
||||
android_resource(
|
||||
name = "res",
|
||||
package = "com.gundemo",
|
||||
res = "src/main/res",
|
||||
)
|
||||
|
||||
android_binary(
|
||||
name = "app",
|
||||
keystore = "//android/keystores:debug",
|
||||
manifest = "src/main/AndroidManifest.xml",
|
||||
package_type = "debug",
|
||||
deps = [
|
||||
":app-code",
|
||||
],
|
||||
)
|
@ -1,151 +0,0 @@
|
||||
apply plugin: "com.android.application"
|
||||
|
||||
import com.android.build.OutputFile
|
||||
|
||||
/**
|
||||
* The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets
|
||||
* and bundleReleaseJsAndAssets).
|
||||
* These basically call `react-native bundle` with the correct arguments during the Android build
|
||||
* cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the
|
||||
* bundle directly from the development server. Below you can see all the possible configurations
|
||||
* and their defaults. If you decide to add a configuration block, make sure to add it before the
|
||||
* `apply from: "../../node_modules/react-native/react.gradle"` line.
|
||||
*
|
||||
* project.ext.react = [
|
||||
* // the name of the generated asset file containing your JS bundle
|
||||
* bundleAssetName: "index.android.bundle",
|
||||
*
|
||||
* // the entry file for bundle generation
|
||||
* entryFile: "index.android.js",
|
||||
*
|
||||
* // whether to bundle JS and assets in debug mode
|
||||
* bundleInDebug: false,
|
||||
*
|
||||
* // whether to bundle JS and assets in release mode
|
||||
* bundleInRelease: true,
|
||||
*
|
||||
* // whether to bundle JS and assets in another build variant (if configured).
|
||||
* // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants
|
||||
* // The configuration property can be in the following formats
|
||||
* // 'bundleIn${productFlavor}${buildType}'
|
||||
* // 'bundleIn${buildType}'
|
||||
* // bundleInFreeDebug: true,
|
||||
* // bundleInPaidRelease: true,
|
||||
* // bundleInBeta: true,
|
||||
*
|
||||
* // whether to disable dev mode in custom build variants (by default only disabled in release)
|
||||
* // for example: to disable dev mode in the staging build type (if configured)
|
||||
* devDisabledInStaging: true,
|
||||
* // The configuration property can be in the following formats
|
||||
* // 'devDisabledIn${productFlavor}${buildType}'
|
||||
* // 'devDisabledIn${buildType}'
|
||||
*
|
||||
* // the root of your project, i.e. where "package.json" lives
|
||||
* root: "../../",
|
||||
*
|
||||
* // where to put the JS bundle asset in debug mode
|
||||
* jsBundleDirDebug: "$buildDir/intermediates/assets/debug",
|
||||
*
|
||||
* // where to put the JS bundle asset in release mode
|
||||
* jsBundleDirRelease: "$buildDir/intermediates/assets/release",
|
||||
*
|
||||
* // where to put drawable resources / React Native assets, e.g. the ones you use via
|
||||
* // require('./image.png')), in debug mode
|
||||
* resourcesDirDebug: "$buildDir/intermediates/res/merged/debug",
|
||||
*
|
||||
* // where to put drawable resources / React Native assets, e.g. the ones you use via
|
||||
* // require('./image.png')), in release mode
|
||||
* resourcesDirRelease: "$buildDir/intermediates/res/merged/release",
|
||||
*
|
||||
* // by default the gradle tasks are skipped if none of the JS files or assets change; this means
|
||||
* // that we don't look at files in android/ or ios/ to determine whether the tasks are up to
|
||||
* // date; if you have any other folders that you want to ignore for performance reasons (gradle
|
||||
* // indexes the entire tree), add them here. Alternatively, if you have JS files in android/
|
||||
* // for example, you might want to remove it from here.
|
||||
* inputExcludes: ["android/**", "ios/**"],
|
||||
*
|
||||
* // override which node gets called and with what additional arguments
|
||||
* nodeExecutableAndArgs: ["node"],
|
||||
*
|
||||
* // supply additional arguments to the packager
|
||||
* extraPackagerArgs: []
|
||||
* ]
|
||||
*/
|
||||
|
||||
project.ext.react = [
|
||||
entryFile: "index.js"
|
||||
]
|
||||
|
||||
apply from: "../../node_modules/react-native/react.gradle"
|
||||
|
||||
/**
|
||||
* Set this to true to create two separate APKs instead of one:
|
||||
* - An APK that only works on ARM devices
|
||||
* - An APK that only works on x86 devices
|
||||
* The advantage is the size of the APK is reduced by about 4MB.
|
||||
* Upload all the APKs to the Play Store and people will download
|
||||
* the correct one based on the CPU architecture of their device.
|
||||
*/
|
||||
def enableSeparateBuildPerCPUArchitecture = false
|
||||
|
||||
/**
|
||||
* Run Proguard to shrink the Java bytecode in release builds.
|
||||
*/
|
||||
def enableProguardInReleaseBuilds = false
|
||||
|
||||
android {
|
||||
compileSdkVersion rootProject.ext.compileSdkVersion
|
||||
buildToolsVersion rootProject.ext.buildToolsVersion
|
||||
|
||||
defaultConfig {
|
||||
applicationId "com.gundemo"
|
||||
minSdkVersion rootProject.ext.minSdkVersion
|
||||
targetSdkVersion rootProject.ext.targetSdkVersion
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
ndk {
|
||||
abiFilters "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
splits {
|
||||
abi {
|
||||
reset()
|
||||
enable enableSeparateBuildPerCPUArchitecture
|
||||
universalApk false // If true, also generate a universal APK
|
||||
include "armeabi-v7a", "x86"
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled enableProguardInReleaseBuilds
|
||||
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
|
||||
}
|
||||
}
|
||||
// applicationVariants are e.g. debug, release
|
||||
applicationVariants.all { variant ->
|
||||
variant.outputs.each { output ->
|
||||
// For each separate APK per architecture, set a unique version code as described here:
|
||||
// http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits
|
||||
def versionCodes = ["armeabi-v7a":1, "x86":2]
|
||||
def abi = output.getFilter(OutputFile.ABI)
|
||||
if (abi != null) { // null for the universal-debug, universal-release variants
|
||||
output.versionCodeOverride =
|
||||
versionCodes.get(abi) * 1048576 + defaultConfig.versionCode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile project(':react-native-webview-bridge')
|
||||
implementation fileTree(dir: "libs", include: ["*.jar"])
|
||||
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
|
||||
implementation "com.facebook.react:react-native:+" // From node_modules
|
||||
}
|
||||
|
||||
// Run this once to be able to run the application with BUCK
|
||||
// puts all compile dependencies into folder libs for BUCK to use
|
||||
task copyDownloadableDepsToLibs(type: Copy) {
|
||||
from configurations.compile
|
||||
into 'libs'
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
@ -1,26 +0,0 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.gundemo">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||
|
||||
<application
|
||||
android:name=".MainApplication"
|
||||
android:label="@string/app_name"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:allowBackup="false"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,15 +0,0 @@
|
||||
package com.gundemo;
|
||||
|
||||
import com.facebook.react.ReactActivity;
|
||||
|
||||
public class MainActivity extends ReactActivity {
|
||||
|
||||
/**
|
||||
* Returns the name of the main component registered from JavaScript.
|
||||
* This is used to schedule rendering of the component.
|
||||
*/
|
||||
@Override
|
||||
protected String getMainComponentName() {
|
||||
return "GunDemo";
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package com.gundemo;
|
||||
|
||||
import android.app.Application;
|
||||
|
||||
import com.facebook.react.ReactApplication;
|
||||
import com.github.alinz.reactnativewebviewbridge.WebViewBridgePackage;
|
||||
import com.facebook.react.ReactNativeHost;
|
||||
import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.shell.MainReactPackage;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
|
||||
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
|
||||
@Override
|
||||
public boolean getUseDeveloperSupport() {
|
||||
return BuildConfig.DEBUG;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<ReactPackage> getPackages() {
|
||||
return Arrays.<ReactPackage>asList(
|
||||
new MainReactPackage(),
|
||||
new WebViewBridgePackage()
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getJSMainModuleName() {
|
||||
return "index";
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public ReactNativeHost getReactNativeHost() {
|
||||
return mReactNativeHost;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
}
|
||||
}
|
Before Width: | Height: | Size: 3.0 KiB |
Before Width: | Height: | Size: 4.9 KiB |
Before Width: | Height: | Size: 2.0 KiB |
Before Width: | Height: | Size: 2.8 KiB |
Before Width: | Height: | Size: 4.5 KiB |
Before Width: | Height: | Size: 6.9 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 15 KiB |
@ -1,3 +0,0 @@
|
||||
<resources>
|
||||
<string name="app_name">GunDemo</string>
|
||||
</resources>
|
@ -1,8 +0,0 @@
|
||||
<resources>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -1,39 +0,0 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
buildToolsVersion = "27.0.3"
|
||||
minSdkVersion = 16
|
||||
compileSdkVersion = 27
|
||||
targetSdkVersion = 26
|
||||
supportLibVersion = "27.1.1"
|
||||
}
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
google()
|
||||
jcenter()
|
||||
maven {
|
||||
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
||||
url "$rootDir/../node_modules/react-native/android"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
task wrapper(type: Wrapper) {
|
||||
gradleVersion = '4.4'
|
||||
distributionUrl = distributionUrl.replace("bin", "all")
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
# Default value: -Xmx10248m -XX:MaxPermSize=256m
|
||||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
|
||||
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
@ -1,5 +0,0 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
172
examples/react-native/android/gradlew
vendored
@ -1,172 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
# Resolve links: $0 may be a link
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin, switch paths to Windows format before running java
|
||||
if $cygwin ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
case $i in
|
||||
(0) set -- ;;
|
||||
(1) set -- "$args0" ;;
|
||||
(2) set -- "$args0" "$args1" ;;
|
||||
(3) set -- "$args0" "$args1" "$args2" ;;
|
||||
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=$(save "$@")
|
||||
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
|
||||
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
|
||||
cd "$(dirname "$0")"
|
||||
fi
|
||||
|
||||
exec "$JAVACMD" "$@"
|
84
examples/react-native/android/gradlew.bat
vendored
@ -1,84 +0,0 @@
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%" == "" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if "%ERRORLEVEL%" == "0" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto init
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:init
|
||||
@rem Get command-line arguments, handling Windows variants
|
||||
|
||||
if not "%OS%" == "Windows_NT" goto win9xME_args
|
||||
|
||||
:win9xME_args
|
||||
@rem Slurp the command line arguments.
|
||||
set CMD_LINE_ARGS=
|
||||
set _SKIP=2
|
||||
|
||||
:win9xME_args_slurp
|
||||
if "x%~1" == "x" goto execute
|
||||
|
||||
set CMD_LINE_ARGS=%*
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if "%ERRORLEVEL%"=="0" goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
|
||||
exit /b 1
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@ -1,8 +0,0 @@
|
||||
keystore(
|
||||
name = "debug",
|
||||
properties = "debug.keystore.properties",
|
||||
store = "debug.keystore",
|
||||
visibility = [
|
||||
"PUBLIC",
|
||||
],
|
||||
)
|
@ -1,4 +0,0 @@
|
||||
key.store=debug.keystore
|
||||
key.alias=androiddebugkey
|
||||
key.store.password=android
|
||||
key.alias.password=android
|
@ -1,5 +0,0 @@
|
||||
rootProject.name = 'GunDemo'
|
||||
include ':react-native-webview-bridge'
|
||||
project(':react-native-webview-bridge').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview-bridge/android')
|
||||
|
||||
include ':app'
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"name": "GunDemo",
|
||||
"displayName": "GunDemo"
|
||||
}
|
8
examples/react-native/index.js
vendored
@ -1,8 +0,0 @@
|
||||
/** @format */
|
||||
import './shim';
|
||||
import {AppRegistry} from 'react-native';
|
||||
import App from './src/App';
|
||||
import {name as appName} from './app.json';
|
||||
|
||||
AppRegistry.registerComponent(appName, () => App);
|
||||
console.disableYellowBox = true;
|