Skip to content

Commit

Permalink
spike of firebase auth/signin and file upload to cloud storage
Browse files Browse the repository at this point in the history
  • Loading branch information
presstube committed Apr 18, 2017
1 parent f509f16 commit 526ae87
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 6 deletions.
7 changes: 7 additions & 0 deletions cors.json
@@ -0,0 +1,7 @@
[
{
"origin": ["*"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
3 changes: 2 additions & 1 deletion index.html
Expand Up @@ -7,6 +7,7 @@
<script src="build/main.js"></script>
</head>
<body>
<div id="firebaseui-auth-container"></div>
<a-scene fog="color: #ccc; near: .1; far:3">
<a-sky color="#ccc"></a-sky>
<a-camera
Expand All @@ -32,4 +33,4 @@
</a-scene>
<a id="downloadAnchorElem" style="display:none"></a>
</body>
</html>
</html>
65 changes: 65 additions & 0 deletions js/firebasesavespike.js
@@ -0,0 +1,65 @@

import * as firebase from "firebase"
import * as firebaseui from "firebaseui"

const config = {
apiKey: "AIzaSyBxE0HZfnB7uF2J57oTmjFX-0mLeBfJI-0",
authDomain: "cloudstoragespike.firebaseapp.com",
databaseURL: "https://cloudstoragespike.firebaseio.com",
projectId: "cloudstoragespike",
storageBucket: "cloudstoragespike.appspot.com",
messagingSenderId: "10638532760"
}

firebase.initializeApp(config)


// document.addEventListener('keydown', e => {
// // console.log('keydown: ', e.key)
// if (e.key == 'S') {
// uploadAnimData('bongo.json', {
// blah: 'bongobongo',
// bloo: 123,
// blee: [1, 2, 3]
// })
// }
// })

const uiConfig = {
signInSuccessURL: '',
signInOptions: [
firebase.auth.GoogleAuthProvider.PROVIDER_ID,
],
tosURL: 'myTOS.txt',
callbacks: {
signInSuccess: (currentUser, credential, redirectUrl) => {
// Do something.
// Return type determines whether we continue the redirect automatically
// or whether we leave that to developer to handle.
// console.log('signin success')
return false // to allow the success page to be same as signin
},
}
},
ui = new firebaseui.auth.AuthUI(firebase.auth())

firebase.auth().onAuthStateChanged(function(user) {
if (user) {
// firebase.auth().signOut()
console.log('already signed in')
} else {
ui.start('#firebaseui-auth-container', uiConfig)
}
});


const uploadAnimData = (filename, animData) => {
const uploadRef = firebase.storage().ref().child('animData/' + filename),
file = new Blob([JSON.stringify(animData)], {type: 'application/json'})

return uploadRef.put(file).then(function(snapshot) {
console.log('upload succeeded whoooo: ', snapshot.downloadURL)
})
}

export {uploadAnimData}
3 changes: 2 additions & 1 deletion js/index.js
@@ -1,2 +1,3 @@
import _ from 'lodash'
import './norman'
import './norman'
// import './firebasesavespike'
16 changes: 12 additions & 4 deletions js/norman.js
Expand Up @@ -2,6 +2,8 @@ import 'aframe'
import _ from 'lodash'
import $ from 'jquery'

import {uploadAnimData} from './firebasesavespike'

import './anim'
import './drawline'
import './onionskin'
Expand Down Expand Up @@ -29,11 +31,14 @@ AFRAME.registerComponent('norman', {
this.frameInterval = 1000 / this.fps
this.setupKeyboard()
_.delay(this.setupControllers.bind(this), 1)
$.getJSON('webvr-exports/snap-connect-1.json', json => {
// this.animData = json.data
// $.getJSON('webvr-exports/snap-connect-1.json', json => {
const downloadURL = 'https://firebasestorage.googleapis.com/v0/b/cloudstoragespike.appspot.com/o/animData%2FtestAnimData.json?alt=media&token=2fe8120e-76ad-4ce3-a2cc-2647435a60dc'

$.getJSON(downloadURL, json => {
this.animData = json.data
this.addAnim()
this.addHomeFrameGhost()
// this.startPlaying()
this.startPlaying()
this.setupOnionSkin()
})
},
Expand All @@ -42,7 +47,10 @@ AFRAME.registerComponent('norman', {
document.addEventListener('keydown', e => {
// console.log('keydown: ', e.key)
if (e.code == 'Enter') {this.togglePlay()}
else if (e.key == 'S') {this.saveAnimDataFile()}
else if (e.key == 'S') {
// console.log('saving: ')
uploadAnimData('testAnimData.json', {data: this.animData})
}
else if (e.key == 'o') {this.toggleOnion()}
else if (e.key == ',') {this.changeFPS(-1)}
else if (e.key == '.') {this.changeFPS(1)}
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -8,6 +8,8 @@
},
"dependencies": {
"aframe": "^0.5.0",
"firebase": "^3.7.8",
"firebaseui": "^1.0.1",
"jquery": "^3.2.1",
"lodash": "^4.17.4"
},
Expand Down

0 comments on commit 526ae87

Please sign in to comment.