1

我正在尝试从这里启动 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 未捕获的不变违规:在“连接(提供者)”的上下文或道具中找不到“商店”。要么将根组件包装在 a 中,要么将“store”作为道具显式传递给“Connect(Provider)”。

您对此代码有什么问题以及如何解决此问题有任何想法吗?

4

1 回答 1

1

我也遇到了这个问题,并通过更新包解决了这个问题。你必须使用

  • 反应@^16.8.4
  • 反应-dom@^16.8.4
  • react-redux@^7.0.0
  • redux@^4.0.0
  • redux-thunk@^2.3.0

以下是要求simplewebRTC

https://docs.simplewebrtc.com/#/ReactVersions

于 2019-05-23T11:51:59.143 回答