示例app的源码,看起来也有些复杂,不容易懂。写文章帮助理解记忆。
一、启动脚本:/home/oem/git/owt-server/dist-debug/bin/daemon.sh :
cd ${OWT_HOME}/apps/current_app/
nohup nice -n ${OWT_NICENESS} node . \
/home/oem/git/owt-server/dist-debug/apps/current_app/package.json:
"main": "samplertcservice.js",
在apps/current_app/目录,启动的是samplertcservice.js
samplertcservice.js使用nodejs 的 express / spdy框架,创建端口3001 3004监听服务,处理http请求。
icsREST = require('./rest');
// http请求的处理,都是调用 icsREST.API
app.get('/rooms', function(req, res) {
'use strict';
icsREST.API.getRooms(pageOption, function(rooms) {
res.send(rooms);
}, function(err) {
res.send(err);
});
});
二,目录结构
/home/oem/git/owt-server/dist-debug/apps/current_app/public/index.html
<script src="scripts/owt.js" type="text/javascript"></script>
<script src="scripts/index.js" type="text/javascript"></script>
<script src="scripts/rest-sample.js" type="text/javascript"></script>
<script language="JavaScript">
runSocketIOSample();
下左图是源文件目录,下右图是chrome获取并解析的目录结构。说明owt.js实际上打包里src/sdk目录的javascript文件。
三,打开视频流程
//创建Owt.Conference.ConferenceClient()对象
https://192.168.1.106:3004/scripts/src/sdk/conference/client.js
/*The ConferenceClient handles PeerConnections between client and server. For conference controlling, please refer to REST API guide.*/
export const ConferenceClient = function(config, signalingImpl) {
file:///home/oem/git/owt-server/dist-debug/apps/current_app/public/scripts/index.js
const runSocketIOSample = function() {
conference = new Owt.Conference.ConferenceClient();
// publish操作
https://192.168.1.106:3004/scripts/src/sdk/conference/channel.js
_createPeerConnection() {
this.pc = new RTCPeerConnection(pcConfiguration);
async publish(stream, options, videoCodecs) {
this._createPeerConnection();
file:///home/oem/git/owt-server/dist-debug/apps/current_app/public/scripts/owt.js
function publish(_x3, _x4, _x5) {
return _publish.apply(this, arguments);
}
https://192.168.1.106:3004/scripts/src/sdk/conference/client.js
this.publish = function(stream, options, videoCodecs) {
return peerConnectionChannel.publish(stream, options, videoCodecs);
};
file:///home/oem/git/owt-server/dist-debug/apps/current_app/public/scripts/index.js
// Publish with options.
conference.publish(localStream, publishOption).then(publication => {
publicationGlobal = publication;
mixStream(myRoom, publication.id, 'common', serverUrlBase)
publication.addEventListener('error', (err) => {
console.log('Publication error: ' + err.error.message);
});
});