可以在Chrome中使用隐身和常规标签与多个用户一起在localhost上测试我的社交聊天应用程序吗?

问题描述

我正在为一个用户使用Chrome普通窗口,为另一个用户使用隐身窗口。 套接字仅将数据发送给正在调用它们的用户,因此用户之间不会交换数据。但是,它们仅在调用它们的用户之间在叶状体和后端之间发送数据。 我使用同一台本地计算机进行测试的方式是否错误

以下是一些摘要

客户端:

  submit() {
      if (this.text) {
        this.socket.emit("new-message",{
          text: this.text,sender: this._id,receiver: this.userPop._id,date: Date.Now(),seen: false,});
        const msg = {
          text: this.text,};

        this.sent.push(msg);
        this.text = "";
 this.socket.on("fetch-message",async (data) => console.log(data));
 text(value) {
      value
        ? this.socket.emit("sender_typing",{
            receiver: this.userPop.first_name,receiver_id: this.userPop._id,sender_id:this._id,sender: this.user.first_name,senderSocketId: this.socket.id,})
        : this.socket.emit("stopTyping");
    },
 mounted() {
    this.socket.on("typing",async (data) => {
      await console.log(data.receiver_id,data.sender_id);
       if (this._id === data.receiver_id) {
        this.typing = data.sender;
      
      }
    });

    this.socket.on("stop_typing",() => {
      this.typing = "";
    });
    // this.socket.on("seen_server",(data)=>{
    //   this.seen= data.message
    // })
  },

后端套接字:

socket.on("new-message",async(data)=>{
   await console.log(data)
 
   await Message.create(data)
    .then(async (msg) => {
      return msg.save();
    })
    .then(async (msg) => {
      const newMsg = await msg.toObject();
      console.log(newMsg);
     socket.emit('fetch-message',{newMsg})
    })
    .catch(err=> console.log(err))
  })
socket.on("sender_typing",async(data) => {
   await console.log(data)
   socket.emit('typing',{
     sender: data.sender,sender_id:data.sender_id,socket_id: socket.id,receiver_id:data.receiver_id,})
    
  });

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)