Created
April 23, 2015 23:32
-
-
Save ghsyeung/5697643d5f98f8ef77e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <reference path="../../tools/typings/firebase/firebase.d.ts"/> | |
module Chat { | |
class ChatMessage { | |
constructor(public name:string, public text:string) { | |
} | |
} | |
export class ChatEngine { | |
private static baseUrl = "<Your Firebase URL>"; | |
private firebase; | |
constructor(private name:string) { | |
this.firebase = new Firebase(ChatEngine.baseUrl); | |
} | |
send(message:string) { | |
this.firebase.push(new ChatMessage(this.name, message)); | |
} | |
startReceive() { | |
this.firebase.on('child_added', (snapshot:FirebaseDataSnapshot) => { | |
this.displayMessage(snapshot.val()); | |
}); | |
} | |
displayMessage(message:ChatMessage) { | |
console.log("%c%s: %c%s", 'color: red', message.name, 'color: green', message.text); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment