sending message works
This commit is contained in:
@@ -8,6 +8,9 @@ import AudioPlayer from "react-h5-audio-player";
|
|||||||
import "react-h5-audio-player/lib/styles.css";
|
import "react-h5-audio-player/lib/styles.css";
|
||||||
import CloudStorageService from "../services/cloudStorageService";
|
import CloudStorageService from "../services/cloudStorageService";
|
||||||
import PowerPlayer from "../components/PowerPlayer";
|
import PowerPlayer from "../components/PowerPlayer";
|
||||||
|
import { Message } from "../models/message";
|
||||||
|
import { useAuth } from "./authContext";
|
||||||
|
import { SendService } from "../services/sendService";
|
||||||
|
|
||||||
interface AudioContextInterface {
|
interface AudioContextInterface {
|
||||||
selectedTeammate: string; // can only have one selected
|
selectedTeammate: string; // can only have one selected
|
||||||
@@ -52,8 +55,11 @@ function stopBothVideoAndAudio(stream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const cloudStorageService = new CloudStorageService();
|
const cloudStorageService = new CloudStorageService();
|
||||||
|
const sendService = new SendService();
|
||||||
|
|
||||||
export default function AudioContextProvider({ children }) {
|
export default function AudioContextProvider({ children }) {
|
||||||
|
const { currUser } = useAuth();
|
||||||
|
|
||||||
// SECTION: set up for shortcuts and recording and such
|
// SECTION: set up for shortcuts and recording and such
|
||||||
const [selectedTeammate, setSelectedTeamMember] = useState<string>(null); // id of selected teammate
|
const [selectedTeammate, setSelectedTeamMember] = useState<string>(null); // id of selected teammate
|
||||||
const [isRecording, setIsRecording] = useState<Boolean>(false);
|
const [isRecording, setIsRecording] = useState<Boolean>(false);
|
||||||
@@ -221,11 +227,13 @@ export default function AudioContextProvider({ children }) {
|
|||||||
(event) => {
|
(event) => {
|
||||||
console.log("on key up");
|
console.log("on key up");
|
||||||
|
|
||||||
// if was recording and released R, then stop recording
|
// if was recording and released R, then stop recording and send message
|
||||||
if (event.keyCode == KeyCode.R && selectedTeammate && isRecording) {
|
if (event.keyCode == KeyCode.R && selectedTeammate && isRecording) {
|
||||||
console.log("stopped recording");
|
console.log("stopped recording");
|
||||||
setIsRecording(false);
|
setIsRecording(false);
|
||||||
|
|
||||||
|
const currReceiverUserId = selectedTeammate;
|
||||||
|
|
||||||
stopRecording()
|
stopRecording()
|
||||||
.then((file) => {
|
.then((file) => {
|
||||||
console.log(file);
|
console.log(file);
|
||||||
@@ -237,10 +245,16 @@ export default function AudioContextProvider({ children }) {
|
|||||||
console.log("file is stored: " + downloadUrl);
|
console.log("file is stored: " + downloadUrl);
|
||||||
|
|
||||||
// send message to firestore
|
// send message to firestore
|
||||||
|
const message = new Message();
|
||||||
|
message.audioDataUrl = downloadUrl;
|
||||||
|
message.senderUserId = currUser.uid;
|
||||||
|
message.receiverUserId = currReceiverUserId;
|
||||||
|
|
||||||
return;
|
return sendService.sendMessage(message);
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
toast.success("clip sent");
|
||||||
})
|
})
|
||||||
.then(() => {})
|
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
toast.error("Problem in sending clip");
|
toast.error("Problem in sending clip");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export default class CloudStorageService {
|
|||||||
/**
|
/**
|
||||||
* return the
|
* return the
|
||||||
*/
|
*/
|
||||||
async uploadMessageAudioFile(audioFile: File): Promise<string | Error> {
|
async uploadMessageAudioFile(audioFile: File): Promise<string> {
|
||||||
// Create the file metadata
|
// Create the file metadata
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
const metadata = {
|
const metadata = {
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
|
|
||||||
|
|
||||||
export enum Collections {
|
export enum Collections {
|
||||||
users = "users",
|
users = "users",
|
||||||
teams = "teams",
|
teams = "teams",
|
||||||
teamMembers = "teamMembers",
|
teamMembers = "teamMembers",
|
||||||
teamSubscriptions = "teamSubscriptions"
|
teamSubscriptions = "teamSubscriptions",
|
||||||
}
|
audioMessages = "audioMessages",
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,26 @@
|
|||||||
|
import {
|
||||||
|
addDoc,
|
||||||
|
collection,
|
||||||
|
Firestore,
|
||||||
|
getFirestore,
|
||||||
|
serverTimestamp,
|
||||||
|
} from "firebase/firestore";
|
||||||
|
import { Message } from "../models/message";
|
||||||
|
import { Collections } from "./collections";
|
||||||
|
|
||||||
export class SendService {
|
export class SendService {
|
||||||
async sendMessage() {}
|
private db: Firestore = getFirestore();
|
||||||
|
|
||||||
|
async sendMessage(message: Message) {
|
||||||
|
// do quick stuff to create the composite for easier future querying
|
||||||
|
message.senderReceiver = [message.senderUserId, message.receiverUserId];
|
||||||
|
|
||||||
|
const teamDocRef = await addDoc(
|
||||||
|
collection(this.db, Collections.audioMessages),
|
||||||
|
{
|
||||||
|
...message,
|
||||||
|
createdDate: serverTimestamp(),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user