简体   繁体   English

传递的参数未明确说明javascript Chrome扩展

[英]Parameter passed without explicitly stating javascript Chrome extension

So this example chrome extension calls a selector for media streams and then the gotStream(stream) clearly is looking for a parameter of a mediaObject. 因此,此示例chrome扩展程序调用媒体流的选择器,然后gotStream(stream)显然正在寻找mediaObject的参数。 However, when the gotStream function is passed in as the second parameter to navigator.webkitGetUserMedia no parameter is passed in. It merely remains states the function name. 但是,当将gotStream函数作为第二个参数传递给navigator.webkitGetUserMedia不会传递任何参数。它仅保留函数名称的状态。

Here is the code 这是代码

function gotStream(stream) {
  console.log("Received local stream");
  var video = document.querySelector("video");
  video.src = URL.createObjectURL(stream);
  localstream = stream;
  stream.onended = function() { console.log("Ended"); };
}

function getUserMediaError() {
  console.log("getUserMedia() failed.");
}

function onAccessApproved(id) {
  if (!id) {
    console.log("Access rejected.");
    return;
  }
  navigator.webkitGetUserMedia({
      audio:false,
      video: { mandatory: { chromeMediaSource: "desktop",
                            chromeMediaSourceId: id } }
  }, gotStream, getUserMediaError);
}

I've seen these kinds of calls before and I just don't get how they work, please help. 我以前见过这类电话,但是我不知道它们的工作方式,请帮忙。

Is there an error of some sorts, or you just don't understand how that works? 是否存在某种错误,或者您只是不了解其工作原理?

navigator.webkitGetUserMedia expects 3 arguments . navigator.webkitGetUserMedia 需要3个参数 One for configuration data, one for a function to call on success (a success callback ) and one to call on error. 一个用于配置数据,一个用于函数调用成功(成功回调 ),另一个用于调用错误。

Note that it expects a function . 请注意,它需要一个function This code passes a reference to the function by name; 该代码按名称传递对该函数的引用; it will be called with the appropriate parameter (from within webkitGetUserMedia ). 将使用适当的参数(从webkitGetUserMedia内部)调用它。

Consider this code, it works in the same manner: 考虑下面的代码,它以相同的方式工作:

 function hello(subject) { alert("Hello, " + subject + "!"); } function passWorldTo(callback) { callback("world"); } passWorldTo(hello); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM