多くの人がMeteorを勉強してまず思うのが、チャットアプリを簡単に作れるな、ということだろう。
クライアント(minimongo)とサーバ(mongo)がソケット通信(DDP)で勝手に通信してくれるのだから、ほかに何もすることはない。
何もすることはないと言っても、UIとか、ROOM管理とか、やはり面倒な仕事はある。そんな時に便利なのがsimple-chatだ。ここにはチャットアプリに必要な基本が全て揃っている。
というわけで、デモプログラムを動かしてみた。その設定手順です。
まず以下のコマンドを打つべし!
meteor create simple-chat
cd simple-chat
meteor npm install
rm server/*
rm client/*
meteor add session
meteor add random
meteor add cesarve:simple-chat
meteor add twbs:bootstrap
meteor add kadira:blaze-layout
meteor add kadira:flow-router
meteor add audit-argument-checks
meteor remove autopublish
次に以下のデモプログラムをダウンロードする
https://github.com/cesarve77/demo-simple-chat
デモプログラムをsimple-chatディレクトリ直下に置く
simplechat.html
simplechat.js
simplechat.css
public
以上で一応動作するはずです。
但しroomに入るときに以下のエラーが出ます。エラーは出るが動作はします。
Exception while invoking method 'SimpleChat.join' TypeError: SimpleChat.options.onJoin is not a function
まあ、これからsimple-chat本体のプログラムを読み解く予定なので、その時に一緒にデッバグできたらいいなと思います。