Example #1
0
    play(url: string, timestamp: number): void {
        if (this._client) this._client.close();

        this._client = new Client();
        this._client.connect(this.host, err => {
            if (err) return this.emit('error', err);

            this._client.launch(MediaReceiver, (err, player) => {
                if (err) return this.emit('error', err);

                this._player = player;

                var opts = {
                    autoplay: true,
                    currentTime: timestamp
                };

                var content = {
                    contentId: url,
                    contentType: 'video/mp4'
                };

                this._player.load(content, opts, err => {
                    if (err) return this.emit('error', err);
                });
            });
        });
    }
Example #2
0
        client.getSessions(function (err, sess) {
          if (err) return cb(err)

          var session = sess[0]
          if (session && session.appId === castv2.DefaultMediaReceiver.APP_ID) {
            client.join(session, castv2.DefaultMediaReceiver, ready)
          } else {
            client.launch(castv2.DefaultMediaReceiver, ready)
          }
        })
 constructor(device) {
     super();
     this._device = device;
     this._client = new Client();
     this._client.on('error', (err) => {
         this._client.close();
         this.emit('error', err);
     });
     this._client.on('status', (status) => {
         this.emit('status', status);
     });
 }
 stop(cbk) {
     if(this._client) {
         this._client.stop(cbk);
     } else {
         (cbk||function(){})(null);
     }
 }
Example #5
0
      client.connect(player.host, function (err) {
        if (err) return cb(err)
        player.emit('connect')

        client.getSessions(function (err, sess) {
          if (err) return cb(err)

          var session = sess[0]
          if (session && session.appId === castv2.DefaultMediaReceiver.APP_ID) {
            client.join(session, castv2.DefaultMediaReceiver, ready)
          } else {
            client.launch(castv2.DefaultMediaReceiver, ready)
          }
        })

        function ready (err, p) {
          if (err) return cb(err)

          player.emit('ready')

          p.on('close', function () {
            connect = thunky(reconnect)
          })

          p.on('status', function (status) {
            player.emit('status', status)
          })

          cb(null, p)
        }
      })
Example #6
0
    var connectClient = thunky(function reconnectClient (cb) {
      var client = new castv2.Client()

      client.on('error', function () {
        connectClient = thunky(reconnectClient)
      })

      client.on('close', function () {
        connectClient = thunky(reconnectClient)
      })

      client.connect(player.host, function (err) {
        if (err) return cb(err)
        cb(null, client)
      })
    })
 setMuted(muted, cbk) {
     if(this._client) {
         this._client.setVolume({muted: !!muted}, function(err, volume) {
             (cbk||function(){})(err, volume.muted, volume.level);
         });
     } else {
         (cbk||function(){})(null, null);
     }
 }
 isMuted(cbk) {
     if(this._client) {
         this._client.getVolume(function(err, volume) {
             cbk(err, volume.muted);
         });
     } else {
         cbk(null, null);
     }
 }
 setVolume(volume, cbk) {
     if(this._client) {
         volume = Math.max(0, Math.min(volume, 1));
         this._client.setVolume({level: volume}, function(err, volume) {
             (cbk||function(){})(err, volume.level);
         });
     } else {
         (cbk||function(){})(null, null);
     }
 }
Example #10
0
 return new Promise(function(resolve, reject) {
   var client = new Client();
   client.connect(ctx.address, function() {
     ctx.client = client;
     resolve(ctx);
   });
   var onError = function(err) {
     debug('client error %o', err);
     client.removeListener('error', onError);
     ctx.shutdown();
   };
   var onClose = function() {
     debug('client onClose');
     client.client.removeListener('close', onClose);
     client.removeListener('error', onError);
     ctx.clientClosed = true;
   };
   client.client.on('close', onClose);
   client.on('error', onError);
 });
    client.connect(host, function() {
      console.log('connected, launching app ...');
      client.launch(DefaultMediaReceiver, function(err, player) {
        _player = player;

        _player.on('status', function(status) {
          console.log('status broadcast playerState=%s', status.playerState);
        });


        callback(err);
      });
    });
 this._client.connect(this._device.addresses[0], () => {
     this._client.launch(DefaultMediaReceiver, (err, player) => {
         if(err) cbk(err);
         else {
             player.load({
                 contentId: `http://${this._webcast.localIp}:${this._webcast.port}/`,
                 contentType: this._webcast.contentType,
                 streamType: 'BUFFERED',
                 metadata: {
                     metadataType: 0,
                     title: streamName
                 }
             }, { autoplay: true }, (err, status) => {
                 this._player = player;
                 if(err) cbk(err);
                 else cbk(null, status);
             });
         }
     });
 });
Example #13
0
 close() {
   this.client.close();
 }
Example #14
0
 connect() {
   this.client.connect(this.host, this.onConnect.bind(this));
   this.client.on('error', this.onClientError.bind(this));
   this.client.on('close', this.onClientClose.bind(this));
 }
Example #15
0
 var onClose = function() {
   debug('client onClose');
   client.client.removeListener('close', onClose);
   client.removeListener('error', onError);
   ctx.clientClosed = true;
 };
Example #16
0
 var onError = function(err) {
   debug('client error %o', err);
   client.removeListener('error', onError);
   ctx.shutdown();
 };
 this._client.on('error', (err) => {
     this._client.close();
     this.emit('error', err);
 });
 close() {
     this._client.close();
     this._client = null;
 }
Example #19
0
 onConnect() {
   this.emit('connected');
   this.client.launch(DefaultMediaReceiver, this.onLaunch.bind(this));
 }
Example #20
0
 onClientError(err) {
   console.error('Chromecast client error', err);
   this.emit('error', err);
   this.client.close();
 }