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.

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南