Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbddb5eb

Browse files
committed
Updates the Web app to work with the new Firebase library
1 parente854670 commitbddb5eb

File tree

1 file changed

+22
-22
lines changed
  • examples/FirebaseNeoPixel_ESP8266/public

1 file changed

+22
-22
lines changed

‎examples/FirebaseNeoPixel_ESP8266/public/index.html

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,16 @@
1616
-->
1717
<html>
1818
<head>
19-
<scriptsrc="https://cdn.firebase.com/js/client/2.2.1/firebase.js"></script>
19+
<scriptsrc="https://www.gstatic.com/firebasejs/3.5.2/firebase.js"></script>
2020
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
2121
<scriptsrc="bower_components/webcomponentsjs/webcomponents-lite.js"></script>
2222
<linkrel="import"href="./bower_components/polymer-color-picker/polymer-color-picker.html">
2323
</head>
2424
<script>
25-
// TODO: Needs security.
26-
varfirebaseUrl='https://example.firebaseio.com';
27-
varfirebaseSecret=secret_or_token;
25+
// NOTICE: Retrieve these values from the Firebase console to run the sample.
26+
varfirebaseDb='yourproject.firebaseio.com';
27+
varfirebaseAuthDomain='yourproject.firebaseapp.com';
28+
varfirebaseApiKey='your_api_key';
2829
</script>
2930
<body>
3031
<h2>Paint Demo</h3>
@@ -113,32 +114,31 @@ <h3>Debugger / tester</h3>
113114
}
114115
</pre>
115116

116-
<script>
117-
// Firebase reference and authentication stored globally.
118-
// TODO: Encapsualte into objects, move to separate JS file
119-
varpixelData=newFirebase(firebaseUrl);
120-
pixelData.authWithCustomToken(firebaseSecret,function(error,result){
121-
if(error){
122-
console.log("Authentication Failed!",error);
123-
}else{
124-
console.log("Authenticated successfully with payload:",result.auth);
125-
console.log("Auth expires at:",newDate(result.expires*1000));
126-
refreshData();
127-
}});
117+
<script>
118+
// Initialize Firebase
119+
varconfig={
120+
apiKey:firebaseApiKey,
121+
authDomain:firebaseAuthDomain,
122+
databaseURL:"https://"+firebaseDb,
123+
storageBucket:'',// not used
124+
messagingSenderId:'',// not used
125+
};
126+
firebase.initializeApp(config);
127+
varpixelData=firebase.database();
128128

129129
/**
130130
* Explicitly refreshes data from Firebase.
131131
* TODO: replace with streaming function that listens for events / updates.
132132
*/
133133
functionrefreshData(){
134-
pixelData.once("value",function(snapshot){
134+
pixelData.ref('/rgbdata/').once("value",function(snapshot){
135135
console.log(snapshot.val());
136-
document.getElementById('pixelData').value=JSON.stringify(snapshot.val()['rgbdata'],2);
136+
document.getElementById('pixelData').value=JSON.stringify(snapshot.val(),2);
137137

138138
for(vari=0;i<32;i++){
139139
varqString='pixel'+i;
140-
if(snapshot.val()['rgbdata'][qString]){
141-
varhexString=parseInt(snapshot.val()['rgbdata'][qString]).toString(16);
140+
if(snapshot.val()[qString]){
141+
varhexString=parseInt(snapshot.val()[qString]).toString(16);
142142
varzeroPrepend=6-hexString.length;
143143
for(varj=0;j<zeroPrepend;j++){
144144
hexString='0'+hexString;
@@ -161,7 +161,7 @@ <h3>Debugger / tester</h3>
161161
* the Firebase database. Note that this is best for debugging.
162162
*/
163163
functionpushData(){
164-
pixelData.set({'rgbdata':JSON.parse(document.getElementById('pixelData').value)});
164+
pixelData.ref('/rgbdata/').set(JSON.parse(document.getElementById('pixelData').value));
165165
refreshData();
166166
}
167167

@@ -199,7 +199,7 @@ <h3>Debugger / tester</h3>
199199
*/
200200
functionupdatePixel(pixelId){
201201
varpath='rgbdata/'+pixelId;
202-
varpixelRef=pixelData.child(path);
202+
varpixelRef=pixelData.ref(path);
203203
varcolorHex=
204204
rgb2hex(document.getElementById(pixelId).style.backgroundColor)
205205
.split('#')[1];

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp