Error from JS SDK when using topic.publishMessage to edit and allready sent message

121 views
Skip to first unread message

Dragos

unread,
Oct 5, 2021, 5:44:41 AM10/5/21
to Tinode General

Hello, I want to implement an edit message feature to an app using Vue JS and the latest version of tinode sdk for JS. I have also tried the next branch but with no success.

I am facing an error from the SDK and I don't understand if it's because of something I do wrong or something wrong with the SDK.

What's happening

I use await this.topic.publishMessage(pub) (inside async function) in order to send an edit for a message. The pub object that is sent is as follows
const pub = {
    topic: this.topic.name,
    head: { replace: `${this.topic.name}:${this.item.seq}` },
    content: this.content,
    noecho: true
  }

This is the error I recive in console.  I catch the error in a try/catch block.
error_tinode.png

Here is the line from electron sources tab from dev console that is specified in error.
error_tinode_line.png

The topic is subscribed and everything else works.

What's it a bit weird is that the pub is sent to the server, registered and it affects the other use in chat. He can see the edit.

Meanwhile there are no problems sending "normal"  messages.

Any ideeas how this can be fixed or orvercome ?

Gene

unread,
Oct 5, 2021, 8:52:59 PM10/5/21
to Tinode General
On Tuesday, October 5, 2021 at 2:44:41 AM UTC-7 Dragos wrote:

Hello, I want to implement an edit message feature to an app using Vue JS and the latest version of tinode sdk for JS. I have also tried the next branch but with no success.

I am facing an error from the SDK and I don't understand if it's because of something I do wrong or something wrong with the SDK.

What's happening

I use await this.topic.publishMessage(pub) (inside async function) in order to send an edit for a message. The pub object that is sent is as follows
const pub = {
    topic: this.topic.name,
    head: { replace: `${this.topic.name}:${this.item.seq}` },
    content: this.content,
    noecho: true
  }

This is the error I recive in console.  I catch the error in a try/catch block.

It's easier to use tinode.dev.js during development. It gives you a much better stack traces in the console.
 
error_tinode.png

Here is the line from electron sources tab from dev console that is specified in error.
error_tinode_line.png

The topic is subscribed and everything else works.

If topic were really attached then you would not be getting this error. Please do make sure that the topic is indeed subscribed and attached.
 

What's it a bit weird is that the pub is sent to the server, registered and it affects the other use in chat. He can see the edit.

I do not understand what you mean.

Meanwhile there are no problems sending "normal"  messages.

Please show the logs from the console.

Dragos

unread,
Oct 6, 2021, 5:08:56 AM10/6/21
to Tinode General
I have installed it with npm install. The project is with nuxt. How could I change the tinode source js to dev ?

What I mean is that:

1) 2 users, A and B have a chat
2) User A edits one of their message.
3) User A get's the error but the edit is sent on {pub} with header: {replace:topicname:msgseq} and user B recieves the edited message on {data}.  Some client side code happens that replace the old message with the new one.

If user A wasn't subscribed to the topic, how could the {pub} be sent anyway and recived by user B ?

I could guess that it has something to do with http://tinode.github.io/js-api/tinode.js.html#line3769 and line 3786. Considering the error about using then on undefined.

What logs from sending  normal messages ? There are no erros, it works well. Also here I use publishDraft with a pub made by createMessage . Meanwhile when I edit the message the pub is made by me as an object(see the const pub from the first post)

Gene

unread,
Oct 6, 2021, 11:42:02 AM10/6/21
to Tinode General
On Wednesday, October 6, 2021 at 2:08:56 AM UTC-7 Dragos wrote:
I have installed it with npm install. The project is with nuxt. 

Please confirm that you have seen this notice and followed the installation instructions:

This is NOT a standalone app, this is just a frontend, a client. It requires a backend. See installation instructions.

How could I change the tinode source js to dev ?

Build against tinode.dev.js
 
What I mean is that:

1) 2 users, A and B have a chat
2) User A edits one of their message.
3) User A get's the error but the edit is sent on {pub} with header: {replace:topicname:msgseq} and user B recieves the edited message on {data}.  Some client side code happens that replace the old message with the new one.

 I just have to repeat my previous answer: Please show the logs from the console.

If user A wasn't subscribed to the topic, how could the {pub} be sent anyway and recived by user B ?

Please show the logs.
 
I could guess that it has something to do with http://tinode.github.io/js-api/tinode.js.html#line3769 and line 3786. Considering the error about using then on undefined.

What logs from sending  normal messages ? There are no erros, it works well. Also here I use publishDraft with a pub made by createMessage . Meanwhile when I edit the message the pub is made by me as an object(see the const pub from the first post)

Just show the logs. 

Dragos

