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
asked 7 months ago297 views
3 Answers
0
Accepted Answer

I added .onopen event, then it worked.

profile picture
N Wang
answered 7 months ago
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
answered 7 months ago
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
answered 7 months ago
  • The status shows "finished" not 200 or 400 with an empty response. I'll post my code in another comment.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions