请教在html中是否可以通过nodejs直接调用摄

请教在html中是否可以通过nodejs直接调用摄,第1张

是通过浏览器web的方式获取还是本地应用获取.

如果是浏览器web的方式 可以查找webrtc 相关的js库.比如module: easyrtc等

如果是本地获取.由于nodejs 的官方文档并没有 *** 作摄像头或者麦克风之类的 api.可能需要通过调用 C或C++的扩展来实现对这些硬件的控制.

var http = require("http"),

url = require("url"),

path = require("path"),

fs = require("fs")

http.createServer(function (req, res) {

var pathname=__dirname+url.parse(req.url).pathname

if (path.extname(pathname)=="") {

pathname+="/"

}

if (pathname.charAt(pathname.length-1)=="/"){

pathname+="index.html"

}

path.exists(pathname,function(exists){

if(exists){

switch(path.extname(pathname)){

case ".html":

res.writeHead(200, {"Content-Type": "text/html"})

break

case ".js":

res.writeHead(200, {"Content-Type": "text/javascript"})

break

case ".css":

res.writeHead(200, {"Content-Type": "text/css"})

break

case ".gif":

res.writeHead(200, {"Content-Type": "image/gif"})

break

case ".jpg":

res.writeHead(200, {"Content-Type": "image/jpeg"})

break

case ".png":

res.writeHead(200, {"Content-Type": "image/png"})

break

default:

res.writeHead(200, {"Content-Type": "application/octet-stream"})

}

fs.readFile(pathname,function (err,data){

res.end(data)

})

} else {

res.writeHead(404, {"Content-Type": "text/html"})

res.end("<h1>404 Not Found</h1>")

}

})

}).listen(8080, "127.0.0.1")

console.log("Server running at http://127.0.0.1:8080/")


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7059718.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-01
下一篇 2023-04-01

发表评论

登录后才能评论

评论列表(0条)

保存