diff --git a/dailyjs/live-streaming/.babelrc b/dailyjs/live-streaming/.babelrc deleted file mode 100644 index a6f4434..0000000 --- a/dailyjs/live-streaming/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["next/babel"], - "plugins": ["inline-react-svg"] -} diff --git a/dailyjs/live-streaming/README.md b/dailyjs/live-streaming/README.md deleted file mode 100644 index 6703492..0000000 --- a/dailyjs/live-streaming/README.md +++ /dev/null @@ -1,41 +0,0 @@ -# Text Chat - - - -### Live example - -**[See it in action here ➡️](https://dailyjs-text-chat.vercel.app)** - ---- - -## What does this demo do? - -- Use [sendAppMessage](https://docs.daily.co/reference#%EF%B8%8F-sendappmessage) to send messages -- Listen for incoming messages using the call object `app-message` event -- Extend the basic call demo with a chat provider and aside -- Show a notification bubble on chat tray button when a new message is received -- Demonstrate how to play a sound whenever a message is received - -Please note: this demo is not currently mobile optimised - -### Getting started - -``` -# set both DAILY_API_KEY and DAILY_DOMAIN -mv env.example .env.local - -yarn -yarn workspace @dailyjs/text-chat dev -``` - -## How does this example work? - -In this example we extend the [basic call demo](../basic-call) with the ability to send chat messages. - -We pass a custom tray object, a custom app object (wrapping the original in a new `ChatProvider`) as well as add our `ChatAside` panel. We also symlink both the `public` and `pages/api` folders from the basic call. - -In a real world use case you would likely want to implement serverside logic so that participants joining a call can retrieve previously sent messages. This round trip could be done inside of the Chat context. - -## Deploy your own on Vercel - -[](https://vercel.com/new/daily-co/clone-flow?repository-url=https%3A%2F%2Fgithub.com%2Fdaily-demos%2Fexamples.git&env=DAILY_DOMAIN%2CDAILY_API_KEY&envDescription=Your%20Daily%20domain%20and%20API%20key%20can%20be%20found%20on%20your%20account%20dashboard&envLink=https%3A%2F%2Fdashboard.daily.co&project-name=daily-examples&repo-name=daily-examples) diff --git a/dailyjs/live-streaming/components/App/App.js b/dailyjs/live-streaming/components/App/App.js deleted file mode 100644 index 7a9a4ce..0000000 --- a/dailyjs/live-streaming/components/App/App.js +++ /dev/null @@ -1,13 +0,0 @@ -import React from 'react'; - -import App from '@dailyjs/basic-call/components/App'; -import { ChatProvider } from '../../contexts/ChatProvider'; - -// Extend our basic call app component with the chat context -export const AppWithChat = () => ( - - - -); - -export default AppWithChat; diff --git a/dailyjs/live-streaming/components/App/index.js b/dailyjs/live-streaming/components/App/index.js deleted file mode 100644 index 770f031..0000000 --- a/dailyjs/live-streaming/components/App/index.js +++ /dev/null @@ -1 +0,0 @@ -export { AppWithChat as default } from './App'; diff --git a/dailyjs/live-streaming/components/ChatAside/ChatAside.js b/dailyjs/live-streaming/components/ChatAside/ChatAside.js deleted file mode 100644 index 2c88d3e..0000000 --- a/dailyjs/live-streaming/components/ChatAside/ChatAside.js +++ /dev/null @@ -1,132 +0,0 @@ -import React, { useEffect, useRef, useState } from 'react'; -import Aside from '@dailyjs/shared/components/Aside'; -import { Button } from '@dailyjs/shared/components/Button'; -import { TextInput } from '@dailyjs/shared/components/Input'; -import { useUIState } from '@dailyjs/shared/contexts/UIStateProvider'; -import { useChat } from '../../contexts/ChatProvider'; -import { useMessageSound } from '../../hooks/useMessageSound'; - -export const CHAT_ASIDE = 'chat'; - -export const ChatAside = () => { - const { showAside, setShowAside } = useUIState(); - const { sendMessage, chatHistory, hasNewMessages, setHasNewMessages } = - useChat(); - const [newMessage, setNewMessage] = useState(''); - const playMessageSound = useMessageSound(); - - const chatWindowRef = useRef(); - - useEffect(() => { - // Clear out any new message notifications if we're showing the chat screen - if (showAside === CHAT_ASIDE) { - setHasNewMessages(false); - } - }, [showAside, chatHistory.length, setHasNewMessages]); - - useEffect(() => { - if (hasNewMessages && showAside !== CHAT_ASIDE) { - playMessageSound(); - } - }, [playMessageSound, showAside, hasNewMessages]); - - useEffect(() => { - if (chatWindowRef.current) { - chatWindowRef.current.scrollTop = chatWindowRef.current.scrollHeight; - } - }, [chatHistory?.length]); - - if (!showAside || showAside !== CHAT_ASIDE) { - return null; - } - - return ( - - ); -}; - -export default ChatAside; diff --git a/dailyjs/live-streaming/components/ChatAside/index.js b/dailyjs/live-streaming/components/ChatAside/index.js deleted file mode 100644 index 8e15e50..0000000 --- a/dailyjs/live-streaming/components/ChatAside/index.js +++ /dev/null @@ -1 +0,0 @@ -export { ChatAside as default } from './ChatAside'; diff --git a/dailyjs/live-streaming/components/Tray/Tray.js b/dailyjs/live-streaming/components/Tray/Tray.js deleted file mode 100644 index 84290bf..0000000 --- a/dailyjs/live-streaming/components/Tray/Tray.js +++ /dev/null @@ -1,28 +0,0 @@ -import React from 'react'; - -import { TrayButton } from '@dailyjs/shared/components/Tray'; -import { useUIState } from '@dailyjs/shared/contexts/UIStateProvider'; -import { ReactComponent as IconChat } from '@dailyjs/shared/icons/chat-md.svg'; -import { useChat } from '../../contexts/ChatProvider'; -import { CHAT_ASIDE } from '../ChatAside/ChatAside'; - -export const Tray = () => { - const { toggleAside } = useUIState(); - const { hasNewMessages } = useChat(); - - return ( - <> - { - toggleAside(CHAT_ASIDE); - }} - > - - - > - ); -}; - -export default Tray; diff --git a/dailyjs/live-streaming/components/Tray/index.js b/dailyjs/live-streaming/components/Tray/index.js deleted file mode 100644 index 100bcc8..0000000 --- a/dailyjs/live-streaming/components/Tray/index.js +++ /dev/null @@ -1 +0,0 @@ -export { Tray as default } from './Tray'; diff --git a/dailyjs/live-streaming/contexts/ChatProvider.js b/dailyjs/live-streaming/contexts/ChatProvider.js deleted file mode 100644 index 6ad611a..0000000 --- a/dailyjs/live-streaming/contexts/ChatProvider.js +++ /dev/null @@ -1,90 +0,0 @@ -import React, { - createContext, - useCallback, - useContext, - useEffect, - useState, -} from 'react'; -import { useCallState } from '@dailyjs/shared/contexts/CallProvider'; -import { nanoid } from 'nanoid'; -import PropTypes from 'prop-types'; - -export const ChatContext = createContext(); - -export const ChatProvider = ({ children }) => { - const { callObject } = useCallState(); - const [chatHistory, setChatHistory] = useState([]); - const [hasNewMessages, setHasNewMessages] = useState(false); - - const handleNewMessage = useCallback( - (e) => { - const participants = callObject.participants(); - const sender = participants[e.fromId].user_name - ? participants[e.fromId].user_name - : 'Guest'; - - setChatHistory((oldState) => [ - ...oldState, - { sender, message: e.data.message, id: nanoid() }, - ]); - - setHasNewMessages(true); - }, - [callObject] - ); - - const sendMessage = useCallback( - (message) => { - if (!callObject) { - return false; - } - - console.log('💬 Sending app message'); - - callObject.sendAppMessage({ message }, '*'); - - // Get the sender (local participant) name - const sender = callObject.participants().local.user_name - ? callObject.participants().local.user_name - : 'Guest'; - - // Update local chat history - return setChatHistory((oldState) => [ - ...oldState, - { sender, message, id: nanoid(), isLocal: true }, - ]); - }, - [callObject] - ); - - useEffect(() => { - if (!callObject) { - return false; - } - - console.log(`💬 Chat provider listening for app messages`); - - callObject.on('app-message', handleNewMessage); - - return () => callObject.off('app-message', handleNewMessage); - }, [callObject, handleNewMessage]); - - return ( - - {children} - - ); -}; - -ChatProvider.propTypes = { - children: PropTypes.node, -}; - -export const useChat = () => useContext(ChatContext); diff --git a/dailyjs/live-streaming/hooks/useMessageSound.js b/dailyjs/live-streaming/hooks/useMessageSound.js deleted file mode 100644 index e894a1c..0000000 --- a/dailyjs/live-streaming/hooks/useMessageSound.js +++ /dev/null @@ -1,19 +0,0 @@ -import { useEffect, useMemo } from 'react'; - -import { useSound } from '@dailyjs/shared/hooks/useSound'; -import { debounce } from 'debounce'; - -/** - * Convenience hook to play `join.mp3` when participants join the call - */ -export const useMessageSound = () => { - const { load, play } = useSound('message.mp3'); - - useEffect(() => { - load(); - }, [load]); - - return useMemo(() => debounce(() => play(), 5000, true), [play]); -}; - -export default useMessageSound; diff --git a/dailyjs/live-streaming/image.png b/dailyjs/live-streaming/image.png deleted file mode 100644 index cca9672..0000000 Binary files a/dailyjs/live-streaming/image.png and /dev/null differ diff --git a/dailyjs/live-streaming/next.config.js b/dailyjs/live-streaming/next.config.js deleted file mode 100644 index 9a0a6ee..0000000 --- a/dailyjs/live-streaming/next.config.js +++ /dev/null @@ -1,13 +0,0 @@ -const withPlugins = require('next-compose-plugins'); -const withTM = require('next-transpile-modules')([ - '@dailyjs/shared', - '@dailyjs/basic-call', -]); - -const packageJson = require('./package.json'); - -module.exports = withPlugins([withTM], { - env: { - PROJECT_TITLE: packageJson.description, - }, -}); diff --git a/dailyjs/live-streaming/package.json b/dailyjs/live-streaming/package.json deleted file mode 100644 index c340eb5..0000000 --- a/dailyjs/live-streaming/package.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "@dailyjs/live-streaming", - "description": "Basic Call + Live Streaming", - "version": "0.1.0", - "private": true, - "scripts": { - "dev": "next dev", - "build": "next build", - "start": "next start" - }, - "dependencies": { - "@dailyjs/shared": "*", - "@dailyjs/basic-call": "*", - "next": "^11.0.0", - "pluralize": "^8.0.0", - "react": "^17.0.2", - "react-dom": "^17.0.2" - }, - "devDependencies": { - "babel-plugin-module-resolver": "^4.1.0", - "next-compose-plugins": "^2.2.1", - "next-transpile-modules": "^8.0.0" - } -} diff --git a/dailyjs/live-streaming/pages/_app.js b/dailyjs/live-streaming/pages/_app.js deleted file mode 100644 index ad38f4e..0000000 --- a/dailyjs/live-streaming/pages/_app.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import App from '@dailyjs/basic-call/pages/_app'; -import AppWithChat from '../components/App'; - -import ChatAside from '../components/ChatAside'; -import Tray from '../components/Tray'; - -App.asides = [ChatAside]; -App.customAppComponent = ; -App.customTrayComponent = ; - -export default App; diff --git a/dailyjs/live-streaming/pages/api b/dailyjs/live-streaming/pages/api deleted file mode 120000 index 999f604..0000000 --- a/dailyjs/live-streaming/pages/api +++ /dev/null @@ -1 +0,0 @@ -../../basic-call/pages/api \ No newline at end of file diff --git a/dailyjs/live-streaming/pages/index.js b/dailyjs/live-streaming/pages/index.js deleted file mode 100644 index 5f31f95..0000000 --- a/dailyjs/live-streaming/pages/index.js +++ /dev/null @@ -1,17 +0,0 @@ -import Index from '@dailyjs/basic-call/pages'; - -export async function getStaticProps() { - // Check that both domain and key env vars are set - const isConfigured = - !!process.env.DAILY_DOMAIN && !!process.env.DAILY_API_KEY; - - // Pass through domain as prop - return { - props: { - domain: process.env.DAILY_DOMAIN || null, - isConfigured, - }, - }; -} - -export default Index; diff --git a/dailyjs/live-streaming/public b/dailyjs/live-streaming/public deleted file mode 120000 index 33a6e67..0000000 --- a/dailyjs/live-streaming/public +++ /dev/null @@ -1 +0,0 @@ -../basic-call/public \ No newline at end of file