Giter Site home page Giter Site logo

firebase / codelab-friendlychat-web Goto Github PK

View Code? Open in Web Editor NEW
1.7K 148.0 1.8K 26.54 MB

The source for the Firebase codelab for building a cross-platform chat app

Home Page: https://firebase.google.com

License: Apache License 2.0

HTML 19.27% JavaScript 44.93% CSS 10.98% TypeScript 9.38% SCSS 1.32% HCL 14.12%
firebase codelab

codelab-friendlychat-web's Introduction

codelab-friendlychat-web's People

Contributors

andreaowu avatar asciimike avatar brandon-irl avatar dpebot avatar emelleme avatar fulv avatar gkaldev avatar hyacccint avatar ianbarber avatar ichthyscode avatar inlined avatar jamesdaniels avatar jamesvanwaza avatar jenh avatar jhuleatt avatar jmdobry avatar kroikie avatar morganchen12 avatar nicolasgarnier avatar nohe427 avatar oguzhnatly avatar rakhi2104 avatar samtstern avatar silvolu avatar tjohns avatar ulukaya avatar viliuskraujutis avatar zaki-yama avatar zayna-shahzad avatar zijianjoy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codelab-friendlychat-web's Issues

Site not found?

I have deployed the completed web app to firebase, however when I go there, I get a message saying 'Site not Found'. Is there any way to fix this?

Cannot deploy?

I am trying to deploy the completed app, however it is not working. Here are my logs:

egaumbp:web gg$ firebase deploy

=== Deploying to 'friendlychat-6e4c3'...

i deploying database, storage, hosting
i storage: checking rules for compilation errors...

Error: Compilation error in storage.rules:

[E] 3:12 - Unexpected '<'.

Having trouble? Try firebase deploy --help

FirebaseApiNotAvailableException

Followed the tutorial For Android and after implementing the sign in/sign out, Firebase threw an exception like
com.google.firebase.FirebaseApiNotAvailableException: API: InternalFirebaseAuth.FIREBASE_AUTH_API is not available on this device.

Android: Retrieve photoURL not populating from Firebase

When a record is loaded from Firebase, the photoURL isn't being populated in the model. This is because the photoURL db property doesn't match the Camel Case attribute referenced in the model.

Please change photoUrl to photoURL, setPhotoUrl to setPhotoURL and getPhotoUrl to getPhotoURL.

This is not an issue when a message is sent because the model's constructor is called and sets the right property. I'm not sure if that value is carried through to the DB but the client UI looks correct.

Older version running on Codelab Computers

The version of Firebase CLI installed on the Codelab Computers (firebase 2.2.x) are older that the version used for the Codelab examples (firebase 3.x.x). It should be indicated in the Codelab documentation that users have to use the updated version of firebase CLI.

firebase serve config

Whilst working through you Web Chat App Javascript tutorial I hit an error when executing firebase serve.

From, firebase-debug.log:
[debug] TypeError: Cannot read property 'public' of undefined at Server.<anonymous> (/usr/local/lib/node_modules/firebase-tools/commands/serve.js:25:15)

I was able to prevent this error by commenting out the following lines in serve.js (obviously not ideal):
if (config.public && config.public !== '.') { logger.info(chalk.bold('Public Directory:'), config.public); }

User Sign-in

In the Initialize Firebase Auth section, the Firebase SDK features, this.auth(); etc return an error saying this.auth() is not a function:

  // Shortcuts to Firebase SDK features.
  this.auth = this.auth();
  this.database = this.database();
  this.storage = this.storage();

main.js:59 Uncaught TypeError: this.auth is not a function

Changing these to firebase or more explicitly window.firebase solves this:

  // Shortcuts to Firebase SDK features.
  this.auth = firebase.auth();
  this.database = firebase.database();
  this.storage = firebase.storage();

Swift Tutorial - Sign out crashes

Workaround is to replace the line

performSegueWithIdentifier(Constants.Segues.FpToSignIn, sender: nil)

with

dismissViewControllerAnimated(true, completion: nil)

