RealTime API OnInput

Hi everyone !!!
First of all “sorry Yisrael…will not try to do like that from now on…” :grinning:

So, In my previous post I was answered by Yisrael how to use RealTime Api after afterInsert Hook…
Why I created this post was to know if I can use the above function in the onInput event function…

Very Thanks !!!
PARDON ME YISRAEL !!!

No problem !!!
I have found the code →

1st create a .jsw backend file called realtime.jsw →

//realtime.jsw

import { publish } from 'wix-realtime-backend';

export function publishMessage(userId) {
 const channel =  { name: 'type' };
 const payload = {userId};
 return publish(channel, payload);
}

In the page →

import { publishMessage } from 'backend/realtime';
import * as realtime from 'wix-realtime';

export function input1_input(event) {  //when the user types something in the input
 return publishMessage()
}

async function type({ payload }) {
 if ($w('#notificationBox2').hidden) {
                $w('#notificationText2').text = JSON.stringify(fullName) + " has posted";
               
                $w('#notificationBox2').show('fade');
                setTimeout(() => $w('#notificationBox2').hide('fade'), 3000);
            } else {
                setTimeout(() => type({ payload }), 1000);
            }
       

}

For reference
Thanks Yisrael !!!

For more info → https://www.wix.com/corvid/forum/tips-tutorials-examples/real-time-api