Reactjs 将类从外部库导入react

Reactjs 将类从外部库导入react,reactjs,Reactjs,我目前正在将webrtc客户端集成到新创建的UI中。客户机是一个类,包含一些init函数,用于与服务器端通信。有人知道如何导入这个外部资源吗?我是前端的新手,非常感谢您的帮助 我尝试过类似的方法,浏览器控制台显示OceanaCustomerWebVoiceVideo不是一个功能: class ClientWrapper extends Component { constructor(props) { super(props); this.state =

我目前正在将webrtc客户端集成到新创建的UI中。客户机是一个类,包含一些init函数,用于与服务器端通信。有人知道如何导入这个外部资源吗?我是前端的新手,非常感谢您的帮助 我尝试过类似的方法,浏览器控制台显示OceanaCustomerWebVoiceVideo不是一个功能:


class ClientWrapper extends Component {
    constructor(props) {
        super(props);
        this.state = { scriptStatus: 'no' };
        this.scriptLoaded = this.scriptLoaded.bind(this);
    }

    scriptLoaded(){
        console.log('external resource has been loaded');
        console.log('initialise client');
        var amcConfig = {
            restUrl: 'xxx.xxx.xxx.xxx',
            port: 'xxx',
            secure: true,
            urlPath: 'xxx/xxx/xxx'
        };

        var aawgConfig = {
            webGatewayAddress: 'xxx.xxx.xxx.xxx',
            port: 'xxx',
            secure: true
        };
        localStorage.setItem('oceana.amcConfig', JSON.stringify(amcConfig));
        localStorage.setItem('oceana.aawg.config', JSON.stringify(aawgConfig));
        var oceanaConfig = JSON.parse(localStorage.getItem('oceana.amcConfig'));
        var webGatewayConfig = JSON.parse(localStorage.getItem('oceana.aawg.config'));

        var config = {
            configuration: oceanaConfig,
            webGatewayConfiguration: webGatewayConfig
        }
        var clientInstance = new window.OceanaCustomerWebVoiceVideo(config);
    }
    componentDidMount() {
        const {scriptLoaded} = this.state;
        const script = document.createElement("script");
        script.async = true;
        script.src = "./OceanaCustomerWebVoiceVideo.js";
        script.onload = ()=>this.scriptLoaded();
        //For head
        document.head.appendChild(script);
    }
    render() {
        

        return (
            <div >
                <h1>{scriptLoaded}</h1>
            </div>

        )
    }
}
export { ClientWrapper };```

类ClientWrapper扩展组件{
建造师(道具){
超级(道具);
this.state={scriptStatus:'no'};
this.scriptLoaded=this.scriptLoaded.bind(this);
}
脚本加载(){
log('外部资源已加载');
console.log(“初始化客户端”);
变量amcConfig={
restUrl:'xxx.xxx.xxx.xxx',
端口:“xxx”,
安全:是的,
urlPath:'xxx/xxx/xxx'
};
var aawgConfig={
webGatewayAddress:'xxx.xxx.xxx.xxx',
端口:“xxx”,
安全:正确
};
setItem('oceana.amcConfig',JSON.stringify(amcConfig));
setItem('oceana.aawg.config',JSON.stringify(aawgConfig));
var oceanaConfig=JSON.parse(localStorage.getItem('oceana.amcConfig');
var webGatewayConfig=JSON.parse(localStorage.getItem('oceana.aawg.config');
变量配置={
配置:oceanaConfig,
webGatewayConfiguration:webGatewayConfig
}
var clientInstance=new window.OceanaCustomerWebVoiceVideo(配置);
}
componentDidMount(){
const{scriptLoaded}=this.state;
常量脚本=document.createElement(“脚本”);
script.async=true;
script.src=“./OceanaCustomerWebVoiceVideo.js”;
script.onload=()=>this.scriptLoaded();
//头部
document.head.appendChild(脚本);
}
render(){
返回(
{scriptLoaded}
)
}
}
导出{ClientWrapper}```

您在哪里定义了
OceanaCustomerWebVoiceVideo
变量?
窗口
对象没有内置的
OceanaCustomerWebVoiceVideo
变量。是的,我在“/OceanaCustomerWebVoiceVideo.js”中定义了OceanaCustomerWebVoiceVideo,在调用该脚本之前,我在其中加载了该脚本。错误是,
OceanaCustomerWebVoiceVideo不是一个函数,那么如何定义该函数呢?