代码之家  ›  专栏  ›  技术社区  ›  AnArrayOfFunctions

如何添加钩子导入?

  •  0
  • AnArrayOfFunctions  · 技术社区  · 5 年前

    我想在每次导入后添加一个导入。我如何才能完成我尝试创建的媒体模块(webrtc)包含:

    export * from "@twilio/webrtc";
    import "adapterjs";
    

    然后是网页包中的别名:

    resolve: {
            alias: {
                '@twilio/webrtc': path.resolve(__dirname, 'src/frontend/misc/webrtc')
            }
    }
    

    我在package.json的sideEffects部分指定了adapterjs。

    但是它给了我:

    Unhandled promise rejection TypeError: Object expected
    

    我想原因是我的钩子。错误的位置是奇数(正好在黑色光标处):

    code 以下是上述文本代码:

    var localTrackOptions=Object.assign({log:log},options);delete localTrackOptions.name;if(options.audio===false&&options.video===false){log.info('Neither audio nor video requested, so returning empty LocalTracks');return Promise.resolve([]);}if(options.tracks){log.info('Adding user-provided LocalTracks');log.debug('LocalTracks:',options.tracks);return Promise.resolve(options.tracks);}var localTrackNameOptions={audio:options.audio&&options.audio.name?{name:options.audio.name}:{},video:options.video&&options.video.name?{name:options.video.name}:{}};if(options.audio){delete options.audio.name;}if(options.video){delete options.video.name;}var mediaStreamConstraints={audio:options.audio,video:options.video};var workaroundWebKitBug180748=options.audio&&options.audio.workaroundWebKitBug180748;var mediaStreamPromise=workaroundWebKitBug180748?workaround180748(log,options.getUserMedia,mediaStreamConstraints):options.getUserMedia(mediaStreamConstraints);return mediaStreamPromise.then(function(mediaStream){var mediaStreamTracks=mediaStream.getAudioTracks().concat(mediaStream.getVideoTracks());log.info('Call to getUserMedia successful; got MediaStreamTracks:',mediaStreamTracks);return mediaStreamTracks.map(function(mediaStreamTrack){return asLocalTrack(mediaStreamTrack,Object.assign(localTrackNameOptions[mediaStreamTrack.kind],localTrackOptions));});},function(error){log.warn('Call to getUserMedia failed:',error);throw error;});}
    
    0 回复  |  直到 5 年前