在Opentok-react-native中,如何获取客户端连接、断开等各种事件信息
In Opentok-react-native, how do I get various events information like client connected, disconnected and so on
我进行了很多搜索,但无法在 opentok-react-native library like when user has connected, disconnected, reconnecting and so on. I even found the documentation for 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>
);}
此处为 TokBox 开发人员布道师。
要通过 OTSession
组件设置事件侦听器,请像这样使用 eventHandlers
属性:
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>
);
}
}
我还继续在回购中提交了 issue 以改进 OTSession
组件的文档。
我进行了很多搜索,但无法在 opentok-react-native library like when user has connected, disconnected, reconnecting and so on. I even found the documentation for 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>
);}
此处为 TokBox 开发人员布道师。
要通过 OTSession
组件设置事件侦听器,请像这样使用 eventHandlers
属性:
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>
);
}
}
我还继续在回购中提交了 issue 以改进 OTSession
组件的文档。