in the signOut function in FCViewController.swift

ios error when trying to add photo

  • running complete ios project.
  • Adding messages no problem
  • When trying to add a photo, app bombs with following error

2016-05-20 14:37:10.156 FriendlyChatSwift[32573:72997859] *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.60.7/UITableView.m:1716 2016-05-20 14:37:10.162 FriendlyChatSwift[32573:72997859] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (7), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).' *** First throw call stack: ( 0 CoreFoundation 0x0000000108852d85 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x000000010a9bddeb objc_exception_throw + 48 2 CoreFoundation 0x0000000108852bea +[NSException raise:format:arguments:] + 106 3 Foundation 0x0000000108ca3d5a -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x00000001095394ca -[UITableView _endCellAnimationsWithContext:] + 15146 5 UIKit 0x000000010954fcf0 -[UITableView _updateRowsAtIndexPaths:updateAction:withRowAnimation:] + 303 6 FriendlyChatSwift 0x0000000105a13f16 _TFFC17FriendlyChatSwift16FCViewController14viewWillAppearFSbT_U_FCSo15FIRDataSnapshotT_ + 774 7 FriendlyChatSwift 0x0000000105adf419 __63-[FIRDatabaseQuery observeEventType:withBlock:withCancelBlock:]_block_invoke + 37 8 FriendlyChatSwift 0x0000000105b064bc __43-[FChildEventRegistration fireEvent:queue:]_block_invoke64 + 88 9 libdispatch.dylib 0x000000010b467d9d _dispatch_call_block_and_release + 12 10 libdispatch.dylib 0x000000010b4883eb _dispatch_client_callout + 8 11 libdispatch.dylib 0x000000010b4701ef _dispatch_main_queue_callback_4CF + 1738 12 CoreFoundation 0x00000001087ac0f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9 13 CoreFoundation 0x000000010876db99 __CFRunLoopRun + 2073 14 CoreFoundation 0x000000010876d0f8 CFRunLoopRunSpecific + 488 15 GraphicsServices 0x000000010c8bcad2 GSEventRunModal + 161 16 UIKit 0x0000000109409f09 UIApplicationMain + 171 17 FriendlyChatSwift 0x0000000105a1974d main + 125 18 libdyld.dylib 0x000000010b4bc92d start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException

Web Tutorial - Typo in step 12

In step 12 (Storage Security Rules), the last section header is "Deploy Database Security Rules", while it should be "Deploy _Storage_ Security Rules"

Sign-in Failed - Android

While trying to sign-in, I keep getting the following error.
E/SignInActivity: Google Sign In failed. Status{statusCode=unknown status code: 12501, resolution=null}, null
I suspect it's the GoogleSignInOptions requestIdToken() method causing the issue. I changed the string passed as the default_web_client_id to the credentials of server key auto generated in Google APIs credentials. That doesn't seem to work either.

Am I missing something, or doing something wrong?

imageData returning nil

The code is bugging out on this line:

