用Meteor 写个即时聊天app

来源:互联网 发布:儿童 绘画 推荐 知乎 编辑:程序博客网 时间:2024/06/07 12:15

https://github.com/Phil-EPAM/chattingMeteor

基本写好了,周末前传到server上去。


刚放上去github上由于用的是公司账户,没有权限,又弄了一遍ssh。


在OSX下,如果cd ~/.ssh如果是空的。 https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

官方文档最清楚


创建完用vim 进入,copy内容,打开Github 右上角的setting,add一个新的key,git config一下基本就搞定了。


Meteor 适用于即时通信要求高的场景,它用websocket来传达信息(优于ajax pull, long pull)。 今天还讲了个webrtc(Real Time Communication),很神奇。


用自带的blaze模版可以在template helper里面写function,在前端就可以用。

比如说

Template.body.helpers({  isOwner:function(name){    if ( name === Meteor.userId()){      return true    }  },  chatContent() {    var x = Template.instance().UID.get('UID');    return ChatHistory.find({'UID':x},{sort: {lastModified: 1}})  },  users() {    return Meteor.users.find({},{sort: {username: 1}})  },});

在html里我就加了个right class进去:

  <div class="{{creatBy}} chatpanel {{#if isOwner creatBy}}right{{/if}}">{{text}}</div>

db.chatHistory.insert({'owner':'ucbmDzYaCiSFwqzCu','chattingTo':'2T9u2apuhBTeM5tsS','history':[{'text':'123','creatAt':new Date()}]})


db.chatHistory.update({'owner':'ucbmDzYaCiSFwqzCu','chattingTo':'2T9u2apuhBTeM5tsS'},{$push:{'history':{'text':321,'creatAt':new Date()}}})

0 0