I'm using pusher in my app to get some live values in-app from the server.
I'm subscribing to static channelName but somehow the user can't get data from the server if he keeps the app for a long time open, if the user restarts the app it works fine.
in the pusher dashboard it works well and shows data go to users but, it's not.
when I read on pusher I found that there is ping-pong but, even if I increased pong time it fails too
here is my code:
1- for pusher & channel create ( called in on create ):
options = new PusherOptions();
String APP_CLUSTER = "APP_CLUSTER ";
options.setCluster(APP_CLUSTER);
String APP_KEY = "APP_KEY ";
pusher = new Pusher(APP_KEY, options);
pusher.connect(new ConnectionEventListener() {
#Override
public void onConnectionStateChange(ConnectionStateChange change) {
Log.e("PUSHER SUCCESS => ", change.getCurrentState().name());
}
#Override
public void onError(String message, String code, Exception e) {
Log.e("PUSHER FAILED => ", message);
}
}, ConnectionState.ALL);
2- channel bind & subscribe ( called in onResume ):
channel = pusher.subscribe("xxx");
channel.bind("MessageCreated", event -> {
Log.e("PUSHER DATA => ", event.getData());
});
3- channel un-subscribe ( called in onPause):
pusher.unsubscribe("xxx");
4- disconnect pusher ( called in onDestroy ):
pusher.disconnect();
I hope if anyone can give me the reason for disconnecting for some users, can someone tell me
Related
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.
I have integrated FCM push notifications in xamarin android app. When foreground notifications delivering, notification click event calling MainActivity and from there it is not receiving and deleting all inserted records of SQLite because of that I am navigating to the wrong page. How can I retrieve my SQLite DB?
Thank you.
My Code:
click_action code:
[IntentFilter(new[] { "SISActivity" }, Categories = new[] { Intent.CategoryHome, Intent.CategoryDefault })]
public class SISActivity : AppCompatActivity
{
//from here need to navigation on other pages.
}
click_action sending with FCM notification
click_action":"SISActivity"
But code starting execution from MainActivity
Code in main activity for getting already logged in user
SQLiteAsyncConnection _conn;
_conn = DatabaseAccess.GetConnection();
//if table already created sqlite wont create it again
await _conn.CreateTableAsync<LoggedInUser>();
var objSisRepo = new SISRepository<LoggedInUser>(_conn);
var resultSingle = await objSisRepo.Get();
resultSingle getting 0 even if records available and deleting existing
records. Consequently, i am navigating to the login page instead of the Home page.
It is working fine when the app is in the background. I am using Async programming here.
SQLite connection getting method.
public static SQLiteAsyncConnection GetConnection()
{
SQLiteAsyncConnection con = null;
try
{
var sqlDbFileName = "edTheSIS.db3";
var documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
var path = System.IO.Path.Combine(documentsPath, sqlDbFileName);
var connection = new SQLiteAsyncConnection(path);
con = connection;
return connection;
}
catch (Exception ex)
{
Toast.MakeText(Application.Context, "Something went wrong", ToastLength.Short).Show();
var objLog = new LogService();
objLog.MobileLog(ex, SISConst.UserName);
}
return con;
}
I don't know whether this is proper answer or not but near to it, and solved my problem. I was using AsyncSQLiteConnection , as I have posted my code. Now I have remove that and just using SQLiteConnection it is working for me. Thank you
I am attempting to create a real-time communication capability for a Phonegap/Cordova app. I am using SignalR 2 to handle the communication.
The thing I am struggling with is getting a message to a particular user. Every single example out there shows saving Context.User.Identity.Name, which is useless to me because the remote site's User.Identity context is not shared by my phonegap app.
In essence, I am not authenticating a user in the traditional sense, so I need another way of linking the SignalR connectionID with the username I pass along.
Taken from the official ASP.NET signalr Examples, I have the following code which overrides the OnConnected event. Unfortunately it takes no parameters and expects User.Identity to be not null:
public override Task OnConnected()
{
using (var db = new UserContext())
{
// Retrieve user.
var user = db.Users
.Include(u => u.Rooms)
.SingleOrDefault(u => u.UserName == Context.User.Identity.Name);
// If user does not exist in database, must add.
if (user == null)
{
user = new User()
{
UserName = Context.User.Identity.Name
};
db.Users.Add(user);
db.SaveChanges();
}
else
{
// Add to each assigned group.
foreach (var item in user.Rooms)
{
Groups.Add(Context.ConnectionId, item.RoomName);
}
}
}
return base.OnConnected();
}
Now, maybe what I'd need is to have a version of this method that takes a string as a parameter and then I'd use that as my user identifier.
But how to go about that?
You need to create a new IUserIdProvider for the user and use dependency injection to register your provider and use it.
public interface IUserIdProvider
{
string GetUserId(IRequest request);
}
Register your provider with Global Host
GlobalHost.DependencyResolver.Register(typeof(IUserIdProvider), () => new MyIdProvider());
Usage:
public class MyHub : Hub
{
public void Send(string userId, string message)
{
Clients.User(userId).send(message);
}
}
Taken from: http://www.asp.net/signalr/overview/guide-to-the-api/mapping-users-to-connections#IUserIdProvider
Sinch In-App Instant Messaging works perfectly fine with Sinch Managed Push but except this one issue.
This is the sistuation - I receives messages using GCM Listener when my app is foreground or background and I show notification but except in the case when my app is not running.
I inserted debug logs statements to see the flow and it seems that push message arrives in the GCM Listener and gets sent to my service as well but it never gets relayed to the message client listener. This only happens when the app is not running or is closed.
I am doing the following when the app is running background or foreground and I do get callback in onIncomingMessage but same code doesn't work when app is not running.
Sinch Client Initialization Code:
public void startSinchClient(String username) {
try {
sinchClient = Sinch.getSinchClientBuilder().context(this).userId(username).applicationKey(ApplicationConstants.SINCH_SANDBOX_API_KEY)
.applicationSecret(ApplicationConstants.SINCH_SANDBOX_API_SECRET).environmentHost(ApplicationConstants.SINCH_SANDBOX_API_URL).build();
sinchClient.setSupportMessaging(true);
sinchClient.setSupportManagedPush(true);
sinchClient.checkManifest();
sinchClient.addSinchClientListener(this);
if ( messageClientListener == null ) {
messageClientListener = new MyMessageClientListener();
}
sinchClient.getMessageClient().addMessageClientListener(messageClientListener);
Log.e("SinchMessageService", "Login successful.");
} catch (MissingGCMException missingGCM) {
Log.e("SinchMessageService", missingGCM.getMessage());
}
}
OnBind Code
if (!isSinchClientStarted()) {
startSinchClient(currentUserId);
sinchClient.start();
}
In RelayRemotePushNotificationCode:
public NotificationResult relayRemotePushNotificationPayload(Intent intent) {
if ( currentUserId.isEmpty() ) {
Log.e("SinchMessageService", "UserID not available.Please login again.");
return null;
} else if ( !isSinchClientStarted() ) {
startSinchClient(currentUserId);
sinchClient.start();
}
Log.d("SinchService", "relayRemotePushNotificationPayload");
NotificationResult notificationResult = sinchClient.relayRemotePushNotificationPayload(intent);
if (notificationResult.isMessage()) {
sinchClient.startListeningOnActiveConnection();
}
return notificationResult;
}
In MessageClientListener:
public void onIncomingMessage(MessageClient client, final Message message) {
if (message.getRecipientIds().get(0).equals(ApplicationConstants.userInfo.getEmail())) {
sinchClient.stopListeningOnActiveConnection();
....
The above code works in all the scenarios. I mean when the app is running in foreground as well as background. Only when I kill the app never get the onIncomingMessage callback.
Log statements from Sinch Client:
03-03 22:07:44.213 17381-17381/com.ontyme E/SinchClient: mUserAgent.startBroadcastListener()
03-03 22:07:45.271 17381-17381/com.ontyme E/MessageClient: onIncomingMessage: NativeMessage [id=2059913a-27ac-4105-a797-764f09af66d2, nativeAddress=-1321533856]
Anyone else has faced the issue?
Sorry guys there is no problem with the Sinch Managed Push. It was small typo at my end which was causing this issue. My receipentid in the app was not getting initialized correctly when the app was not running which is why all the messages were getting ignored in onIncomingMessage.
Managed Push works seamlessly for me now.
I'm currently attempting to use AppSync to sync a piece of data between an android app and a pebble app. However, I seem to not be able to get the pebble to realize that any data is being transferred - that is, no logs are being produced where they should be. What is really bothering me is that this is essentially the code found in the pebble weather example. I've pasted the relevant bits of code below - could someone possibly look it over and suggest where any issues may be? I've made sure that the UUIDs in both programs (pebble app and android app) are the same, and that they are on the same network, and that the pebble is actually connected to the phone, and that the android function is actually being called and all.
Snippet of pebble app code:
static void sync_error_callback(DictionaryResult dict_error, AppMessageResult app_message_error, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "App Message Sync Error: %d", app_message_error);
}
static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, new_tuple->value->cstring);
}
void home_screen_load() {
// set up each one of the SimpleMenuItems
Tuplet initial_values[] = {
TupletCString(0x0, "Initial 1")
};
app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values), sync_tuple_changed_callback, sync_error_callback, NULL);
}
Snippet of android app:
final UUID PEBBLE_APP_UUID = UUID.fromString("10549fd4-1fe4-4d30-8a18-6f2f8149f8fd");
public void sendDataToWatch(String toSend) {
// Build up a Pebble dictionary containing the weather icon and the current temperature in degrees celsius
PebbleDictionary data = new PebbleDictionary();
data.addString(0x0, toSend);
PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID, data);
}
To debug this type of problem, you should set a inbox_dropped handler and see if you get anything there.
After initializing AppMessage and AppSync, call:
app_message_register_inbox_dropped(appmsg_in_dropped);
And add this function:
static void appmsg_in_dropped(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "In dropped: %s", translate_error(reason));
}
Take a look at this question for the source of the translate_error function.