self.profileImageStorage.child(imagePath).putData(imageData!, metadata: metadata) { (metadata, error) in

because the line:

let imageData = UIImageJPEGRepresentation(image, 1)

is returning nil and then failing when putting the data.

Currently I am just trying to get the upload to work before implementing further code relavant to my project. Here is my picker delegate code:

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {

        let image : UIImage = info[UIImagePickerControllerOriginalImage] as! UIImage

        self.profileImage.image = image

        let imageData = UIImageJPEGRepresentation(image, 1)
        let imagePath = FIRAuth.auth()!.currentUser!.uid +
            "/\(Int(NSDate.timeIntervalSinceReferenceDate() * 1000)).jpg"
        let metadata = FIRStorageMetadata()
        metadata.contentType = "image/jpeg"
        self.profileImageStorage.child(imagePath).putData(imageData!, metadata: metadata) { (metadata, error) in

                if let error = error {

                    print("Error uploading: \(error)")
                    return

                }
        }

        picker.dismissViewControllerAnimated(true, completion:nil)

    }

[self performSegueWithIdentifier:SeguesFpToSignIn sender:nil] does not work

this paragraph is wrong or not updated.
https://codelabs.developers.google.com/codelabs/firebase-ios-objc/index.html?index=..%2F..%2Findex#4

FCViewController.m

- (IBAction)signOut:(UIButton *)sender {
  FIRAuth *firebaseAuth = [FIRAuth auth];
  NSError *signOutError;
  BOOL status = [firebaseAuth signOut:&signOutError];
  if (!status) {
    NSLog(@"Error signing out: %@", signOutError);
    return;
  }
  [AppState sharedInstance].signedIn = false;
  [self performSegueWithIdentifier:SeguesFpToSignIn sender:nil];
}

[self performSegueWithIdentifier:SeguesFpToSignIn sender:nil];
โ†“
[self dismissViewControllerAnimated:YES completion:NULL];

No sign-in button & Docs update (storageBucket)- "Not enabled Firebase Storage"

Hi,

I'm following the docs precisely (https://codelabs.developers.google.com/codelabs/firebase-web/#) but I keep arriving at the error:

I am not able to see a "Sign-in" button (despite it being in the HTML).

Here is the parts I added to main.js in case there were any errors there (seeing as parts of the document snippets of code ended in ... somewhat confusing...):

FriendlyChat.prototype.initFirebase = function() {
  // Shortcuts to Firebase SDK features.
  this.auth = firebase.auth();
  this.database = firebase.database();
  this.storage = firebase.storage();
  // Initiates Firebase auth and listen to auth state changes.
  this.auth.onAuthStateChanged(this.onAuthStateChanged.bind(this));
};

FriendlyChat.prototype.signIn = function() {
  // Sign in Firebase using popup auth and Google as the identity provider.
  var provider = new firebase.auth.GoogleAuthProvider();
  this.auth.signInWithPopup(provider);
};

FriendlyChat.prototype.signOut = function() {
  // Sign out of Firebase.
  this.auth.signOut();
};

FriendlyChat.prototype.onAuthStateChanged = function(user) {
  if (user) { // User is signed in!
    // Get profile pic and user's name from the Firebase user object.
    var profilePicUrl = user.photoURL;
    var userName = user.displayName;
  }};

  FriendlyChat.prototype.checkSignedInWithMessage = function() {
  // Return true if the user is signed in Firebase
  if (this.auth.currentUser) {
    return true;
  }};]

SEPERATE ISSUE/NOTE:

Initially I kept getting the error:

You have not enabled Firebase Storage prior to importing the firebase SDK

I looked at my script, and it seems there is no value for "storageBucket"

The FIX If I go to the firebase console>Auth>Web Setup (at the top), it generates a snippet of code which includes a storageBucket.

This storageBucket code was only generated once I enabled a sign-in method on Auth.

You should update the docs to this affect.

11. Send Images

in saveImageMessage this:

imageUrl: FriendlyChat.LOADING_IMAGE,

Should be:

imageUrl: FriendlyChat.LOADING_IMAGE_URL,

As earlier in main.js this is set:

FriendlyChat.LOADING_IMAGE_URL = 'https://www.google.com/images/spin-32.gif';

Also there are a few variable name changes required in setImageUrl as the variables passed in are different:

// Sets the URL of the given img element with the URL of the image stored in Firebase Storage.
FriendlyChat.prototype.setImageUrl = function(imageStorageUri, imgElement) {
  // If the image is a Firebase Storage URI we fetch the URL.
  if (imageUri.startsWith('gs://')) {
    image.src = FriendlyChat.LOADING_IMAGE; // Display a loading image first.
    this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) {
      imgElement.src = metadata.downloadURLs[0];
    });
  } else {
    image.src = imageUri;
  }
};

Working version:

// Sets the URL of the given img element with the URL of the image stored in Firebase Storage.
FriendlyChat.prototype.setImageUrl = function(imageStorageUri, imgElement) {
  // If the image is a Firebase Storage URI we fetch the URL.
  if (imageStorageUri.startsWith('gs://')) {
    imgElement.src = FriendlyChat.LOADING_IMAGE_URL; // Display a loading image first.
    this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) {
      imgElement.src = metadata.downloadURLs[0];
    });
  } else {
    imgElement.src = imageUri;
  }
};

