50
loading...
This website collects cookies to deliver better user experience
photoUrl
of each user to an actual image address. You can find free images here to act as the profile pictures of your users. const inbox = session.createInbox({selected: conversation});
inbox.mount(document.getElementById("talkjs-container"));
var chatbox = session.createChatbox(conversation);
chatbox.mount(document.getElementById("talkjs-container"));
var chatbox = session.createChatbox(conversation);
var chatbox = session.createChatbox(conversation, {showChatHeader: false});
talkjs-container
div into the structure shown below. As you can see we have a div for our entire chatbox, and a separate div for our header. We also have a div called button-container
where we’ll add our video call button.<!-- Container element for all TalkJS UI elements -->
<div class="chatbox-container">
<!-- Custom TalkJS chat header -->
<div id="chatbox-header">
<div id="header-bg"></div>
<div id="user-avatar"></div>
<p id="header-subject"><span id="header-username"> Username</span></p>
<div class="button-container">
<div class="call-button">
<!--input type="checkbox" name="notificationToggle" class="toggle-checkbox" id="toggle"-->
<input type="image" name="videoCallButton" id="videocall" src="https://img.icons8.com/material-sharp/24/ffffff/video-call--v1.png"/>
</div>
</div>
</div>
<!-- container element in which TalkJS will display a chat UI -->
<div id="talkjs-container" style="width: 100%; height: 500px"><i>Loading chat...</i></div>
</div>
// Add the participant user's name and photo to the custom header
var headerUsername = document.getElementById('header-username');
headerUsername.textContent = other.name;
document.getElementById('user-avatar').style.backgroundImage = "url(" + other.photoUrl + ")";
chatbox-container
are centered horizontally and scale their width similar to how the default Chatbox.<style>
/* Container for everything TalkJS*/
.chatbox-container {
width: 420px;
max-width: 100%;
margin: auto;
}
/* Custom header for the chatbox*/
#chatbox-header {
height: 110px;
position: relative;
background-color: #000;
display: flex;
flex-direction: row;
justify-content: flex-start;
/* Slightly curve the top of the header */
border-radius: 10px 10px 0 0;
margin-bottom: -3px;
padding: 10px;
position: relative;
}
#header-bg {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
border-radius: inherit;
opacity: 0.6;
}
#user-avatar {
position: absolute;
height: 50px;
width: 50px;
background-size: cover;
background-repeat: no-repeat;
background-position: center;
border-radius: 50%;
border: 2px solid #eee;
}
#chatbox-header p {
font-family: "Helvetica", sans-serif;
color: #eee;
margin: 0;
}
#header-subject {
position: absolute;
font-size: 32px;
left: 70px;
top: 7px;
}
/* Notification toggle */
.button-container {
text-align: right;
position: absolute;
bottom: 15px;
right: 10px;
}
.button-container p {
display: inline;
font-size: 10px;
padding-right: 10px;
vertical-align: middle;
}
.call-button {
vertical-align: middle;
display: inline-block;
position: relative;
width: 51px;
-webkit-user-select:none;
-moz-user-select:none;
-ms-user-select: none;
user-select: none;
height: 18px;
}
</style>
<script crossorigin src="https://unpkg.com/@daily-co/daily-js"></script>
```
var callButton = document.getElementById('videocall');
callButton.addEventListener('click', function() {
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
showFullscreenButton: true,
});
callFrame.join({ url: 'https://talkjstest.daily.co/{your-video-call-room-id}' })
});
```
showLeaveButton
and showFullscreenButton
. Check out this guide for more information on what you can do with the premade Daily UI.button-container
div to the following:<div class="button-container">
<div class="call-button">
<input type="image" name="videoCallButton" id="videocall" src="https://img.icons8.com/material-sharp/24/ffffff/video-call--v1.png"/>
</div>
<div class="call-button">
<input type="image" name="audioCallButton" id="audiocall" src="https://img.icons8.com/material-rounded/24/ffffff/phone-disconnected.png"/>
</div>
</div>
var callButton = document.getElementById('videocall');
var audioCallButton = document.getElementById('audiocall');
var callFrame;
callButton.addEventListener('click', function() {
if(callFrame != null){
callFrame.destroy();
}
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
showFullscreenButton: true,
});
callFrame.join({ url: 'https://talkjstest.daily.co/{your-video-call-room-id}' })
});
//audio button listener
audioCallButton.addEventListener('click', function() {
if(callFrame != null)
{
callFrame.destroy();
}
callFrame = window.DailyIframe.createFrame({
showLeaveButton: true,
showFullscreenButton: true,
});
callFrame.join({ url: 'https://talkjstest.daily.co/{your-audio-call-room-id}' })
});
callFrame
Chat frame each time the button is pressed, and proceed to load the new audio or video UI depending on what button was clicked. This will ensure only one frame is displayed at any one time.