有没有办法检测哪个设备(摄像头、麦克风)处于活动状态MediaStream?
我当前正在开发的应用程序只是简单地查询这样的流并将其附加到一个<video/>元素:
const stream = await navigator.mediaDevices.getUserMedia({ audio: true, video: true })\n\nconst el = document.querySelector("video")\nel.srcObject = stream\n\nconsole.log(stream.getTracks())\n// MediaStreamTrack { kind: "audio", id: "{000d071e-f936-42d8-872e-a568cd96cc2d}", label: "USB Audio Device Mono", \xe2\x80\xa6 }\n\xe2\x80\x8b// MediaStreamTrack { kind: "video", id: "{186427d5-b04a-4906-9177-1a088c5d4e0a}", label: "C922 Pro Stream Webcam", \xe2\x80\xa6 \nRun Code Online (Sandbox Code Playgroud)\n下一步是让用户能够更改摄像头/麦克风。其基本代码是:
\nconst devices = await navigator.mediaDevices.enumerateDevices()\nconsole.log(devices)\n// MediaDeviceInfo { deviceId: "yQx5+MN7znbmkE0tV98jJHpvqrUaa6Gv5WIXF52jj0s=", kind: "videoinput", label: "C922 Pro Stream Webcam", \xe2\x80\xa6 }\n\xe2\x80\x8b// MediaDeviceInfo { deviceId: "dIjwtaOGQbjT2HOqfJ4xjzjXBwBxz4CEeX3a2fn0ZgA=", kind: "audioinput", label: "USB Audio Device …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种在Rails应用程序中应用一些外部CSS框架的通用方法.这些框架通常定义一组应该用于某些HTML元素的类名.
考虑jQuery UI.要获得一致的表单样式,您可能会这样:
# in a view
<% form_for @foo do |f| %>
...
<%= f.text_field :bar, :class => ['ui-widget', 'ui-widget-content', 'ui-widget-container', 'ui-corner-all'] %>
or
<%= f.text_field :bar, :class => 'ui-widget ui-widget-content ui-widget-container ui-corner-all' %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
对每个输入字段执行此操作根本不是DRY.
甚至像帮助方法一样
# in application_helper.rb
def jquery_ui_classes
'ui-widget ui-widget-content ui-widget-container ui-corner-all'
end
# in a view
<%= f.text_field :bar, :class => jquery_ui_classes %>
Run Code Online (Sandbox Code Playgroud)
要么
# in application_helper.rb
def jquery_text_field(form_builder, method, opts = {})
ui = ['ui-widget', 'ui-widget-content', 'ui-widget-container', 'ui-corner-all']
klass = [opts.delete(:class), …Run Code Online (Sandbox Code Playgroud) 我有以下密封课.我正试图将列表作为一个返回ReadOnlyCollection.尝试了几件事,但我没有掌握这一点.那么如何将列表返回或转换为只读集合?
public sealed class UserValues
{
private readonly List<UserValue> _Values = new List<UserValue>();
public ReadOnlyCollection<UserValues> Values
{
get
{
return _Values;
}
}
}
Run Code Online (Sandbox Code Playgroud) 翻译某些字段的DRY方式是什么?
在我的RESTful视图中,我有一些重复的片段,就像在show-view中一样:
...
<dt><%= t("activerecord.attributes.user.firstname") %></dt>
<dd><%= @user.firstname %></dd>
...
Run Code Online (Sandbox Code Playgroud)
现在,我不是t("activerecord.attributes.user.attr_name")一遍又一遍地写,而是只想写t(:attr_name)(类似于f.label :firstname表格视图).
基本上,这应该不是问题(至少对于RESTful视图而言),因为I18n模块可以查询controller方法来推断模型名称,然后猜测正确的翻译字符串.
我的问题:有没有人对这种方法有实际经验?甚至还有RubyGem吗?或者:有没有陷阱,我没想到?
internationalization abbreviation method-call ruby-on-rails-3
我正在为Actionscript 3寻找一个功能齐全的AOP库.
到目前为止我注意到的以下项目,但他们似乎都遇到了问题:
有谁知道更好的解决方案?或者有没有人在Actionscript 3中有过AOP的经验?
最好的祝福,
汤姆
我正在尝试使用来自不同文件的类.
something.rb
class Something
def initialize
end
def getText
'Some example text'
end
end
Run Code Online (Sandbox Code Playgroud)
another.rb
class Another
end
somethingVar = Something.new
puts somethingVar.getText
Run Code Online (Sandbox Code Playgroud)
这给了我错误
/usr/bin/ruby -e $stdout.sync=true;$stderr.sync=true;load($0=ARGV.shift) /home/chris/RubymineProjects/untitled1/another.rb
/home/chris/RubymineProjects/untitled1/another.rb:4:in `<top (required)>': uninitialized constant Something (NameError)
from -e:1:in `load'
from -e:1:in `<main>'
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我有一个ruby进程,它使用amqp gem从RabbitMQ队列中消耗msgs,如下所示:
require "bundler/setup"
require "amqp"
require 'eventmachine'
require 'em-http'
AMQP.start(:host => $AMQP_URL) do |connection|
@channel ||= AMQP::Channel.new(connection)
@queue ||= @channel.queue("results")
puts " [*] Waiting for messages. "
@queue.subscribe do |body|
http = EventMachine::HttpRequest.new(URL).post :body => body
http.callback {
# do something
}
http.errback {
$LOG.error "[errorback] -> #{http.error}"
}
end
end
Run Code Online (Sandbox Code Playgroud)
现在URL很慢,队列有很多消息(> 30K),我在日志中遇到了这个错误:
**[errorback] -> unable to create new socket: Too many open files**
Run Code Online (Sandbox Code Playgroud)
任何帮助都将受到高度赞赏,因为我一直在努力寻找如何解决它,但根本没有任何结果.
提前致谢
ruby ×2
abbreviation ×1
amqp ×1
aop ×1
c# ×1
css ×1
eventmachine ×1
formbuilder ×1
frameworks ×1
getusermedia ×1
javascript ×1
mediastream ×1
method-call ×1
rabbitmq ×1