我正在尝试从此处启动SimpleWebRTC应用程序:https://docs.simplewebrtc.com/#/?id=getting-started
App.js文件:
import React from "react";
import { Provider } from "react-redux";
import ReduxToastr from "react-redux-toastr";
import store from "./redux/store/index";
import Routes from "./routes/Routes";
const App = () => (
<Provider store={store}>
<Routes />
<ReduxToastr
timeOut={5000}
newestOnTop={true}
position="top-right"
transitionIn="fadeIn"
transitionOut="fadeOut"
progressBar
closeOnToastrClick
/>
</Provider>
);
export default App;
./ redux / store / index.js文件:
import { combineReducers } from "redux";
import sidebar from "./sidebarReducers";
import layout from "./layoutReducer";
import theme from "./themeReducer";
import app from "./appReducer";
import auth from "./authReducer";
import { reducer as simplewebrtc } from '@andyet/simplewebrtc';
import { reducer as toastr } from "react-redux-toastr";
export default combineReducers({
sidebar,
layout,
theme,
toastr,
app,
auth,
simplewebrtc
});
./ redux / store / index.js文件:
import { createStore, applyMiddleware } from "redux";
import thunk from 'redux-thunk';
import rootReducer from "../reducers/index";
const persistedState = localStorage.getItem('reduxState') ? JSON.parse(localStorage.getItem('reduxState')) : {}
var store
if(persistedState.app){
store = createStore(rootReducer, persistedState, applyMiddleware(thunk));
}else{
store = createStore(rootReducer, applyMiddleware(thunk));
}
store.subscribe(()=>{
localStorage.setItem('reduxState', JSON.stringify(store.getState()))
})
export default store;
Chat.js文件:
const API_KEY = '';
const ROOM_PASSWORD = 'test';
const CONFIG_URL = `https://api.simplewebrtc.com/config/guest/${API_KEY}`
const ROOM_NAME = 'uniq-room-name'
class _SimpleWebRtc extends React.Component {
constructor(props) {
super(props);
}
render(){
return (
<SWRTC.Provider configUrl={CONFIG_URL}> {/* <------- problem here */}
{/* Render based on the connection state */}
<SWRTC.Connecting>
<h1>Connecting...</h1>
</SWRTC.Connecting>
<SWRTC.Connected>
<h1>Connected!</h1>
<SWRTC.RequestUserMedia audio auto />
<SWRTC.Room name={ROOM_NAME} password={ROOM_PASSWORD}>
<SWRTC.RemoteAudioPlayer />
</SWRTC.Room>
</SWRTC.Connected>
</SWRTC.Provider>
)
}
}
const SimpleWebRtc = connect(store => ({simplewebrtc: store.simplewebrtc})) (_SimpleWebRtc)
当我尝试运行此代码时,它为我返回了以下错误:
app.js:58464未捕获的永久违规:在“ Connect(Provider)”的上下文或道具中找不到“ store”。将根组件包装在中,或者将“存储”作为道具明确传递给“ Connect(Provider)”。
您对这段代码有什么问题以及如何解决此问题有任何想法吗?
答案 0 :(得分:0)
我也遇到了这个问题,并通过更新软件包解决了该问题。 您必须使用
这里是simplewebRTC