unread,
Oct 6, 2021, 3:53:05 PM10/6/21
to Tinode General
What should I build ?

I am not using the react app. I using tinode-sdk in VueJS. I also have a server. On the server everything is ok.

nodejs.png

From package.json.

I have no more logs than what I gave you about that error. All can I do is add more console.logs, but what should I log ?

Aforge Forgess

unread,
Oct 6, 2021, 8:05:59 PM10/6/21
to tin...@googlegroups.com
For using tinode.dev.js you can access your via “/index-dev.html”.

Sent from my iPhone

On Oct 6, 2021, at 08:42, Gene <ge...@tinode.co> wrote:


--
You received this message because you are subscribed to the Google Groups "Tinode General" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tinode+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tinode/aa3e7365-c392-4c6c-a7be-016c18e1ea02n%40googlegroups.com.

Gene Sokolov

unread,
Oct 6, 2021, 8:57:52 PM10/6/21
to tin...@googlegroups.com


On Wed, Oct 6, 2021, 12:53 Dragos <drag...@gmail.com> wrote:
What should I build ?

I am not using the react app. I using tinode-sdk in VueJS. I also have a server. On the server everything is ok.

nodejs.png

From package.json.

I have no more logs than what I gave you about that error. All can I do is add more console.logs, but what should I log ?

--
You received this message because you are subscribed to a topic in the Google Groups "Tinode General" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tinode/yWSF14ZXJ5w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tinode+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tinode/f6ac5814-feab-4708-b3b1-9f1e3968a8a4n%40googlegroups.com.

Dragos

unread,
Oct 7, 2021, 4:00:09 AM10/7/21
to Tinode General
logs_error_sender.pngerror_log_reciver.png

Here are the logs. In white from the sender client, in black from reciver client.
The topic name is hidden, but it's the right name.
As you can see the error happens on sender client but it still sends the edit and the reciver client get it.

Gene

unread,
Oct 7, 2021, 10:50:01 PM10/7/21
to Tinode General
I suspect you are re-initializing Tinode object between calls or have multiple Tinode object some of which are not initialized.
For example, your first {pub} has an id=109946, while the second {pub} has no id, which means it's issued by a different Tinode object.

Dragos

unread,
Oct 8, 2021, 4:24:59 AM10/8/21
to Tinode General
I changed it a bit. I added the edit code in a nuxt plugin file and used tinode instance to get the topic by topicName passed from component. But the problem still persists.

I am leaving 4 images with the code from the component (the one with method) ,the code from the nuxt plugin file(the longer one) , the console with status of topic.isSubscribed
() and the error and the network tab with the sent {pub}
edit msg component.pngedit msg plugin.pngerror console.png
network_tab.png
Can it be reproduced  ?
The mistery is why does it sends the new {pub} but it returns an error related to using a then on an undefined.

Gene

unread,
Oct 8, 2021, 10:55:53 AM10/8/21
to Tinode General
Please directly acknowledge what I wrote in my previous message:

I suspect you are re-initializing Tinode object between calls or have multiple Tinode objects some of which are not initialized.
For example, your first {pub} has an id=109946, while the second {pub} has no id, which means it's issued by a different Tinode object.

There is no bug in the SDK. The bug is in your code.

Dragos

unread,
Oct 11, 2021, 4:02:28 AM10/11/21
to Tinode General
The first pub has an id because I use topic.createMessage before sending it with topic.publishDraft
Meanwhile when I edit I don't use topic.createMessage but make my own object with similar props exept the ID and I add the head prop. That's why there is no ID.  I could not found a way to add head prop when usin topic.createMessage.

Anyway, how could I check if I use the same tinode object ? I am sure that I use the same object. I create it inside an object and edit method is a method of that object.  Bellow this new Tinode...etc are the methods where I use tinodeInstance. So it must by the same instance. This is inside a nuxt plugin file.

tinode_object.png

Gene

unread,
Oct 11, 2021, 11:34:38 AM10/11/21
to Tinode General
On Monday, October 11, 2021 at 1:02:28 AM UTC-7 Dragos wrote:
The first pub has an id because I use topic.createMessage before sending it with topic.publishDraft

Take a look at this line:

It only returns a promise if you provide an ID.

Dragos

unread,
Oct 19, 2021, 7:18:50 AM10/19/21
to Tinode General
Finaly someone from my team found a way to send a pub with head.
We used const pkt = tinodeInstance.initPacket("pub", topicName) and on pkt.pub we set the head and sent this pkt.pub to publishMessage method. Now it works.

The SDK nor the docs specify how to send a custom pub.

Gene

unread,
Oct 19, 2021, 2:13:15 PM10/19/21
to Tinode General
You are welcome to add a section to the docs explaining how to do it.
Reply all
Reply to author
Forward
0 new messages