【发布时间】:2023-03-10 14:31:01
【问题描述】:
我正在尝试使用 opentok-react-native 库构建一个应用程序。
应用运行时,发布者组件变成黑色方块,订阅者组件显示我的摄像头视频。
在日志中,我可以看到流已创建,带有流 ID,并且显然正在运行。但是当我转到我的Tokbox account 时,我在仪表板上看不到任何数据:
这是我当前的代码:https://github.com/victor0402/opentok-demo
重要的部分是:
import React, {Component} from 'react';
import {View} from 'react-native';
import {OT, OTPublisher, OTSession, OTSubscriber} from "opentok-react-native";
export default class App extends Component {
//Publisher token
token = 'TOKEN HERE';
//Routed session ID
session = 'SESSION ID HERE';
apiKey = 'API KEY';
constructor(props) {
super(props);
this.state = {
streamProperties: {},
};
this.publisherProperties = {
publishVideo: true,
publishAudio: true,
cameraPosition: 'front'
};
this.publisherEventHandlers = {
streamCreated: event => {
console.log('publisherEventHandlers: streamCreated.... updating state');
const streamProperties = {
...this.state.streamProperties, [event.streamId]: {
subscribeToAudio: true,
subscribeToVideo: true,
style: {
width: 400,
height: 300,
},
}
};
this.setState({streamProperties});
},
streamDestroyed: event => {
console.log('Publisher stream destroyed!', event);
}
};
this.subscriberProperties = {
subscribeToAudio: true,
subscribeToVideo: true,
};
this.sessionEventHandlers = {
streamCreated: event => {
console.log('sessionEventHandlers : streamCreated');
},
streamDestroyed: event => {
console.log('Stream destroyed!!!!!!', event);
},
};
this.subscriberEventHandlers = {
error: (error) => {
console.log(`There was an error with the subscriber: ${error}`);
},
};
}
render() {
OT.enableLogs(true);
return (
<View>
<OTSession apiKey={this.apiKey} sessionId={this.session} token={this.token}
eventHandlers={this.sessionEventHandlers}>
<OTPublisher
properties={this.publisherProperties}
eventHandlers={this.publisherEventHandlers}
style={{ height: 100, width: 100 }}
/>
<OTSubscriber
properties={this.subscriberProperties}
eventHandlers={this.subscriberEventHandlers}
style={{height: 100, width: 100}}
streamProperties={this.state.streamProperties}
/>
</OTSession>
</View>
);
}
}
那么,我的代码有问题吗? 如何发布视频并在我的帐户仪表板上获取结果和录音?
【问题讨论】:
-
这是在 ios 还是 android 上发生的?
-
@10101010 在安卓 5.1 上
标签: react-native opentok tokbox