我正在尝试通过OTSession发出来自streamCreated
,signal
,streamDestroyed
之类的引用的事件。这样可能吗:
How I think it should work
答案 0 :(得分:1)
来自TokBox的Manik。
您无法通过ref访问事件,因为我们将事件传递到本机层并在安装组件时设置侦听器,但是,您可以像这样监听事件:
import React, { Component } from 'react';
import { View } from 'react-native';
import { OTSession, OTPublisher, OTSubscriber } from 'opentok-react-native';
export default class App extends Component {
constructor(props) {
super(props);
this.apiKey = '';
this.sessionId = '';
this.token = '';
this.sessionEventHandlers = {
streamCreated: event => {
console.log("stream created", event);
},
streamDestroyed: event => {
console.log("stream destroyed", event);
},
};
}
render() {
return (
<View style={{ flex: 1, flexDirection: 'row' }}>
<OTSession apiKey={this.apiKey} sessionId={this.sessionId} token={this.token} eventHandlers={this.sessionEventHandlers}>
<OTPublisher style={{ width: 100, height: 100 }} />
<OTSubscriber style={{ width: 100, height: 100 }} />
</OTSession>
</View>
);
}
}