1
votes

I am trying to create Electron app which can manage Airplay on MacOS

I am using Angular and TypeScript to wrap APIs from this npm package Airplay npm package :

this is the code I am using in TypeScript :

export class AirplaySharing {
    public init() {
        const airplayer = window['require']('airplayer');
        const list = airplayer();

        list.on('update', function(player) {
            console.log('Found new AirPlay device:', player.name);
        });
    }
}

I get this error while calling init()

Error: Cannot find module 'airplayer'
at Module._resolveFilename
at Function.Module._resolveFilename
at Function.Module._load
at Module.require
at require
at t.init
at new t
at bs
at gs
at Ys

2
Did you install the package npm install airplayer --save? - LearnToday
Yes I did install the package - Ebram
I installed the wrong package. Thanks! - Ebram

2 Answers

0
votes

Would this work

import airplayer = require('airplayer');

export class AirplaySharing {
    public init() {
        const list = airplayer();
        list.on('update', function(player) {
            console.log('Found new AirPlay device:', player.name);
        });
    }
}

Also would it be better to make use of the typescript constructor? Like this:

import airplayer = require('airplayer');

export class AirplaySharing {
    constructor(public list: airplayer()) {
        list.on('update', function(player) {
            console.log('Found new AirPlay device:', player.name);
        });
    }
}

Hope that helps :)

0
votes

Did you install the package npm install airplayer --save?