So I was trying to implement one-to-one messaging in NextJS with Ably but I couldn't get it done.
I'm stuck between making channels for interactions (e.g. private:<user_1>-<user_2>) and channels for users (e.g. private:<user_1>).
In the second implementation I would need to subscribe only <user_1> to their channel but allow other users to publish to private:<user_1>.
Summary: What would be the best way to use Ably Realtime in NextJS to implement one-to-one messaging
const {data: session, status} = useSession()
let inputBox = null;
let messageEnd = null;
const [time, setTime] = useState("")
const [messageText, setMessageText] = useState("");
const [receivedMessages, setMessages] = useState([]);
const messageTextIsEmpty = messageText.trim().length === 0;
useEffect(()=>{
console.log(session);
}, [session])
if(status === "authenticated"){
console.log(session.id);
const [channel, ably] = useChannel(`chat:${session.id}`, (message) =>{
console.log(message);
})
}
I tried this but quickly realized that the rules of React Hooks make it impossible
Apologies, it is my first time posting to Stack Overflow