Last active
September 27, 2019 12:35
-
-
Save enricop89/018592cdb89c3f0ed29cb8fb01d5a53e to your computer and use it in GitHub Desktop.
Opentok with RequireJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- index.html --> | |
<html> | |
<body> | |
<!-- container for rendered React element --> | |
<div id="root"></div> | |
<!-- Require.js --> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.2/require.min.js"></script> | |
<!-- main --> | |
<script src="main.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
requirejs.config({ | |
// module name mapped to CDN url | |
paths: { | |
// Require.js appends `.js` extension for you | |
'react': 'https://unpkg.com/react@15.3.2/dist/react', | |
'react-dom': 'https://unpkg.com/react-dom@15.3.2/dist/react-dom', | |
'OT': 'https://static.opentok.com/v2/js/opentok' | |
} | |
}); | |
requirejs.onError = function (err) { | |
console.log('onError', err); | |
if (err.requireType === 'timeout') { | |
console.log('modules: ' + err.requireModules); | |
} | |
throw err; | |
}; | |
// load the modules defined above | |
requirejs(['react', 'react-dom', 'OT'], function (React, ReactDOM, OT) { | |
// now you can render your React elements | |
ReactDOM.render( | |
React.createElement('p', {}, 'Hello, Opentok!'), | |
document.getElementById('root') | |
); | |
console.log('OT', OT) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment