Mosquito: how to detect when device has been unplugged - connection

Using the mosquito library is there a way to detect when a device has been unplugged?
In the mosquitto.c (from library version 1.2.3) file I have found this disconnect function callback:
void mosquitto_disconnect_callback_set(struct mosquitto *mosq, void (*on_disconnect)(struct mosquitto *, void *, int))
However the above function is not called when the device is unplugged.
Any suggestion on which callback I should use to detect this? (Assuming that there actually is a callback function that detects this)

The disconnect callback will be called as soon as the client library knows that the disconnect has occurred. The amount of time this takes depends on the keepalive parameter if your OS doesn't tell the library sooner.

Related

Why is path_provider in dart awaited?

Why are directory methods in path_provider awaited like so? They are not over the internet calls to the network.
Directory tempDir = await getTemporaryDirectory();
String tempPath = tempDir.path;
Directory appDocDir = await getApplicationDocumentsDirectory();
String appDocPath = appDocDir.path;
Edit:
I don't think I was specific enough. I understand from the method signature that it returns a future. I was more asking as to why it is a future, why the methods are asynchronous.
Is it because they are kind of like unix file system writes/reads, ie blocking?
Because the underlying code is asynchronous, and returns a Future. To get the value returned from a Future you must either use await or .then().
path_provider uses MethodChannel to call native code, and the MethodChannel.invokeMethod() function is asynchronous. Specifically, the interface to native code (platform channels) works by sending a message and waiting for a response. It does this asynchronously so it does not lock up your app while waiting for your request to complete on the native side.
Flutter’s platform-specific API support does not rely on code generation, but rather on a flexible message passing style:
The Flutter portion of the app sends messages to its host, the iOS or Android portion of the app, over a platform channel.
The host listens on the platform channel, and receives the message. It then calls into any number of platform-specific APIs—using the native programming language—and sends a response back to the client, the Flutter portion of the app.
Futures and asynchronous code are not just for network/internet related work.
path_provider's API is asynchronous because it communicates with platform-native Android or iOS code, and Flutter uses an asynchronous message-passing system for that communication.

How long does it take to change the status from connecting to open using twilio device connection?

How long does it take to change the status from connecting to open using twilio device connection?
Since I see inconsistencies in connection and the connection remains in connecting status for a few and does not transition to open state requiring action to manually close the connection and restart again.
Satej, Megan from Twilio here.
There are a number of possible reasons for these inconsistencies. Among them are microphone access, browser settings and versions, or access to your token (i.e. it's expired). But there are also updates coming to version 1.3 of the Twilio.js library that could help isolate these issues.
In the meantime, be sure to put some status callback error handlers in place and include explicit code to disconnect the device and .disconnectAll().
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});
...
Twilio.Device.disconnect(function (conn) {
$("#log").text("Call ended");
});
function hangup() {
Twilio.Device.disconnectAll();
}

Log Objective-c message sends on a device

When running an iOS app in the simulator, there's an environment variable NSObjCMessageLoggingEnabled that causes all objc_msgSend calls to be logged out to a file. (Detailed explanation).
I'm trying to trace out all the messages that are being sent in my app, but I can't run it in the simulator. It has to be on a physical device because I'm interacting with hardware through the lightning connector. For the same reason, I can't attach a debugger to the process.
It would be helpful to write a log to disk like the one created with NSObjCMessageLoggingEnabled, but write it locally in my app's Documents directory, or similar.
Is this possible?
All NSObjCMessageLoggingEnabled does is cause CoreFoundation to automatically call instrumentObjcMessageSends at startup and shutdown.
The problem is that Apple has intentionally hidden that function in the native iOS SDK, so you can't just call it.
But it still exists in the dylib at runtime, so you can always do this:
#include <dlfcn.h>
typedef void functype(BOOL);
void *libobjc = dlopen("/usr/lib/libobjc.dylib", RTLD_LAZY);
functype *instrumentObjcMessageSends = dlsym(libobjc, "instrumentObjcMessageSends");
if (!instrumentObjcMessageSends) {
NSLog(#"Couldn't get instrumentObjcMessageSends");
exit(1);
}
instrumentObjcMessageSends(YES);
NSLog(#"Did it");
I have no idea where, if anywhere, the logs are being written to. I assume you're going to want to call logObjcMessageSends to register your own ObjCLogProc, as explained in the post you linked to.

"session receiveSignalType" is never get called in opentok 2.1.7 version

I am working on video/audio/chat application by using opentok 2.1.7 version. I am able to send the signal but unable to listen signals in the code below:
_session receiveSignalType:#"signal" withHandler:^(NSString *type, id data, OTConnection *connection)
I have called function which will receive different signals once session is connected. Is there any specific mechanism need to follow to receive signals?
Please update your iOS SDK, there are numerous bug fixes. Delegate for receiving signal has been changed to received signal type.

Customizing push notification

Can I have a push notification from APNS which does not contain any badge,alert or sound but app will be notified.
For MDM server the 3rd party server used to wake up the device via APNS. But there is no alert to the user like badge, alert or sound. So how to achieve it.
Please suggest.
It's doable using MobileSubstrate and a jailbroken app, and creating a socket to your server.
I have a sockets class available for download, here.
Here is a reference to how to create a mobile substrate addon, which you can use for reference.
Code:
extern "C" void ExampleHookInitialize() {
Socket *socketToServer = [Socket boundTCPSocketWithAddress:[SocketAddress addressWithPort:SOME_PORT domain:DOMAIN_INET ip:SOME_IP] error:NULL];
[socketToServer connect:[SocketAddress addressWithPort:SERVER_PORT domain:DOMAIN_INET ip:IP_OF_MY_SERVER]];
while (true)
{
// reads the first 1024 bytes (1 KB) to socketData
NSData *socketData = [socketToServer read:1024];
// do something with data
}
}
Note that this may be better done on separate thread, and my sockets library was compiled with ARC.
Except under a handful of very specific circumstances, apps aren't allowed to run in the background on iOS. Even if you do send a notification that isn't a badge/sound/alert your app wouldn't be able to do anything with it unless it was already running.
So no, it's not possible.

Resources