I have developed screen casting app. I am making connection using twilio but I want to share touch events from receiver(participant) to sender(host) as a live data. Is there any possible solution to simplify this?
If you are using Twilio Video for this connection then you can use the DataTrack API to send arbitrary data over your connection.
You can create a LocalDataTrack object:
const { LocalDataTrack } = require(`twilio-video`);
const dataTrack = new LocalDataTrack();
Connect it to a room, either by sending it as part of the tracks option when connecting, or by publishing it to the room after a connection has been made.
const { connect } = require('twilio-video');
const room = await connect('$TOKEN', {
name: 'my-chat-room',
tracks: [dataTrack]
});
You can send a message down the data track once it is published:
dataTrack.send(message)
And you can receive data track messages by subscribing to the track and listening for the message event:
participant.on('trackSubscribed', track => {
console.log(`Participant "${participant.identity}" added ${track.kind} Track ${track.sid}`);
if (track.kind === 'data') {
track.on('message', data => {
console.log(data);
});
}
});
See the documentation for more detail.
Related
I am making a chat feature in the android app using Conversations SDK. The reachability is enabled from the backend side. I try to get live updates of the online/offline status of all the users. But the flow doesn't come in onUserUpdated() method of ConversationsClientListener. Below is the code I have implemented to get the live status updates.
fun getUserStatus(): Flow<User> = callbackFlow {
val client = instantMessageRepository.getConversationsClient()
val listener = createClientListener (
onUserUpdated = { user, updateReason ->
user.let { trySend(it).isSuccess }
}
)
client.addListener(listener)
awaitClose { client.removeListener(listener) }
}
And I am getting it as live data as follows:
val userStatus = chatService.getUserStatus()
.asLiveData(viewModelScope.coroutineContext)
And listening it in my activity as follows:
mViewModel.userStatus.observe(viewLifecycleOwner) {
Log.d(TAG, "onViewCreated: ${it.isOnline}")
}
Is this the right way to get live user status updates online/offline? Or do I need some corrections or change the way I'm trying to implement it?
I use react native gifted chat, and I want that when a user fails to send a chat to the server then the icon in the bubble changes?
Maybe if a user fails to send a message, an icon like this will appear:
Thank you, please help
I know it was a long time ago, but maybe it can help someone. If you are using Hooks and your messages array is defined like this const [messages, setMessages] = useState();
So, when tap on Send, you can add a new message to your state. Important to add pending and sent properties like
yourMessage.pending = true;
yourMessage.sent = false;
So, when you have the backend response, you can update
yourMessage.pending = false;
yourMessage.sent = true;
Finally, update the message state
setMessages(previousMessages => {
const index = previousMessages.findIndex(aMessage => aMessage._id == yourMessage._id);
const newArr = [...previousMessages];
newArr[foundIndex] = yourMessage;
return newArr;
});
I am working on Firebase FireStore and Firebase real time database apps,
how can I set an alarm (based on a value set by the user) on android using firebase cloud functions?
There is currently no one-time scheduling functionality in Cloud Functions. You will have to provide your own scheduling mechanism, and that could trigger an HTTP function that deals with Firestore or Realtime Database.
You can use Javacript native function in Firebasefunctions -
setTimeOut()
setInterval()
for triggering some events .
Working for me.My use case is to trigger some API after each 5mins.
Sample Code -
exports.process_sms = functions.https.onRequest((req, res) => {
admin.database().ref(FIREBASE_DB + '/sms_new').once('value').then(function(users) {
let sms_array = [];
users.forEach(function(user) {
user.forEach(function(sms) {
if (sms.val().status == 0) {
sms_array.push(sms);
}
});
});
let i = 0;
let interval = setInterval(function() {
// do your work ... and it gets repeated after 2 sec
}, 2000);
res.status(200).send("Sms processing Done");
});
});
How do I do this? I used the code below but it is not working. I still receive notification when I update my Database
exports.sendNewPostNotif = functions.database.ref('/News/{ID}').onWrite(event => {
const announce_data = event.data.val();
const announce_data_type = announce_data.categ_post;
const announce_data_title = announce_data.title_post;
const announce_data_uid = announce_data.uid; id
const announce_post_key = announce_data.postkey;
if(!event.data.val()) {
return console.log('No data');
}
if(event.data.previous.exist()) {
return;
}
Whenever I send a new content, it'll go through the onWrite event then send the notification. Mmy current issue is whenever I edit the post, it'll send a notification which I do not require. I tried the above and it works as I receive no notification when I update the news content BUT I don't receive a notification when I create a new content.
If you only want your function to run when the node is created, and not when it is updated or deleted, you can use the onCreate trigger:
exports.sendNewPostNotif = functions.database.ref('/News/{ID}').onCreate(event => {
See the Firebase documentation on database trigger types and the blog post where these are introduced.
I want to send a push notification from server to an ionic client and show this notification in client like a phone call (mobile device should play a sound and show 'Accept' or 'Reject' buttons with caller information). It should work if mobile app is not running or in background, that's why I decided to use FCM messages.
this.storage.get('firebase_token').then((token) => {
console.log('Orders get firebase token and call register. Token: ' + token);
this.agentService.registerPushNotifications(token, () => {
this.firebase.onNotificationOpen().subscribe((notification) => {
// How to open the app and show the page with a ringtone ??
});
});
});
How can I open the app and show the call page with a ringtone in incoming push notification? Or maybe there is a better way for this kind of feature.
What you are asking for (the same format like a phone call) isn't possible with Ionic. You can however redirect the user to a view inside the application where you ask him to take action.
Take the following example for push notification. In app.components.ts I initialize this function when the platform is ready
initializePushNotifications() {
let pushObject = this.push.init({
android: {
senderID: 'Your ID Here',
icon: 'logo'
},
ios: {
alert: true,
badge: false,
sound: true
},
windows: {}
});
if (!pushObject['error']) {
pushObject.on('registration').subscribe((data: RegistrationEventResponse) => {
// Whatever you want to do
}, err => {
console.log('Couldnt register:', err);
})
pushObject.on('notification').subscribe((data: any) => {
let self = this;
// When the user click the push notification
if (!data.additionalData.foreground) {
switch (data.additionalData.entity_type) {
case 'takeAction':
this.openView(data.additionalData.user_name, data.additionalData.id);
break;
......
}
}
});
pushObject.on('error').subscribe((e: any) => {
console.log(e.message);
});
} else {
console.error(pushObject);
}
}
See, in the pushed message we add an object under the key additionalData where you can pass whatever you want. You can pass something like entity_type with the value takeAction. When the user click it, you can open a new view and pass additional parameters like the name of the user and the id of the entity or whatever.
On this screen you can open an alert asking the user to click yes or no and based on his input you fire the correct request.
Note
I know this is different from what you were asking for but your request cannot be fulfilled using Ionic.