cast api get device ip address - google-chrome

Working on a project that casts videos from a chrome app to chrome-cast, I'm unable to decide what's the best way to decide which network adapter ip address i should pass to the chrome.cast.media.MediaInfo api method (I have multiple addresses that starts with 192.168...)
I am able to list all adapters using: chrome.system.network.getNetworkInterfaces.
And also able to find the device using this method, but it is not very stable and doesn't list the device everytime I try it:
chrome.mdns.onServiceList.addListener(function (e)
{
console.log('mdns.onServiceList', e);
},
{
'serviceType': '_googlecast._tcp.local'
});
I thought maybe there's an options to get the ip of the device the user selected using the cast extension but couldn't find any.
so, what is the best way to decide which network adaptar/address is the one accessible to the chrome-cast device.
Thanks!

Related

How to read COM ports? navigator.serial.getPorts returns empty list

I have a small number of USB serial interfaces connected (a HF transceiver, CW keyer based on Arduino) and two bluetooth ports, that I never use and am not sure where do they come from (probably some application). In my SPA I need to read list of ports to be able to select which one to connect as which function.
However, when I call navigator.serial.getPorts() I always get an empty list. BTW, same for navigator.usb.getDevices() It runs on Chrome version 87.0.4280.141 (Official Build) (64-bit). Serial API is enabled.
How to solve this?
UPDATE: it is invoked from script in HTML file in local filesystem (not served over HTTP)
You need to request the user's permission to read the Serial's ports by first calling navigator.serial.requestPort():
onclick = async () => {
await navigator.serial.requestPort();
console.log( await navigator.serial.getPorts() );
};
Live example
You have to get permission to access any serial port by Serial.requestPort(). And the requestPort function can be called only with user activation, such as in click event callback.
After you get the permission of many serial ports, you can list the ports that you can access by Serial.getPorts().
getPorts function doesn't mean get the permission to serial ports, but lists the serials ports that you have had permission to access.
Ref: https://developer.mozilla.org/en-US/docs/Web/API/Serial

Method GetInfo in WebSerial API? Is there another way to get device infos?

I'm using the Web Serial API to connect two different scales. They send the weight data in different ways, so I'm trying to get the serialport metadata from them (vendorId etc) because I want to detect which scale is connected. The "getInfo()" method does not work because it is undefined in the Serialport Object.
[Exposed=(DedicatedWorker,Window), SecureContext]
interface SerialPortInfo {
maplike<DOMString, DOMString?>;
};
This is the interface for the metadata but I don't even know, how to use it.
My sources: https://wicg.github.io/serial/#dom-serialportinfo
The method is declared a little strangely in that version of the specification. You can treat the return value as a plan object. If the port is a USB device then it will have usbVendorId and usbProductId properties which are the metadata you are interested in.

How to find out the availability status of a Web API from a Windows Store application

