In this post, we're going to level up the interactivity and add live chat alongside our live stream viewer. - by elementaltech amazonivs chatinamazonivslivestream
To retrieve a chat token from the CLI, you can use the following command. But hold off on generating that for now until we need it below, because the token will expire pretty quickly. To clarify - the token itself is used to authorize a chat user and establish a session. The default timeout for the session established via the token is 60 minutes, at which point a new session will need to be established .
$ aws \ ivschat \ create-chat-token \ --room-identifier "[YOUR CHAT ROOM ARN]" \ --user-id "[A UNIQUE ID FOR THIS USER]" \ --capabilities "SEND_MESSAGE"Now that we have a chat room, let's build out a demo to see it in action. As I mentioned above, since the chat room requires a chat token, we'll create a form to capture the token and the messaging endpoint.You can generate your own token to plug in to this form via the console or the CLI methods shown above.
import AWS from 'aws-sdk'; const credentials=new AWS.Credentials; const IvsChat=new AWS.Ivschat; const createToken=async { let token; const params={ roomIdentifier: "[YOUR CHAT ARN]", userId: "[UNIQUE USERID]", attributes: {}, capabilities: ['SEND_MESSAGE'], sessionDurationInMinutes: 60, }; try { const data=await IvsChat.createChatToken.promise; token=data.token; } catch { console.
Next, add some markup to display the chat messages, a text input to enter a new message, and a send button.We'll listen for the form submission, and when that happens we can initialize the chat room WebSocket connection. const endpoint=document.getElementById.value; const token=document.getElementById.value; window.chatConnection=new WebSocket;onmessagewindow.chatConnection.onmessage==> { // parse the event data const data=JSON.parse; // append the incoming msg to the chat const msgHtml=`${data.Attributes.username}: ${data.Content}`; const chatContainer=document.getElementById; chatContainer.innerHTML +=msgHtml; chatContainer.scrollTop=chatContainer.scrollHeight; };chatConnectiondocument.getElementById.
Australia Latest News, Australia Headlines
Similar News:You can also read news stories similar to this one that we have collected from other news sources.
Wolfson Children’s Hospital recognized as Level 1 Pediatric Trauma CenterThe Porter Family Children’s Trauma Center at Wolfson Children’s Hospital on Friday was verified by the American College of Surgeons as a level-one pediatric trauma center, making it one of only a few dozen in the country with such a designation.
Read more »
S\u0026P 500 Forecast: Pulls Back from Crucial 3900 LevelThe S\u0026P 500 E-mini contract pulled back from the crucial 3900 level during the trading session on Tuesday.
Read more »
Threat Level Imagines a World in Which Rivalries Begin and End on the FieldMichigan and Michigan State played a rivalry game on Saturday, which devolved into ugliness afterward.
Read more »
RSV vaccine may be close as Chicago pediatric hospitalizations reach highest level in yearsPfizer says its RSV vaccine is safe for pregnant women and effective in helping protect their babies as the virus hits Chicago hard.
Read more »
Stanford study on whales, microplastics reveals concerning level of food chain contaminationWhales migrate past our Bay Area coastline. But now a team from Stanford's Hopkins Marine Station is raising concern about a possible threat to their food chain from microplastics
Read more »
Cadillac Lyriq Customers Will Get A Free Level 2 Home Charger In Canada | CarscoopsCadillac Canada is offering the option between a free L2 home charger or a $750 credit at public chargers
Read more »