Google play services simple chat implementation? - android

I am looking to create an extremely simple chat feature for my app.
I just want to be able to send a message to the opponent in my Turn-Based Multiplayer match.
I don't want to use libraries like Scringo and what have you. Is there any way to implement this?
I've tried to use Games.RealtimeMultiplayer.sendReliableMessage() but my players aren't in a room so it does not work.

In looking through the API, it appears that the only way to send out data is to call takeTurn
To take a turn, use this method:
Method Description
takeTurn()
Your game should only invoke this method when it is the user's turn in an active turn-based match. After invoking this method, the user sees this match under the Their Turn list in the match list UI.
If a participant ID is specified in the method call, that participant becomes the current player and can play a turn. The first time this happens to an invited player, the player receives an invitation notification. Subsequently, the player receives a turn notification.
If no pending participant ID is specified, the match state changes to MATCH_STATUS_AUTO_MATCHING. Your game can only leave the participant ID unspecified if there are player slots that are still vacant for auto-matching.
Your game can call takeTurn() with the current player as the pending participant. In this case, Play Games services uploads the the game data but no notification is sent.
There are no other calls that change the data that is held in the servers and passed to the other player(s).
Now, having said that, it IS possible to send out a chat for the player that currently owns the Turn. It would appear that there are two ways to do that, either include the Chat and set the Pending Participant to the Next Participant... or update only the Chat portion, and then call takeTurn with the Pending Participant set to the currently active Participant. Looking at the documentation, this would then update the Data held on Google's servers, BUT, would not necessarily send out any notification that it had updated, as it appears that Notifications are only sent out if it is actually to notify a Player that it is their turn. (if you envision your app as being open while the Player waited for others to complete, then it could poll for the data using getData(), as there is no requirement that I can see for it to be a Player's turn to request the Data().
This would allow a player to Chat, but not Real Time like you mention... as the API is strictly turn based.

Related

Broadcasting Android application using Opentok SDK

Im working on an android application where multiple user subscribe to my stream published from android device. What i want to pull off is, when i click the video of a certain subscriber, all the subscriber(user) will then subscribe to his/her stream rather than mine.
if there is any article or code to suggest me, please do so.
I don't have a sample to point to but I can tell you how I would solve this.
You will need to communicate to everyone in the Session which stream to subscribe to. You can use the signal API in opentok to do this by passing a streamId along. Then when each participant receives that signal they can lookup the corresponding stream and subscribe to it. You will need to make sure that every time a new person joins you also send them a signal saying which stream to subscribe to. You can do this by listening for the connectionCreated event.
If only one participant is allowed to tell everyone who to subscribe to then you might want to have a look at the connection data property of tokens. Then you can add eg. 'admin' as the connection data and then when you receive the signals make sure that they are coming from someone that has 'admin' as their connection data.

How would android apps notify users even though the app is not opened yet?

I've thinking this for a while that how do android app really notify its users?
Like Messenger, Messenger usually notify a user by making a floating circular profile picture of the sender.
and like other games like Subway Surfers or Zombie Catchers,
in the case of subway Surfers and other apps it notify users, when they are updated or an event is going on,
but in the case of Zombie Catchers, it notifies the users when their slushies are ready to be sold. Or the drones found new zombies at the alloted time.
So my concern is that, how can i notify my users when they have a unread messages or there is an event coming? without using Firebase?
If you are not using Firebase then I guess you must be using SQLite in android. If you are using SQLite then in order to notify its users you must add a TRIGGER on the table so that whenever some value is inserted or updated you can create a Notification Builder or any sort of notification like a TOAST.
E.g:
A user wants to know unread messages, there would be a table consisting of the number of message that are not opened. Whenever the app is opened it checks whether there are any unread messages and if there are/is, you can notify the user.
Link on how to use Trigger in SQLite.
How to use TRIGGER in Android SQLite
Link to notification builder.
https://developer.android.com/reference/android/app/Notification.Builder.html
However if you want the notification to appear when your App is closed, then you must also add a Sticky Service in the manifest file which would check the database after some interval and you should be good.
But I would recommend using Firebase since it has Value event listener and child event listeners making your task much easier.

Telephone with OpenTok

