0
(function ($) {

    var webcam = {

    "extern": null, // external select token to support jQuery dialogs
    "append": true, // append object instead of overwriting

    "width": 320,
    "height": 240,

    "mode": "callback", // callback | save | stream

    "swffile": "../Webcam_Plugin/jscam_canvas_only.swf",
    "quality": 85,

    "debug":    function () {},
    "onCapture":    function () {},
    "onTick":   function () {},
    "onSave":   function () {},
    "onLoad":   function () {}
    };

    window["webcam"] = webcam;

    $["fn"]["webcam"] = function(options) {

    if (typeof options === "object") {
        for (var ndx in webcam) {
        if (options[ndx] !== undefined) {
            webcam[ndx] = options[ndx];
        }
        }
    }

    var source = '<object id="XwebcamXobjectX" type="application/x-shockwave-flash" data="'+webcam["swffile"]+'" width="'+webcam["width"]+'" height="'+webcam["height"]+'"><param name="movie" value="'+webcam["swffile"]+'" /><param name="FlashVars" value="mode='+webcam["mode"]+'&amp;quality='+webcam["quality"]+'" /><param name="allowScriptAccess" value="always" /></object>';

    if (null !== webcam["extern"]) {
        $(webcam["extern"])[webcam["append"] ? "append" : "html"](source);
    } else {
        this[webcam["append"] ? "append" : "html"](source);
    }

    var run = 3;
    (_register = function() {
        var cam = document.getElementById('XwebcamXobjectX');

        if (cam && cam["capture"] !== undefined) {

        /* Simple callback methods are not allowed :-/ */
        webcam["capture"] = function(x) {
            try {
            return cam["capture"](x);
            } catch(e) {}
        }
        webcam["save"] = function(x) {
            try {
            return cam["save"](x);
            } catch(e) {}
        }
        webcam["setCamera"] = function(x) {
            try {
            return cam["setCamera"](x);
            } catch(e) {}
        }
        webcam["getCameraList"] = function() {
            try {
            return cam["getCameraList"]();
            } catch(e) {}
        }
        webcam["pauseCamera"] = function() {
            try {
            return cam["pauseCamera"]();
            } catch(e) {}
        }       
        webcam["resumeCamera"] = function() {
            try {
            return cam["resumeCamera"]();
            } catch(e) {}
        }
        webcam["onLoad"]();
        } else if (0 == run) {
        webcam["debug"]("error", "Flash movie not yet registered!");
        } else {
        /* Flash interface not ready yet */
        run--;
        window.setTimeout(_register, 1000 * (4 - run));
        }
    })();
    }

})(jQuery);

以上是我用来访问系统网络摄像头的功能。当我在 localhost 上使用它时它工作正常,但是当将它放在服务器上然后通过 Intranet 访问时就会出现问题。我找不到修复它的原因。请帮助我。

本地主机

本地主机

内联网

前两个图像是我在 localhost 上使用我的代码时的图像。它工作正常,因为我能够访问网络摄像头。

问题陈述: 最后一张图片是我尝试通过服务器执行相同操作的图片。由图像打开的网络摄像头完全消失了。只出现一个白色屏幕,即使我通过网络摄像头拍摄照片,白色图像也只保存在服务器上,而不是正确的原始图像。

4

2 回答 2

0

出于安全原因,您必须通过 Https 为站点提供服务才能访问相机。

于 2018-06-28T09:31:42.793 回答
0
var webcam = {

    "extern": null, // external select token to support jQuery dialogs
    "append": true, // append object instead of overwriting

    "width": 320,
    "height": 240,

    "mode": "callback", // callback | save | stream

    "swffile": "../Webcam_Plugin/jscam_canvas_only.swf",
    "quality": 85,

    "debug":    function () {},
    "onCapture":    function () {},
    "onTick":   function () {},
    "onSave":   function () {},
    "onLoad":   function () {}
    };

    window["webcam"] = webcam;

    $["fn"]["webcam"] = function(options) {

    if (typeof options === "object") {
        for (var ndx in webcam) {
        if (options[ndx] !== undefined) {
            webcam[ndx] = options[ndx];
        }
        }
    }

    var source = '<object id="XwebcamXobjectX" type="application/x-shockwave-flash" data="'+webcam["swffile"]+'" width="'+webcam["width"]+'" height="'+webcam["height"]+'"><param name="movie" value="'+webcam["swffile"]+'" /><param name="FlashVars" value="mode='+webcam["mode"]+'&amp;quality='+webcam["quality"]+'" /><param name="allowScriptAccess" value="always" /></object>';

    if (null !== webcam["extern"]) {
        $(webcam["extern"])[webcam["append"] ? "append" : "html"](source);
    } else {
        this[webcam["append"] ? "append" : "html"](source);
    }

    var run = 3;
    (_register = function() {
        var cam = document.getElementById('XwebcamXobjectX');

        if (cam && cam["capture"] !== undefined) {

        /* Simple callback methods are not allowed :-/ */
        webcam["capture"] = function(x) {
            try {
            return cam["capture"](x);
            } catch(e) {}
        }
        webcam["save"] = function(x) {
            try {
            return cam["save"](x);
            } catch(e) {}
        }
        webcam["setCamera"] = function(x) {
            try {
            return cam["setCamera"](x);
            } catch(e) {}
        }
        webcam["getCameraList"] = function() {
            try {
            return cam["getCameraList"]();
            } catch(e) {}
        }
        webcam["pauseCamera"] = function() {
            try {
            return cam["pauseCamera"]();
            } catch(e) {}
        }       
        webcam["resumeCamera"] = function() {
            try {
            return cam["resumeCamera"]();
            } catch(e) {}
        }
        webcam["onLoad"]();
        } else if (30 == run) {
        webcam["debug"]("error", "Flash movie not yet registered!");
        } else {
        /* Flash interface not ready yet */
        run--;
        window.setTimeout(_register, 1000 * (4 - run));
        }
    })();
    }

})(jQuery);
于 2020-12-09T05:24:48.710 回答