Comments (13)
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.otPublisher = React.createRef();
}
getPublisherStats(){
this.otPublisher.getPublisher().getStats((err, stats) => console.log(err, stats));
}
render() {
return <OTPublisher ref={this.otPublisher} />;
}
}
from opentok-react.
I think you can also do something like this:
class MyComponent extends React.Component {
constructor(props) {
super(props);
this.otPublisher = React.createRef();
}
getPublisherStats(){
this.otPublisher.getPublisher().getStats((err, stats) => console.log(err, stats));
}
render() {
return <OTPublisher ref={(instance) => { this.otPublisher = instance }} />;
}
}
Using the instance inside the ref function (ref={(instance) => { this.otPublisher = instance }}
), you access the OTPublisher
directly.
from opentok-react.
From https://github.com/opentok/opentok-react#otpublisher-component
To facilitate this the Publisher instance is exposed via the getPublisher() component method. You should always call this method to get the latest Publisher instance instead of keeping a reference to it as it's possible for the Publisher instance to change, leaving you with a stale reference.
and
There are plans to support more Publisher properties but for now you will have to call getPublisher() to retrieve the Publisher instance and make the necessary changes yourself.
It's not ideal but this was low priority when first implemented. Feel free to submit a PR if you'd like this improved.
from opentok-react.
Yes that tells you to use the getPublisher
method of OTPublisher
component instance in order to change the OT.Publisher instance, what I am saying is there is no documentation or examples on how getPublisher
is actually supposed to be used.
How am I supposed to call getPublisher
from the OTPublisher
instance? Neither of the below works:
render(){
const p = <OTPublisher {....props} />;
console.log(p.getPublisher());
}
-> getPublisher is not a function
render(){
const p = new OTPublisher(...props);
console.log(p.getPublisher());
}
-> getPublisher is not a function
I am only able to find the method being used twice in the entire project, both times it is being used in the context of enzyme tests where enzyme makes the instance easily accessible with wrapper.instance()
: https://github.com/opentok/opentok-react/search?q=getPublisher&unscoped_q=getPublisher
I'm happy to submit a PR to add documentation on how it is intended to be used, but first I need to understand that myself.
from opentok-react.
Good point. I use it in this SO answer: https://stackoverflow.com/a/49889581/545726
from opentok-react.
The above does not work. It results in this.otPublisher
having a value of
{current: OTPublisher}
Which does not have a .getPublisher()
method.
from opentok-react.
So then use current
: this.otPublisher.current.getPublisher()
You can figure this out on your own by looking up the documentation for React.createRef
from opentok-react.
this.otPublisher.current
appears to be an actual instance of OTPublisher
and also lacks a getPublisher
method, I have no idea whether the current
property will actually be dynamically returning a live reference of the current OTPublisher
that is being managed under the hood or just the initial one I already have a reference of
from opentok-react.
@wyqydsyq getPublisher
should be on the prototype. Did you try calling it? It comes from here: https://github.com/opentok/opentok-react/blob/master/src/OTPublisher.js#L61
from opentok-react.
@wyqydsyq did you found the solution, because i am having the same issue.
from opentok-react.
I was facing a similar issue, but with the subscriber. In order to have access to the object that getSubscriber
returns I had to wait for componentDidMount
but also wait for the next animation frame.
So having this:
componentDidMount() {
requestAnimationFrame(() => {
console.log('>>>>> 2: ', this.otSubscriber.current.getSubscriber());
});
console.log('>>>>> 1: ', this.otSubscriber.current.getSubscriber())
}
1 prints null, but 2 prints the subscriber object. This makes sense, according to React lifecycle and how componentDidMount
works. So make sure you're not accessing your refs object too early.
from opentok-react.
@ashifa454 the suggestion made by @aiham ended up working for me, just had to use .current
as mentioned above. I'll try to get around to submitting a PR to add this to the docs
from opentok-react.
We've gone ahead and documented this. Closing the issue!
from opentok-react.
Related Issues (20)
- Changing audioSource doesn't work
- Is this project being maintained? HOT 4
- Opentok JS sdk considers media volume instead of phone volume.
- Doesn't work with react v17 HOT 4
- Firefox and Safari compatibility
- In Safari on iOS 15, the video is rotated and flickered, if the app is run in the background
- Timeout error and please find attached screen for the react api
- What about Feature: [WebRTC] Deprecate and Remove Plan B ?
- Opentok publisher video always showing endless loading on Safari in IPhone
- How can we show network disconnected message to both connected users?
- Support stricter Content Security Policies
- prop-types-15.5.10.tgz: 4 vulnerabilities (highest severity is: 7.5)
- lodash-4.17.4.tgz: 7 vulnerabilities (highest severity is: 9.1)
- How to stream system audio along with screenshare
- Share only a portion of screen
- Option to mute microphone of the publisher through a button
- applyVideoFilter not working HOT 1
- cannot screen share
- sessionDisconnected, sessionReconnected, sessionReconnecting events not triggered on internet connection change HOT 2
- applyVideoFilter: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opentok-react.