tinode / chat

Instant messaging platform. Backend in Go. Clients: Swift iOS, Java Android, JS webapp, scriptable command line; chatbots
GNU General Public License v3.0
11.94k stars 1.87k forks source link

409 js #109

Closed xingguangkuo closed 6 years ago

xingguangkuo commented 6 years ago

When I used a one to one chat, there were the following mistakes based on the subscription Topic.

my code: Tinode.Tinode.publish("usrGq2qpQ0u9ws","1122",undefined,"text/plain") .then(function(ctrl) { console.info(ctrl); }); }).catch(function(err) { // Login or subscription failed, do something. console.info(err); }); error log: tinode.js?723e:873 Uncaught (in promise) Error: Error: must attach first (409) at execPromise (tinode.js?723e:873) at Object.dispatchMessage [as onMessage] (tinode.js?723e:1066) at WebSocket.conn.onmessage (tinode.js?723e:532)

how to solve the problem? thank you

or-else commented 6 years ago

You have to attach first. For instance, see here: https://github.com/tinode/example-react-js/blob/master/index.html#L4294

xingguangkuo commented 6 years ago
      var t111 =Tinode.Tinode.getTopic("usrctNBS3OGhFE");
      var query = t111.startMetaQuery().withDesc().withSub().withData();
      var pub = {"fn":"bob"};                   //对方用户名
      var priv = ["email:bob@example.com"]; //对方用户邮箱
      t111.subscribe(query.build(), {desc: {public: pub, private: priv}});
      t111.publish(textMsg, undefined, "text/plain").then(function (ctrl) {
        console.info(ctrl);
      });

      I added subscriptions, but sometimes I occasionally had 409.
or-else commented 6 years ago

All commands are asynchronous. You may wish to wait for the completion of subscribe before issuing publish, e.g. subscribe(...).then(...)