ivs chat websocket connect failed.

0

I followed the instructions to create a chatroom and token, and used the sample code to connect to the chatroom using WebSocket, but I got a connection error.

my lab is hosting a sample file ivs-chatroom.html on my ec2 server. And tried to connect to wss://edge.ivschat.ap-northeast-1.amazonaws.com failed.

profile picture
N Wang
已提问 8 个月前310 查看次数
3 回答
0
已接受的回答

I added .onopen event, then it worked.

profile picture
N Wang
已回答 7 个月前
0

Updated code part. ps. the chatClientToken has expired. when I start testing i always use the latest token.

const chatClientToken = "AQICAHgDPFqoWS2jdOfTGB1Vo7NQnk0RhxoHKwei87S3M72_WgGXpV-mDgAwwUJ2UdCY15ZUAAAB0TCCAc0GCSqGSIb3DQEHBqCCAb4wggG6AgEAMIIBswYJKoZIhvcNAQcBMB4GCWCGSAFlAwQBLjARBAyJQR2ruBPj-WXSeyACARCAggGE1gSj19XcIQPV30V8wF15YmAk7Rac086esruMblXDKabrTC2UdanFCksa4aE62SeppjmhKleGNSvXUH0IajebRu4FvsflOgldfAEto8Kmum_--y7JnM0pRiefk03tXpFI9mXGhQ0AY8sbsw1gZIeg4xttXq7umQKEYef3bpsD-nC_pEcFyFPz6ilkNPVjZNaPRK_jBikhvyVImCh7x1PT3LGa8j8xhKtzGZdY1LzNgnbS9x8Q7rNmeekhkZtOaI04sMsxVIHRJlT9fGvdpkeompQo_IbUU_-Kf4YhIEROSnRSH1qSzOztUmjD33K18L5xmFnorgYCM_CsNydLMuxv8s2ygFJeOiJ-_J358y1Qmr6AdMZT-xI7lBhVftubxQ-LAwL3Hs-NPqIlq079MbH4xw1YmH8yJ56V28AKl0NfVavMWMhfwRepr2BiSUd6gQyE6rB2Y2MbQp3c4C-gMvlMAwPYMBesbTb9kCQQP-Qz2Qz5L4ZsLgJZ04kvlSVXqezFxOoNDQ!!#0";
const socket = "wss://edge.ivschat.ap-northeast-1.amazonaws.com"; // Replace “us-west-2” with supported region of choice.
const connection = new WebSocket(socket, chatClientToken);

/*
2. You can send your first message by listening to user input 
in the UI and sending messages to the WebSocket connection.
*/
const payload = {
  "Action": "SEND_MESSAGE",
  "Content": "text message",
  "Attributes": {
    "CustomMetadata": "test metadata"
  }
}
connection.send(JSON.stringify(payload));

browser console log browser console network log with header

profile picture
N Wang
已回答 7 个月前
0

It is possible that the chat token you are using to connect to the chat room has expired. Can you provide more information about the error? What HTTP status code is returned? Here is a list of the possible errors you may receive. You might want to also decode the token using https://jwt.io to verify that it looks good and is not expired.

profile picture
已回答 8 个月前
  • The status shows "finished" not 200 or 400 with an empty response. I'll post my code in another comment.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容