我进行了很多搜索,但找不到任何方法在opentok-react-native库中找到各种回调,例如当用户连接,断开连接,重新连接时等等。我什至在OTSession的文档中找到了描述各种事件的文档,但是这些文档不起作用。这些所有事件都一起被调用。
视频通话效果很好,但是我想根据这些事件执行各种操作
renderVideoView(data) {
console.log("rendering view view,, ", data);
return (
<View
style={{
flex: 1,
flexDirection: "row",
backgroundColor: R.Colors.COLOR_VIDEO_BACKGROUND
}}
>
<OTSession
ref={ref => {
this.OTSession = ref;
}}
connectionCreated={ console.log("connection created")}
connectionDestroyed={ console.log("connection destroyed")}
sessionConnected={ console.log("Client connect to a session")}
sessionDisconnected={
console.log("Client disConnect to a session")
}
sessionReconnected={() => console.log("session reconnected")}
apiKey={this.apiKey}
sessionId={data.sessionId}
token={data.token}
>
<OTSubscriber style={{ width: "100%", height: "100%" }} />
<View style={styles.publisherStyle}>
<OTPublisher
properties={{
publishAudio: this.state.publishAudio,
cameraPosition: this.state.cameraPosition,
publishVideo: this.state.publishVideo
}}
style={{ width: 90, height: 107, padding: 2 }}
/>
</View>
{this.renderViewAtCenter()}
{this.renderBottomView()}
{this.renderTopView()}
</OTSession>
</View>
);}
答案 0 :(得分:1)
此处是TokBox开发人员的传播者。
要通过{
"errors": {
"EndDate": [
"EndDate must be equal to or later than StartDate."
]
},
"title": "One or more validation errors occurred.",
"status": 400,
"traceId": "0HLKANM74IPHB:00000005"
}
组件设置事件监听器,请像这样使用OTSession
道具:
eventHandlers
我也继续前进,并在仓库中提交了issue,以改善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 = {
connectionCreated: event => {
console.log("connection created", event);
},
connectionDestroyed: event => {
console.log("connection destroyed", event);
},
sessionConnected: event => {
console.log("Client connect to a session")
},
sessionDisconnected: event => {
console.log("Client disConnect to a session")
},
sessionReconnected: event => {
console.log("session reconnected")
},
};
}
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>
);
}
}
组件的文档。