Firebase活动“<用户>正在写...“像WhatsApp

编程入门 行业动态 更新时间:2024-10-23 19:27:28
本文介绍了Firebase活动“<用户>正在写...“像WhatsApp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否有任何方式在Firebase事件中克隆whatsapp事件 [user]正在撰写... ?

阅读 www.firebase/docs/web/api/上的Firebase活动但是我还没有发现任何问题。 $ b $ p

谢谢。

解决方案

var ref = new Firebase('https: //<your-app>.firebaseio'); var input = document.getElementById('input'); var typers = document.getElementById('typers'); var uid = Date.now(); //产生一个假的用户ID var timer; //附加一个侦听器,显示当前在列表中输入的所有人员 ref.on('value',function(snapshot){ typers.innerText =''; snapshot.forEach(function(typer){ var li = document.createElement('li'); li.innerText = typer.key(); typers.appendChild (li); }); }); //每当textarea的内容改变时 input.addEventListener('input',function(e){ //标记这个用户一个输入 ref.child(uid).set(true); //如果我们倒计时,停止定时器 if(timer)clearTimeout(timer); //删除用户在2秒内 timer = setTimeout(function(){ ref.child(uid).remove(); },2000); });

若要查看它,请查看这个JSBin 。 我宣布的 tweet 。

Is there any manner to clone the whatsapp event "[user] is writing..." in Firebase events?

I have reading about the Firebase events in www.firebase/docs/web/api/ but I've not found anything about the issue.

Thanks.

解决方案

I wrote such a typing indicator a while ago.

var ref = new Firebase('<your-app>.firebaseio'); var input = document.getElementById('input'); var typers = document.getElementById('typers'); var uid = Date.now(); // generate a fake user id var timer; // attach a listener that display all people current typing in a list ref.on('value', function(snapshot) { typers.innerText = ''; snapshot.forEach(function(typer) { var li = document.createElement('li'); li.innerText = typer.key(); typers.appendChild(li); }); }); // whenever the content of the textarea changes input.addEventListener('input',function(e) { // mark this user a "typing" ref.child(uid).set(true); // if we're counting down, stop the timer if (timer) clearTimeout(timer); // remove this user in 2 seconds timer = setTimeout(function() { ref.child(uid).remove(); }, 2000); });

To see it in action, have a look at this JSBin. The tweet where I announced it.

更多推荐

Firebase活动“&lt;用户&gt;正在写...“像WhatsApp

本文发布于:2023-11-28 13:01:15,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用户   amp   Firebase   lt   WhatsApp

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!