I have a Line-of-Business (LoB) Windows 8.1 Store application I developed for a client. The client side-loads it on several Windows 10 tablets. They use it in an environment where WiFi is spotty at best and they would like to get some sort of notification inside the app, regardless of what page they are on, notification that will let them know that they've lost connectivity to the network. I have created a method on my Web API that is not hitting the repository (database). Instead, it quickly returns some static information regarding my Web API, such as version, date and time of the invocation and some trademark stuff that I'm required to return. I thought of calling this method at precise intervals of time and when there's no response, assume that the Web API connectivity is lost. In my main page, the first one displayed when the application is started, I have the following stuff in the constructor of my view model:
_webApiStatusTimer = new DispatcherTimer();
_webApiStatusTimer.Tick += OnCheckWebApiStatusEvent;
_webApiStatusTimer.Interval = new TimeSpan(0, 0, 30);
_webApiStatusTimer.Start();
Then, the event handler is implemented like this:
private async void OnCheckWebApiStatusEvent(object sender, object e)
{
// stop the timer
_webApiStatusTimer.Stop();
// refresh the search
var webApiInfo = await _webApiClient.GetWebApiInfo();
// add all returned records in the list
if (webApiInfo == null)
{
var messageDialog = new MessageDialog(#"The application has lost connection with the back-end Web API!");
await messageDialog.ShowAsync();
// restart the timer
_webApiStatusTimer.Start();
}
}
When the Web API connection is lost, I get a nice popup message that informs me that the Web API is no longer available. The problem I have is that after a while, especially if I navigate away from the first page but not necessary, I get an UnauthorizedAccessException in my application.
I use the DispatcherTimer since my understanding is that this is compatible with
UI threads, but obviously, I still do something wrong. Anyone cares to set me on the right path?
Also, if you did something similar and found a much better approach, I'd love to hear about your solution.
Thanks in advance,
Eddie
First, If you are using Windows Store Apps, then you could possibly use a Background task to check poll for the status of the web api instead of putting this responsibility on your view model, its not the viewmodels concern
Second, if you are connecting from your Windows store app to your API then one successful authentication/ authorization for the first time, how and where do you store the token (assuming you are using token authentication). If you are (and ideally you should), is there a timer that you start which is set to the token expiration time? Is your local storage getting flushed somehow and loosing the aurthorization data?
Need more information.

Chrome Extension, messaging: getting port status

I am trying to get a port's status in an application (not a content script). When I do :
this.port = chrome.runtime.connect("okcbadfdlhldjgkbafhnkcpofabckgde");
I get a valid port object but I can't find anyway to determine if the port can be used at all (I don't even get a disconnect event if the extension can't be reached).
The only way I figured out to have the connectivity state is to actually trap an exception when performing a this.port.postMessage.
Is there a better way ?
https://developer.chrome.com/extensions/runtime#method-connect
Update
Running Version 48.0.2564.97 (64-bit) on Linux Ubuntu
No cross-extension messaging, just application to/from extension
Extension source code but note I have since moved on to implement another strategy for the extension because of the issue raised in this question.
Your extension uses a background-script that provides listener function for the chrome.runtime.onMessageExternal event. This event is used to listen for incoming messages, send from external webpage-scripts (or other extensions) by calling the chrome.runtime.sendMessage method.
Since your extension does not provide a listener function for the chrome.runtime.onConnectExternal event, chrome.runtime.connect cannot work for your extension.
As far as knowing the connection status is concerned, in this case a simple try-catch block would do enough to know whether the extension supports port or not. If it does, you need to view the manifest corresponding to this extension - to see if a particular host is allowed to send messages or not.
I was able to send message to your extension (see the enclosed figure) by adding the following lines of code in the background-script. In addition to this, I also added the matches string for the host - www.example.org in the manifest.
chrome.runtime.onMessageExternal.addListener(
function(request, _sender, sendResponse) {
console.log(request);
...
}
);

Windows Phone Custom URI

in my windows phone 8 application i am using custom uri association to launch another application through my phone.
i.e
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
but my app is not able to get certified for store because of this. the testing team tells that you app terminates unexpectedly while executing this.
now, i don't know how to deal with this.
is there any way to throw exception if the app which i am launching is not installed on phone ?
or i should try something else so my task gets accomplished and app gets certified for store as well.
You do not need to wrap your launch in try/catch or check for success as described in the other answers. As soon as you call LaunchUriAsync, the platform takes over and will automatically handle the possibility of no app being installed by asking the user if she wishes to search in the store.
A couple of things to double-check:
1) Ensure that you can successfully back into your app following the navigation to sixtag.
2) Ensure that your call to LaunchUriAsync is the direct result of a user action (eg. tapping a button)
try
{
await Windows.System.Launcher.LaunchUriAsync(new Uri("sixtag:"));
}
catch
{
MessageBox.Show("please install Sixtag from the app store","AppMissing", MessageBoxButton.OK);
}
you can perhaps display another button and on clicking directly navigate to the app store. See if this solves your problem. Do vote it up if it does :)
You are needed to handle that as shown here . Also Read out Remarks given there.