Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0ee4311

Browse files
committed
[CHG]区分日志类型, 优化播放日志展示,支持自定义错误回调捕获获取播放地址错误
1 parent cd07d02 commit 0ee4311

File tree

1 file changed

+38
-22
lines changed

1 file changed

+38
-22
lines changed

ezuikit.js

Lines changed: 38 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,11 @@
205205
var getRealUrl = this.getRealUrl(playParams);
206206
/**是否自动播放 */
207207
if (isPromise(getRealUrl)) {
208-
getRealUrl.then(function () {
208+
getRealUrl.then(function (data) {
209209
var initDecoder = _this.initDecoder(playParams);
210210
if (isPromise(initDecoder) && (playParams.autoplay !== false)) {
211-
initDecoder.then(function () {
212-
_this.play({ handleError: playParams.handleError });
211+
initDecoder.then(function (data) {
212+
_this.play({ handleError: playParams.handleError, handleSuccess: playParams.handleSuccess });
213213
})
214214
}
215215
})
@@ -337,6 +337,10 @@
337337
}
338338
}
339339
};
340+
// 日志
341+
EZUIPlayer.prototype.log = function (msg, className) {
342+
this.emit('log', msg, className);
343+
};
340344

341345
EZUIPlayer.prototype.getRealUrl = function (playParams) {
342346
var _this = this;
@@ -358,13 +362,21 @@
358362
// _this.opt.currentSource = realUrl;
359363
resolve(realUrl);
360364
} else {
361-
resolve('get realURL error')
365+
// 将错误信息捕获到用户自定义错误回调中
366+
if (playParams && playParams.handleError) {
367+
playParams.handleError(data);
368+
}
369+
reject(JSON.stringify(data));
362370
throw new Error('获取播放token失败');
363371
}
364372
}
365373
var nodeError = function (error) {
366-
console.log("getdecoder url from api error", error);
367-
throw new Error('获取播放token失败');
374+
// 将错误信息捕获到用户自定义错误回调中
375+
if(playParams && playParams.handleError){
376+
playParams.handleError(error);
377+
}
378+
reject(JSON.stringify(error))
379+
throw new Error('获取播放token失败', 'error');
368380
}
369381
// 向API请求真实地址
370382
var apiUrl = apiDomain + "/api/lapp/live/url/ezopen";
@@ -399,14 +411,21 @@
399411
}
400412
request(nodeUrl, 'GET', '', '', nodeSuccess, nodeError);
401413
} else {
402-
resolve('get realURL error')
414+
// 将错误信息捕获到用户自定义错误回调中
415+
if (playParams && playParams.handleError) {
416+
playParams.handleError(data);
417+
}
418+
reject(JSON.stringify(data), 'error')
403419
//throw new Error('获取播放设备信息失败');
404420
}
405421
/**参数容错处理 end*/
406422
}
407423
var apiError = function (error) {
408-
console.log("getdecoder url from api error", error);
409-
resolve('get realURL error')
424+
// 将错误信息捕获到用户自定义错误回调中
425+
if (playParams && playParams.handleError) {
426+
playParams.handleError(error);
427+
}
428+
reject(JSON.stringify(error))
410429
//throw new Error('获取播放设备信息失败');
411430
}
412431
var isHttp = 'false';
@@ -436,15 +455,17 @@
436455
});
437456
var getRealUrlPromiseObj = Promise.all(promiseTaskList)
438457
.then(function (result) {
458+
// 获取真实地址成功后,赋值到opt属性中
439459
_this.opt.sources = result;
440460
_this.opt.currentSource = result[0];
441461
})
442462
.catch(function (err) {
463+
_this.log("获取真实地址错误" + JSON.stringify(err), 'error')
443464
})
444465
return getRealUrlPromiseObj;
445466
} else {
446467
if (!this.opt.currentSource) {
447-
this.log('未找到合适的播放URL');
468+
this.log('未找到合适的播放URL', 'error');
448469
return;
449470
}
450471
var me = this;
@@ -512,7 +533,6 @@
512533
that.video.load();
513534
that.tryPlay(data.data);
514535
} else {
515-
console.log("平台获取播放地址错误")
516536
that.log('data: ' + JSON.stringify(data));
517537
throw new Error(data.msg);
518538
return;
@@ -669,10 +689,6 @@
669689
this.hls = hls;
670690
};
671691

672-
// 日志
673-
EZUIPlayer.prototype.log = function (msg) {
674-
this.emit('log', msg);
675-
};
676692

677693
// 初始化ckplayer
678694
EZUIPlayer.prototype.initCKPlayer = function (url) {
@@ -904,20 +920,21 @@
904920
if (!params || typeof params.index === 'undefined') {
905921
_this.opt.sources.forEach(function (item, index) {
906922
_this.jSPlugin.JS_Play(getPlayParams(item).websocketConnectUrl, { playURL: getPlayParams(item).websocketStreamingParam }, index).then(function () {
907-
console.log("realplay success", index);
923+
_this.log('播放成功,当前播放第' + (index + 1) + '路');
908924
// 默认开启声音
909925
// 默认开启第一路声音
910926
if (index === 0) {
911-
_this.log("默认开启第一路声音");
927+
_this.log("默认开启第1路声音");
912928
setTimeout(() => {
913929
_this.jSPlugin.JS_OpenSound(0);
914930
}, 100)
915931
}
932+
// 播放成功回调
916933
if (params && params.handleSuccess) {
917934
params.handleSuccess();
918935
}
919936
}, function (err) {
920-
console.log("realplay failed", err.oError);
937+
_this.log('播放失败' + JSON.stringify(err), 'error');
921938
if (params && params.handleError) {
922939
var errorInfo = JSON.parse(_this.errorCode).find(function (item) { return item.detailCode.substr(-4) == err.oError.errorCode })
923940
params.handleError({ retcode: err.oError.errorCode, msg: errorInfo ? errorInfo.description : '其他错误' });
@@ -927,11 +944,10 @@
927944
} else {
928945
params.index.forEach(function (item, index) {
929946
_this.jSPlugin.JS_Play(getPlayParams(_this.opt.sources[item]).websocketConnectUrl, { playURL: getPlayParams(_this.opt.sources[item]).websocketStreamingParam }, item).then(function () {
930-
console.log("realplay success", index);
947+
_this.log('播放成功,当前播放第' + (index + 1) + '路')
931948
// 默认开启第一路声音
932949
if (index === 0) {
933950
_this.log("默认开启第一路声音");
934-
console.log("默认开启第一路声音")
935951
setTimeout(() => {
936952
_this.jSPlugin.JS_OpenSound(0);
937953
}, 100)
@@ -940,7 +956,7 @@
940956
params.handleSuccess();
941957
}
942958
}, function (err) {
943-
console.log("realplay failed", err.oError);
959+
_this.log('播放失败' + JSON.stringify(err), 'error');
944960
if (params && params.handleError) {
945961
var errInfo = err.oError;// 包装错误码
946962
params.handleError(errInfo);
@@ -977,9 +993,9 @@
977993
_this.jSPlugin.JS_Resize(playParams.width || 600, playParams.height || 400);
978994
}
979995
_this.log("初始化解码器----完成");
980-
_this.log("开始设置秘钥");
981996
var validateCode = _this.opt.validateCode;
982997
if (validateCode) {
998+
_this.log("开始设置秘钥");
983999
_this.jSPlugin.JS_SetSecretKey(0, validateCode);
9841000
}
9851001
resolve('200 OK')

0 commit comments

Comments
 (0)