Changed imageUri to imageStorageUri, image.src to imgElement.src and LOADING_IMAGE to LOADING_IMAGE_URL.

could not import json

In your project in Firebase console visit the Database section on the left navigation bar. In the overflow menu of the Database select Import JSON.

could not find import button

11. Send images issue

There is a bug in a code

// Sets the URL of the given img element with the URL of the image stored in Firebase Storage. FriendlyChat.prototype.setImageUrl = function(imageUri, imgElement) { // If the image is a Firebase Storage URI we fetch the URL. if (imageUri.startsWith('gs://')) { imgElement.src = FriendlyChat.LOADING_IMAGE; // Display a loading image first. this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) { imgElement.src = metadata.downloadURLs[0]; }); } else { imgElement.src = imageUri; } };
In line
this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) {
imageStorageUri should be replaced with imageUri

Downloading image uses wrong variable name

I've found that when pulling an uploaded image from storage, main.js' setImageUrl() uses imageStorageUri instead of imageUri. This results in an undefined error for me. This line works though:
this.storage.refFromURL(imageUri).getMetadata().then(function(metadata) {

Update web tutorial to include firebase init

There is a missing step in "5. Install the Firebase Command Line Interface." One must firebase init and enter "." for the public directory. Please update the tutorial.

Without doing this firebase serve will fail as it is looking for "public." See #4

Swift Tutorial - Internal Error when clicking Create Account

On page 5 of the tutorial, https://codelabs.developers.google.com/codelabs/firebase-ios-swift/#4, I get an Internal Error when clicking "Create Account".

Here is the tail of the log from the Xcode console:

<FIRAnalytics/DEBUG> Uploading data. Host: https://play.googleapis.com/log
2016-06-07 16:52:47.281 FriendlyChatSwift[90258:] <FIRAnalytics/DEBUG> Received SSL challenge for host. Host: https://play.googleapis.com/log
An internal error has occurred, print and inspect the error details for more information.

Wrong parameter used in saveImageMessage for web-start

Currently reads:

FriendlyChat.prototype.saveImageMessage = function(e) {
  var file = event.target.files[0];

Should read:

FriendlyChat.prototype.saveImageMessage = function(event) {
  var file = event.target.files[0];

It is correct in the web directory.

Install Firebase command line tools step 1 may be incorrect.

when following the instructions here: https://console.firebase.google.com/project/friendlychat-740b9/hosting

on step 1: Install Firebase tools
it says to install using the command: "npm install -g firebase-tools"

yet on this page: https://codelabs.developers.google.com/codelabs/firebase-web/#4
it says after installing, check the version using: "firebase version" and that the version should be "3..."
However it reports version 2.2.

using the instructions here: https://www.npmjs.com/package/firebase-cli
by running the commands:
npm install firebase-cli
and then
npm install -g firebase-tools

it reports version 3.0.

Another typo

see ... https://codelabs.developers.google.com/codelabs/firebase-web/#10
should this be
gs://<bucket>/<uid>/<timestamp>/<file_name>.
instead of
gs://<bucket>/<uid>/<timestamp/<file_name>.
here ...

In the chat messages we saved the Firebase Storage reference of the images. These are of the form gs://<bucket>/<uid>/<timestamp/<file_name>. To display these images we need to query Firebase Storage for a URL.

image upload for the web app does not work

Image upload does not work. when I pick an image the spinner goes on forever without uploading.. he is the console output:
Failed to load resource: https://friendlychat-7f0bc.firebaseapp.com/null
server responded with a status of 404 (Not Found)

If I sign out and sign in again the spinner keeps loading..
Also in order to upload the image, the image name has to start with "image", it would be better to check common extensions like .png, .jpg,..

Swift Tutorial - Adding An Image Crashes Application

When I try add an image on both iPhone/Simulator, the application crashes with the following message:

'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (4), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).'

firebase serve error

I am following the instructions exactly but I'm getting this error.

[debug] ----------------------------------------------------------------------
[debug] Command: C:\Program Files\nodejs\node.exe C:\Users\kuokkit.chan\AppData\Roaming\npm\node_modules\firebase-tools\bin\firebase serve
[debug] CLI Version: 3.0.0
[debug] Platform: win32
[debug] Node Version: v4.4.4
[debug] Time: Tue May 24 2016 09:53:03 GMT+0800 (Malay Peninsula Standard Time)
[debug] ----------------------------------------------------------------------
[debug]
[info] Starting Firebase development server...
[info]
[info] Project Directory: C:\Users\kuokkit.chan\Desktop\Firebase\friendlychat\web-start
[debug] TypeError: Cannot read property 'public' of undefined
at Server. (C:\Users\kuokkit.chan\AppData\Roaming\npm\node_modules\firebase-tools\commands\serve.js:24:15)
at Server.g (events.js:260:16)
at emitNone (events.js:67:13)
at Server.emit (events.js:166:7)
at emitListeningNT (net.js:1260:10)
at nextTickCallbackWith1Arg (node.js:431:9)
at process._tickCallback (node.js:353:17)
[error]
[error] Error: An unexpected error has occurred.

Please help

Typo in Step 11 of Codelabs tut

// Sets the URL of the given img element with the URL of the image stored in Firebase Storage.
FriendlyChat.prototype.setImageUrl = function(imageUri, imgElement) {
  // If the image is a Firebase Storage URI we fetch the URL.
  if (imageUri.startsWith('gs://')) {
    imgElement.src = FriendlyChat.LOADING_IMAGE; // Display a loading image first.
    this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) {
      imgElement.src = metadata.downloadURLs[0];
    });
  } else {
    imgElement.src = imageUri;
  }
};

The line this.storage.refFromURL(imageStorageUri).getMetadata().then(function(metadata) {
should have imageUri in parenthesis instead of imageStorageUri.

Secondly, and unrelated to the title, image upload doesn't seem to work for my and my friend. We've tried everything.

warnings for web-start tutorial step 5, 6

I navigated to the web-start subdirectory, then tried to run

firebase init

but am getting warnings like:

  • You are currently outside your home directory
  • You are initializing in an existing Firebase project directory

is this expected? I tried to skip the init command but if I try to run

firebase use --add
firebase serve

an error results after trying to start the server: Error: An unexpected error has occurred.

IOS-Swift

in FCViewController.swift (FriendlyChatSwift)

The line
if let imageUrl = message[Constants.MessageFields.imageURL] should be
if let imageUrl = message[Constants.MessageFields.photoUrl]

There is no constant imageUrl

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    // Dequeue cell
    let cell: UITableViewCell! = self.clientTable .dequeueReusableCellWithIdentifier("tableViewCell", forIndexPath: indexPath)
    // Unpack message from Firebase DataSnapshot
    let messageSnapshot: FIRDataSnapshot! = self.messages[indexPath.row]
    let message = messageSnapshot.value as! Dictionary<String, String>
    let name = message[Constants.MessageFields.name] as String!
    if let imageUrl = message[Constants.MessageFields.**photoUrl**] {
        if imageUrl.hasPrefix("gs://") 

Sign-in Failed - Android

I cannot sign in again after sign out , got this error in logcat

signInWithCredential:onComplete:false
signInWithCredential com.google.firebase.FirebaseException: An internal error has occured. [ Invalid id_token in IdP response: ...]
at com.google.android.gms.internal.zzacq.zzbN(Unknown Source)
at com.google.android.gms.internal.zzacn$zzg.zza(Unknown Source)
at com.google.android.gms.internal.zzacy.zzbO(Unknown Source)
at com.google.android.gms.internal.zzacy$zza.onFailure(Unknown Source)
at com.google.android.gms.internal.zzact$zza.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:453)

Using emulator to get this error, is that the cause of this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.