stream-chat-react
Version:
React components to create chat conversations or livestream style chat
30 lines (29 loc) • 1.26 kB
JavaScript
export const SUPPORTED_VIDEO_FORMATS = [
'video/mp4',
'video/ogg',
'video/webm',
'video/quicktime',
];
// This identity function determines attachment type specific to React.
// Once made sure other SDKs support the same logic, move to stream-chat-js
export const isGalleryAttachmentType = (attachment) => Array.isArray(attachment.images);
export const isSvgAttachment = (attachment) => {
const filename = attachment.fallback || '';
return filename.toLowerCase().endsWith('.svg');
};
export const divMod = (num, divisor) => [
Math.floor(num / divisor),
num % divisor,
];
export const displayDuration = (totalSeconds) => {
if (!totalSeconds || totalSeconds < 0)
return '00:00';
const [hours, hoursLeftover] = divMod(totalSeconds, 3600);
const [minutes, seconds] = divMod(hoursLeftover, 60);
const roundedSeconds = Math.ceil(seconds);
const prependHrsZero = hours.toString().length === 1 ? '0' : '';
const prependMinZero = minutes.toString().length === 1 ? '0' : '';
const prependSecZero = roundedSeconds.toString().length === 1 ? '0' : '';
const minSec = `${prependMinZero}${minutes}:${prependSecZero}${roundedSeconds}`;
return hours ? `${prependHrsZero}${hours}:` + minSec : minSec;
};