We are developing a VoIP app and we want to switch to the Tokbox library.
Ours is like a telephone app just like Viber but for a specific audience. We need the app to behave like a telephone app. The user makes the call, the receiver hears the phone ringing, picks up the call and hangs it up when done talking. I could find a lot of resources on Tokbox online (for Android and iOS) but I couldn't find much info on a telephone with the library. Can anyone point me to the right direction or explain things a little bit.
Thanks in advance.
To implement a mobile telephony app (like Viber) where user A calls user B you need a couple of extra pieces in addition to TokBox platform.
First you need to make use of standard Apple&Google push notifications to initiate the call to B. For example you can use Google's service [1]. Typically A will send a HTTP request to your server to initiate the call to B and your server will use Google API to send the push notification to B.
At the same time your server should generate a TokBox sessionId for this call and send that sessionId and a token back to user A. User A can use them to connect to the TokBox session and start publishing while waiting for B to join it.
When B receives the notification then you can alert the user (ringing tone) and present any UI you want to him. When B accepts the call you can make another HTTP request to your server to get the sessionId and token for the call (that sessionnId and token could also come in the initial push notification) and join it.
At that point you have both users (A and B) connected to the same TokBox session, publishing audio&video and subscribing to the other stream, so you have a bidirectional audio+video call.
[1] https://firebase.google.com/docs/cloud-messaging/

Update Chromecast MediaMetadata

I'm playing a live HLS stream in a Chromecast app, and I'm wanting to update the MediaMetadata when programmes start/finish. However I can't find a method to do this. I can load the stream again with fresh MediaInfo, but I can't just update the existing metadata. Is there any way to do this?
At present I'm casting from an Android app.
Is there a way to send fresh MediaMetadata to the receiver, or can I pass a custom data message with the information, and update the metadata within the sender using javascript?
see 'CCL' in general for the interfaces to manipulate things like metaData on events like onRemoteStatusChange()...
Looking at that, IMO if you want to alter the message type below to "METADATA_CHANGE" OR whatever it would be for a change in the mediaInfo, then just send the message to the receiver and you should get the broadcast you want... onMediaDataChanged().
sample msg from receiver to CastMgr...
{"requestId":0,"status":{"applications":[{"appId":"33E59692","displayName":"test-receiver-app","namespaces":[{"name":"urn:x-cast:com.google.cast.player.message"},{"name":"urn:x-cast:com.google.cast.media"}],"sessionId":"0869F8A7-25CE-E55F-F571-346EBABB81FB","statusText":"Ready To Cast","transportId":"web-3"}],"isActiveInput":true,"volume":{"level":1.0,"muted":false}},"type":"RECEIVER_STATUS"}
onRemoteMediaPlayerStatusUpdated()
When the receiver goes from PLAY to IDLE at the end of a video , the status change event is called on all 'listeners' ie all implementations of IVideoCastConsumer that have registered as listeners for 'status-changed'.
In the Base CCL class of BaseCastManager, you can watch for this specific status change and then broadcast your onRemoteMediaPlayerMetadataUpdated() event and all observers will get appropriate callback on that.... OR listen on event and just send the correct type of message to the receiver.
If its not exactly intended to observe mediaMetaDataChanges IMO , looking it over may help you tweek the existing API with and #Override in order to get your desire result.

Send notification when inviting to multiplayer game (Game Services)

I’m playing around with Google Play Game Services and multiplayer support. If I invite a player with this service, is it possible to send a notification to the receiver automatically? When I use the demo project nothing like this occurs. The documentation however says:
If the signed-in player accepts an invitation from the notification area on the Android status bar, your app should accept the invitation and go directly to the game screen (skipping the main menu).
This doesn’t explicit says that notifications are supported, but it gives my some hope at least :-). According to this question: Google play game services invitations get lost notifications seems to be supported, but I have never received any.
notifications are supported and will be sent to the receiving player... if the players are not in each other's circles sometimes the notification does not get displayed, depending on the receiver's settings. maybe that is why you haven't received any?
Ok, I finally solved much thanks to #smiller.
First of all I had my test account circled just as Following. This is not enough! Some other circle (Friend, Familiy etc) has to be used. If the person is just in the following circle, onRoomCreated is called with status code 6 (STATUS_NETWORK_ERROR_OPERATION_FAILED) on the inviter's application.
A secondary problem I had was that data synchronizing was turned off on my device. Obviously this has to be turn on. Unfortunately the inviter never get some feedback on this, it just waits forever.

Categories

Resources