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

Update npm package #19

Closed
navaneetharaopy opened this issue Nov 10, 2015 · 3 comments
Closed

Update npm package #19

navaneetharaopy opened this issue Nov 10, 2015 · 3 comments

Comments

@navaneetharaopy
Copy link

package: castv2
version: 0.1.4
issue: The following error still exist , #14 null referencing error). Please update source and npm module.
screen shot 2015-11-10 at 12 07 12 pm

@thibauts
Copy link
Owner

I need to know why this error happens before settling on a way to fix it. It shouldn't happen in the first place, so how do we end up with onclose firing when self.ps is null ?

If you can help with that you're more than welcome.

@navaneetharaopy
Copy link
Author

connect two chrome cast in a network and change the app id in the following code.

var Client = require('castv2').Client,
    mdns = require('mdns');

var browser,
    detectedPlayers={},
    searchProgress = false;

function createBus(host,name) {
    var target ={};

    target.isConnected = true;
    target.ip = host;
    target.connection = null;
    target.heartbeat = null;
    target.receiver = null;
    target.liveTimer = null;
    target.client = new Client();


    target.client.connect(host, function() {

        target.connection =  target.client.createChannel(name,'receiver-0', 'urn:x-cast:com.google.cast.tp.connection', 'JSON');
        target.heartbeat  =  target.client.createChannel(name, 'receiver-0', 'urn:x-cast:com.google.cast.tp.heartbeat', 'JSON');
        target.receiver   =  target.client.createChannel(name, 'receiver-0', 'urn:x-cast:com.google.cast.receiver', 'JSON');


        target.connection.send({ type: 'CONNECT' });

        target.connection.on('error',function(){
            console.log('error in connection');
        })
        target.connection.on('message',function(msg){
            console.log(msg);
        })

        target.liveTimer = setInterval(function() {
            target.heartbeat.send({ type: 'PING' });
            target.receiver.send({"type": "GET_STATUS"})
        }, 10000);

        target.heartbeat.on('error',function(){
            console.log('error in heartbeat');
        })

        target.receiver.send({ type: 'LAUNCH', appId: 'app id goes here', requestId: 1 });

        target.receiver.on('error',function(){
            console.log('error in receiver');
        })

        target.receiver.on('message', function(data, broadcast) {
            if(data.type = 'RECEIVER_STATUS') {
                console.log(data);

                if(data.reason == 'CAST_INIT_TIMEOUT'){
                    target.receiver.send({ type: 'LAUNCH', appId: 'app id goes here', requestId: 1 });
                }

                if(data.status && data.status.isStandBy){
                    //clearInterval(target.liveTimer);
                    //target.connection.close();
                    //target.heartbeat.close();
                    //target.receiver.close();
                    //target.client.close();
                    target.isConnected = false;

                }
            }
        });
    });

    target.client.on('error',function(err){
        console.log('error',err);
        //clearInterval(target.liveTimer);
        target.isConnected = false;
    })

    target.client.on('close',function(err){
        console.log('close',err);
        //clearInterval(target.liveTimer);
        target.isConnected = false;
        console.log(detectedPlayers);

    })
    target.client.on('message',function(msg,msg1){
        console.log('message ',target.ip,msg.msg1);
    })

     detectedPlayers[host] = target;
}

function searchDevice(){
    console.log('launching discovery service')
    browser = mdns.createBrowser(mdns.tcp('googlecast'));
    searchProgress = true;
    browser.start();

    browser.on('serviceUp', function(service) {
        var castIP = service.addresses[0],
            castname = service.name;
        if(!detectedPlayers[castIP] || !detectedPlayers[castIP].isConnected){
            createBus(service.addresses[0],castname);
        }
    });
    browser.on('serviceDown', function(service) {
        console.log("service down: ", service);
    });
}

searchDevice();

setInterval(function(){
        if(browser)
            browser.stop();
        searchDevice();
    },30*1000);

Please correct me if anything is wrong. And add your custom receiver number in target.receiver.send

@thibauts
Copy link
Owner

I don't have two Chromecasts unfortunately. Please run your code code with DEBUG=* node yourscript.js and post the log.

@thibauts thibauts closed this as completed Apr 6, 2016
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

2 participants