Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ConnectSDK cordova CapabilityFilters #47

Open
gowebsmarty opened this issue Feb 26, 2016 · 13 comments
Open

ConnectSDK cordova CapabilityFilters #47

gowebsmarty opened this issue Feb 26, 2016 · 13 comments

Comments

@gowebsmarty
Copy link

Is there some capabilityfilter options to filter ONLY airplay and chromecast devices?

@orilux
Copy link

orilux commented Feb 26, 2016

Hi @MyCreativeWebSolutions, in your case you do not need to filter for capabilities, but for services. Here's a function that will return only AirPlay and Chromecast devices:

function getFilteredDevices() {

    var allDevices = ConnectSDK.discoveryManager.getDeviceList();
    var filteredDevices = [];

    for (i = 0; i < allDevices.length; i++) {

        var device = allDevices[i];

        if (device.hasService("AirPlay") || device.hasService("Chromecast")) {

            filteredDevices.push(device);

        }
    }

    return filteredDevices;

}

@gowebsmarty
Copy link
Author

Thank you somuch!.. Any ideas on how can I implement this with pickdevice() pop up function?

On 26-Feb-2016, at 8:54 PM, Oggy Shopov [email protected] wrote:

Hi @MyCreativeWebSolutions, in your case you do not need to filter for capabilities, but for services. Here's a function that will return only AirPlay and Chromecast devices:

function getFilteredDevices() {

var allDevices = ConnectSDK.discoveryManager.getDeviceList();
var filteredDevices = [];

for (i = 0; i < allDevices.length; i++) {

    var device = allDevices[i];

    if (device.hasService("AirPlay") || device.hasService("Chromecast")) {

        filteredDevices.push(device);

    }
}

return filteredDevices;

}

Reply to this email directly or view it on GitHub.

@orilux
Copy link

orilux commented Feb 26, 2016

The built in pop-up is native. It won't be very simple to customize it with that filter. You'd have to start a custom branch of the whole plugin and make changes for both Android and IOS. You'd probably need to look at this file in the core library for the Android version: Connect-SDK-Android-Core/src/com/connectsdk/device/DevicePickerAdapter.java

Instead of doing all of that I would recommend just building a custom picker in JavaScript. You can subscribe to the "devicelistchanged" event on the DiscoveryManager and repopulate your own list every time the event fires. The behavior will be very similar to the built-in picker.

@gowebsmarty
Copy link
Author

Hi @orilux Thank you somuch for your help!.

The major issue we noticed in Cordova ConnectSDK is, the event "devicelistchanged" never fires..

Ex:-

ConnectSDK.discoveryManager.startDiscovery();
ConnectSDK.discoveryManager.on('devicelistchanged', 'getFilteredDevices', false);


function getFilteredDevices() {
alert("List changed");
}

Even tried

document.addEventListener('devicelistchanged', 'getFilteredDevices', false);
ConnectSDK.discoveryManager.addListener('devicelistchanged', 'getFilteredDevices', false);

@gowebsmarty
Copy link
Author

The events "devicefound" and "devicelost" are also not firing in Cordova

@orilux
Copy link

orilux commented Mar 4, 2016

Hi @MyCreativeWebSolutions, it looks like you are not passing your callback function correctly. You shouldn't pass the name of the function as a string. Change your code to this and see if it works:

ConnectSDK.discoveryManager.on('devicelistchanged', getFilteredDevices);

@gowebsmarty
Copy link
Author

Hi @orilux That was very much helpful!.... Finally, we need to store this filtered list in a javascript sessionStorage or localStorage and retrieve it later. Any ideas on this?. Getting difficulty in storing this filteredlist in session.

  ConnectSDK.discoveryManager.startDiscovery();

ConnectSDK.discoveryManager.on('devicelistchanged', getFilteredDevices, false);

function getFilteredDevices() {

    var allDevices = ConnectSDK.discoveryManager.getDeviceList();

  var filteredDevices = [];

    $.each(allDevices, function(idx, dv){      

        if (dv.hasService("AirPlay") || dv.hasService("Chromecast")) {
            filteredDevices.push(dv);               
        }
     });

     window.sessionStorage.setItem("playdevices", JSON.stringify(filteredDevices));

}



function showDevicePicker() { //this is triggered on a button click
    var fdevices = window.sessionStorage.getItem("playdevices");
    alert(fdevices); //returns NULL always
}

@orilux
Copy link

orilux commented Mar 11, 2016

I am guessing this is because of the asynchronous callback of $.each(). In other words you are probably adding filteredDevices to sessionStorage before $.each() has finished adding elements to it.

A quick thing to try is to move the sessionsStorage code inside the iterator like this:

...
$.each(allDevices, function(idx, dv){      

        if (dv.hasService("AirPlay") || dv.hasService("Chromecast")) {
            filteredDevices.push(dv);               
        }

     window.sessionStorage.setItem("playdevices", JSON.stringify(filteredDevices));

     });
...

Keep in mind that this overwrites the sessionsStorage for every item in the array, so it is not the best solution. You should look into using an iterator that does not use callbacks.

@gowebsmarty
Copy link
Author

@orilux Looks like I can store deviceId or friendlyName in filteredDevices array and later retrieve it from sessionStorage without any issues. But entire device object cannot be stored or alerted using JSON.stringify.

Is there a possible way to store only device parameter like its deviceID or friendlyName and later initiate a device object using that parameter?.

P.S., I even tried calling getDeviceList later to get all devices and initiate the device object by cross checking the deviceID. But, getDeviceList in cordova only returns devices that are already connected/being streamed when called separately without any events.

@orilux
Copy link

orilux commented Mar 11, 2016

Saving the entire device object is a very bad idea, because the device's ip address might have changed next time you try to connect.

You should save the deviceId and then when devicelistchanged fires you should iterate through all the devices in the array and look for the one that has a matching id. However if there is more than one device on the network devicelistchanged is going to fire multiple times so you will need to handle that. In other words, just because the device was not in the list the first time, it doesn't mean that it is not available.

@gowebsmarty
Copy link
Author

Hi,

The major challenge here is, we need to save devices on devicelistchanged event and create a custom device picker that gets called on a button click. Any ideas on how to handle this situation? We are just trying to create a custom device picker here as per this thread.

Thanks in advance!

On 11-Mar-2016, at 9:31 PM, Oggy Shopov [email protected] wrote:

Saving the entire device object is a very bad idea, because the device's ip address might have changed next time you try to connect.

You should save the deviceId and then when devicelistchanged fires you should iterate through all the devices in the array and look for the one that has a matching id. However if there is more than one device on the network devicelistchanged is going to fire multiple times so you will need to handle that. In other words, just because the device was not in the list the first time, it doesn't mean that it is not available.


Reply to this email directly or view it on GitHub.

@gowebsmarty
Copy link
Author

@orilux @penelopus @Andolamin @jlai Hi Team,

Can we please get some final thoughts on handling the above situation?. We really wish default picker would have device filtering instead of building this custom picker. Anyhow, We're expecting some small help in building the custom picker here. We are about to launch the App and this is the final thing holding us from doing that.

Thanks,

@rajesh-boda
Copy link

Hi,
Here i am unable get android set top box device list in DiscoveryManager. It showing only LG TV devices only.
Please help us to get android devices too in connectSDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants