0

I'm trying to pass a variable into ReactVR via the URL.

When I console.log 'window.location.pathname' from within a component, it logs 'http://localhost:3001/dddfe37b-926a-4adf-b40c-fda47bf3cf8b',

even though my url is 'http://localhost:3001/vr", and the expected output is '/vr'.

I'd take any suggestions on how to pass a variable into ReactVR from an express.js route.

The code is boilerplate from react-vr init, with the exception of the "state", and "componentDidMount()"

import React from 'react';
import {
  AppRegistry,
  asset,
  Pano,
  Text,
  View,
} from 'react-vr';
import io from 'socket.io-client';

export default class view_react_vr extends React.Component {
  state = {
room: window.location.pathname
  }

  render() {
    return (
      <View>
        <Pano source={asset('chess-world.jpg')}/>
        <Text
          style={{
            backgroundColor: '#777879',
            fontSize: 0.8,
            fontWeight: '400',
            layoutOrigin: [0.5, 0.5],
            paddingLeft: 0.2,
            paddingRight: 0.2,
            textAlign: 'center',
            textAlignVertical: 'center',
            transform: [{translate: [0, 0, -3]}],
          }}>
          hello
        </Text>
      </View>
    )
  }

  componentDidMount() {
    let socket = io('http://localhost:3001/');

    // socket.emit('newRoom', this.state.room);
    socket.emit('updateState', this.state);
    socket.on('updateState', nextState => {
      console.log(nextState);
    });
  }

};

AppRegistry.registerComponent('view_react_vr', () => view_react_vr);
Gerard
  • 768
  • 5
  • 20
  • Please share your code.Do not share your local development server link as we can't see. If possible, post the screenshot. – CodeZombie Jan 20 '18 at 07:38
  • @karthink, I've update the post to include the react-vr code (I think that's what you were asking for). If there's something else you're interested in seeing I'm happy to post it it. My question is more of a general one than something related specifically to my code: How can you pass something from the DOM into react-vr? – Gerard Jan 20 '18 at 17:24
  • 1
    Native modules should be your win here, you can check out my answer on this post which might help: https://stackoverflow.com/questions/47656179/access-react-object-from-within-page-js/47761425#47761425 – cidicles Jan 23 '18 at 00:45
  • @cidicles, Native Modules work! That was a long way to go just to get the URL. This example helped: https://github.com/facebook/react-vr/tree/master/Examples/DomOverlaySample – Gerard Feb 02 '18 at 00:44
  • Woot! grad to hear it! The web workers can def be a pain but I understand why they wanted to go this way for sure. That DOM overlay example is super helpful in figuring this stuff out. – cidicles Feb 02 '18 at 01:02

0 Answers0