Beispiel #1
0
  _starter = () => {
    if (crosstab.supported) {
      crosstab.on(ACTOR_INIT_EVENT, (msg) => {
        if (msg.origin !== crosstab.id && window.location.hash !== '#/deactivated') {
          history.push('deactivated');
        }
      });
    }

    const appRootElemet = document.getElementById(this.rootElement);

    if (window.location.hash !== '#/deactivated') {
      if (crosstab.supported) crosstab.broadcast(ACTOR_INIT_EVENT, {});
      window.messenger = Actor.create({
        endpoints: this.endpoints,
        logHandler: this.logHandler
      });
    }

    const intlData = getIntlData(this.forceLocale);

    /**
     * Method for pulling props to router components
     *
     * @param RoutedComponent component for extending
     * @param props props to extend
     * @returns {object} extended component
     */
    const createElement = (Component, props) => {
      return <Component {...props} delegate={this.delegate} isExperimental={this.isExperimental}/>;
    };

    const root = (
      <IntlProvider {...intlData}>
        <Router history={history} createElement={createElement}>
          {this.getRoutes()}
        </Router>
      </IntlProvider>
    );

    render(root, appRootElemet);

    // initial setup fot react modal
    Modal.setAppElement(appRootElemet);

    if (window.location.hash !== '#/deactivated') {
      if (LoginStore.isLoggedIn()) LoginActionCreators.setLoggedIn({ redirect: false });
    }
  };
Beispiel #2
0
const initReact = () => {
  if (window.location.hash !== '#/deactivated') {
    if (crosstab.supported) {
      crosstab.broadcast(ActorInitEvent, {});
    }

    if (location.pathname === '/app/index.html') {
      window.messenger = new window.actor.ActorApp(['ws://' + location.hostname + ':9080/']);
    } else {
      window.messenger = new window.actor.ActorApp();
    }
  }

  const App = React.createClass({
    render() {
      return <RouteHandler/>;
    }
  });

  const routes = (
    <Route handler={App} name="app" path="/">
      <Route handler={Main} name="main" path="/"/>
      <Route handler={JoinGroup} name="join" path="/join/:token"/>
      <Route handler={Login} name="login" path="/auth"/>
      <Route handler={Deactivated} name="deactivated" path="/deactivated"/>
      <DefaultRoute handler={Main}/>
    </Route>
  );

  const router = Router.run(routes, Router.HashLocation, function (Handler) {
    injectTapEventPlugin();
    React.render(<Handler/>, document.getElementById('actor-web-app'));
  });

  if (window.location.hash !== '#/deactivated') {
    if (LoginStore.isLoggedIn()) {
      LoginActionCreators.setLoggedIn(router, {redirect: false});
    }
  }
};
  _starter = () => {
    if (crosstab.supported) {
      crosstab.on(ACTOR_INIT_EVENT, (msg) => {
        if (msg.origin !== crosstab.id && window.location.hash !== '#/deactivated') {
          history.push('deactivated');
        }
      });
    }

    const appRootElemet = document.getElementById(this.rootElement);

    if (window.location.hash !== '#/deactivated') {
      if (crosstab.supported) crosstab.broadcast(ACTOR_INIT_EVENT, {});
      window.messenger = Actor.create({
        endpoints: this.endpoints,
        logHandler: loggerAppend
      });
    }

    const Login = (typeof this.delegate.components.login == 'function') ? this.delegate.components.login : DefaultLogin;
    const Deactivated = (typeof this.delegate.components.deactivated == 'function') ? this.delegate.components.deactivated : DefaultDeactivated;
    const Install = (typeof this.delegate.components.install == 'function') ? this.delegate.components.install : DefaultInstall;
    const Archive = (typeof this.delegate.components.archive == 'function') ? this.delegate.components.archive : DefaultArchive;
    const Join = (typeof this.delegate.components.join == 'function') ? this.delegate.components.join : DefaultJoin;
    const Empty = (typeof this.delegate.components.empty == 'function') ? this.delegate.components.empty : DefaultEmpty;
    const Dialog = (typeof this.delegate.components.dialog == 'function') ? this.delegate.components.dialog : DefaultDialog;
    const intlData = getIntlData(this.forceLocale);

    const requireAuth = (nextState, replaceState) => {
      if (!LoginStore.isLoggedIn()) {
        replaceState({
          pathname: '/auth',
          state: {nextPathname: nextState.location.pathname}
        });
      }
    };

    function checkPeer(nextState, replaceState) {
      const peer = PeerUtils.stringToPeer(nextState.params.id);
      if (!PeerUtils.hasPeer(peer)) {
        console.error('Invalig peer', nextState);
        replaceState('/im');
      }
    }

    /**
     * Method for pulling props to router components
     *
     * @param RoutedComponent component for extending
     * @param props props to extend
     * @returns {object} extended component
     */
    const createElement = (Component, props) => {
      return <Component {...props} delegate={this.delegate} isExperimental={this.isExperimental}/>;
    };

    const root = (
      <IntlProvider {...intlData}>
        <Router history={history} createElement={createElement}>
          <Route path="/" component={App}>
            <Route path="auth" component={Login}/>
            <Route path="deactivated" component={Deactivated}/>
            <Route path="install" component={Install}/>
            <Route path="join/:token" component={Join} onEnter={requireAuth}/>

            <Route path="im" component={Main} onEnter={requireAuth}>
              <Route path="archive" component={Archive}/>
              <Route path=":id" component={Dialog} onEnter={checkPeer}/>
              <IndexRoute component={Empty}/>
            </Route>

            <IndexRedirect to="im"/>
          </Route>
        </Router>
      </IntlProvider>
    );

    render(root, appRootElemet);

    // initial setup fot react modal
    Modal.setAppElement(appRootElemet);

    if (window.location.hash !== '#/deactivated') {
      if (LoginStore.isLoggedIn()) LoginActionCreators.setLoggedIn({redirect: false});
    }
  };