我想把库伦托和流星结合起来。在将Node.JS的嵌套回调转换为适当的Meteor服务器代码时,我遇到了问题。
下面是我正在尝试使用Meteor.wrapAsync进行转换的代码:
kurento(args.ws_uri, function(error, client) {
if ( error ) return onError(error);
client.create('MediaPipeline', function(error, pipeline) {
if ( error ) return onError(error);
console.log("Got MediaPipeline");
pipeline.create('RecorderEndpoint', { uri : file_uri }, function(error, recorder) {
if ( error ) return onError(error);
console.log("Got RecorderEndpoint");
pipeline.create('WebRtcEndpoint', function(error, webRtc) {
if ( error ) return onError(error);
console.log("Got WebRtcEndpoint");
webRtc.connect(recorder, function(error) {
if ( error ) return onError(error);
console.log("Connected");
recorder.record(function(error) {
if ( error ) return onError(error);
console.log("record");
webRtc.connect(webRtc, function(error) {
if ( error ) return onError(error);
console.log("Second connect");
});
webRtc.processOffer(offer, function(error, answer) {
if ( error ) return onError(error);
console.log("offer");
return answer;
});
});
});
});
});
});
});我正在尝试使用wrapAsync在流星服务器中编写它,如下所示。
client = Meteor.wrapAsync(kurento,ws_uri);
//client = Meteor.wrapAsync(getKurentoClient);
console.log("got connected to server");
pipeline = Meteor.wrapAsync(client.create,'MediaPipeline');
console.log("Got MediaPipeline");
var webRtc = Meteor.wrapAsync(pipeline.create,'WebRtcEndpoint');
console.log("Got WebRtcEndpoint");
var recorder = Meteor.wrapAsync(pipeline.create,('RecorderEndpoint', {uri: file_uri}));
console.log("Got RecorderEndpoint");
Meteor.wrapAsync(webRtc.connect,recorder);
console.log("Connected recorder");
Meteor.wrapAsync(webRtc.connect,webRtc);
console.log("Connected webRtc");
Meteor.wrapAsync(recorder.record);
console.log("started recording");
var sdpAnswer = Meteor.wrapAsync(webRtc.processOffer,offer);
console.log("sdpAnswer"+sdpAnswer());
return sdpAnswer;每当我尝试这样做时,我都会得到一个输出函数,而不是对象!下面是我最后一个用于查看sdp答案的concole语句的输出。
调用方法'onOffer‘TypeError时的异常:无法调用未定义的方法“应用” I20150722-19:10:15.185(5.5)?在包裹/流星/helpers.js:118:1 I20150722-19:10:15.186(5.5)?在object Object.Meteor.methods.onOffer (app/absimpl.js:90:31) I20150722-19:10:15.186(5.5)?在maybeAuditArgumentChecks (packages/ddp/livedata_server.js:1617:1) I20150722-19:10:15.186(5.5)?在包/ddp/livedata_server.js:648:1 I20150722-19:10:15.186(5.5)?在对象Object._.extend.withValue (包/流星/动力学_nodejs.js:56:1) I20150722-19:10:15.186(5.5)?在包/ddp/livedata_server.js:647:1 I20150722-19:10:15.186(5.5)?在对象Object._.extend.withValue (包/流星/动力学_nodejs.js:56:1) I20150722-19:10:15.186(5.5)?在对象Object._.extend.protocol_handlers.method (packages/ddp/livedata_server.js:646:1) I20150722-19:10:15.186(5.5)?在包/ddp/livedata_server.js:546:1
如何使用Meteor.wrapAsync正确地将回调地狱转换为一个好的同步函数?
发布于 2015-07-22 14:26:16
每个回调需要2行,您要同时声明&调用。(wrapasync)
第一行是创建同步调用。第二行是调用同步调用。
clientSync = Meteor.wrapAsync(client.create, client);
pipeline = clientSync('MediaPipeline');请注意,我没有使用kurento,所以不能详细说明,但是对于一般的wrapAsync布局,这是您想要的。
https://stackoverflow.com/questions/31562770
复制相似问题