Skip to content

Commit

Permalink
feat: Added video message support (#259)
Browse files Browse the repository at this point in the history
### Changelog
- Supports video typed file messages when sent by bot user

### Side note
- [Video message takes up 'wide
view'.](https://sendbird.slack.com/archives/C0585965FFA/p1717486126855269?thread_ts=1717397963.921489&cid=C0585965FFA)

### Ticket
https://sendbird.atlassian.net/browse/AC-2197

### After

[Video and Audio APIs - Learn web development _
MDN.webm](https://github.com/sendbird/chat-ai-widget/assets/16806397/843c2e49-6496-43df-9979-7bb1eebe41fc)

[Video and Audio APIs - Learn web development _ MDN
(1).webm](https://github.com/sendbird/chat-ai-widget/assets/16806397/22602105-18b2-47ee-be90-72c0dce2f8b8)


Note: The testing is when message is sent by me not bot. It is only for
testing. In production, only bot message is supported.
  • Loading branch information
liamcho authored Jun 5, 2024
1 parent 1e142d5 commit 489d4d3
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 12 deletions.
1 change: 0 additions & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ar } from 'date-fns/locale';
import React from 'react';

import { StringSet } from '@uikit/ui/Label/stringSet';
Expand Down
2 changes: 1 addition & 1 deletion src/components/ChatAiWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const MobileComponent = () => {
return (
<>
<MobileContainer
style={{ display: (isOpen && isVisible) ? 'block' : 'none' }}
style={{ display: isOpen && isVisible ? 'block' : 'none' }}
width={mobileContainerWidth}
id={elementIds.widgetWindow}
>
Expand Down
3 changes: 2 additions & 1 deletion src/components/CustomMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { User } from '@sendbird/chat';

import TypingDots from '@uikit/ui/TypingIndicatorBubble/TypingDots';
import { CoreMessageType } from '@uikit/utils';
import { CoreMessageType, isVideoMessage } from '@uikit/utils';

import AdminMessage from './AdminMessage';
import BotMessageFeedback from './BotMessageFeedback';
Expand Down Expand Up @@ -136,6 +136,7 @@ export default function CustomMessage(props: Props) {
if (message.isFileMessage()) {
return (
<BotMessageWithBodyInput
wideContainer={isVideoMessage(message)}
{...commonProps}
botUser={botUser}
bodyComponent={<FileMessage message={message} />}
Expand Down
29 changes: 21 additions & 8 deletions src/components/FileMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '../css/index.css';
import { FileMessage as ChatFileMessage } from '@sendbird/chat/message';

import { useGroupChannelContext } from '@uikit/modules/GroupChannel/context/GroupChannelProvider';
import { isImageMessage, isVideoMessage } from '@uikit/utils';
// import { FileViewerComponent } from '@sendbird/uikit-react/ui/FileViewer';
// import {downloadFileWithUrl, noop} from '../utils';
// import {createPortal} from 'react-dom';
Expand All @@ -16,6 +17,10 @@ export default function FileMessage(props: Props) {

// const root = document.getElementById('aichatbot-widget-window');

/**
* Currently only video and image file messages will be sent.
* TODO: In the future, we may support other file types. When we do, we need to update the logic.
*/
return (
<div className="sendbird-ai-widget-file-message-root">
{/*Please keep the commented code for referencing in the future when adding file viewer*/}
Expand All @@ -38,14 +43,22 @@ export default function FileMessage(props: Props) {
root!
)}
*/}
<img
className="sendbird-ai-widget-file-message-image"
src={message.url}
alt={''}
onLoad={() => {
scrollToBottom();
}}
/>
{isVideoMessage(message) && (
<video controls className="sendbird-ai-widget-file-message">
<source src={message.url} type={message.type} />
<track kind="captions" />
</video>
)}
{isImageMessage(message) && (
<img
className="sendbird-ai-widget-file-message"
src={message.url}
alt={''}
onLoad={() => {
scrollToBottom();
}}
/>
)}
</div>
);
}
2 changes: 1 addition & 1 deletion src/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ input:focus {
width: 100%;
}

.sendbird-ai-widget-file-message-image {
.sendbird-ai-widget-file-message {
border-radius: 16px;
width: 100%;
}
Expand Down

0 comments on commit 489d4d3

Please sign in to comment.