我正在尝试在我正在创建的phonegap应用程序中实现音频调用.我正在使用PeerJS让2个客户端连接.这部分正在运作.但问题在于为媒体流创建的URL.它看起来像这样:
<audio src="blob:file%3A///6212fd77-7d1e-46ba-9abe-cfe96d414b28"></audio>
Run Code Online (Sandbox Code Playgroud)
而不是像:
<audio src="blob:http%3A///url-to-server.com/6212fd77-7d1e-46ba-9abe-cfe96d414b28"></audio>
Run Code Online (Sandbox Code Playgroud)
这就是为什么两台设备都没有听到任何消息(我正在使用genymotion和我的智能手机进行测试).
但奇怪的是,当我在浏览器和手机中进行测试时,它可以正常工作.当我在笔记本电脑中使用内置麦克风讲话时,我会在手机上听到它.但是当我用手机说话时,笔记本电脑上没有任何声音.
作为参考,当我选择播放媒体流的音频元素时,这就是我所得到的:
<audio src="blob:http%3A//localhost%3A8100/861180b2-2c12-4134-a6da-89fcb40ef372"></audio>
Run Code Online (Sandbox Code Playgroud)
不确定这是否真的是问题.
我正在使用离子来开发应用程序,它可以与crosswalk顺利集成,基本上只是将最近的Chrome浏览器与你的应用程序打包在一起,这样它就可以毫无问题地使用闪亮的新东西.
这是请求麦克风的代码:
function getAudio(successCallback, errorCallback){
navigator.getUserMedia({
audio: true,
video: false
}, successCallback, errorCallback);
}
Run Code Online (Sandbox Code Playgroud)
然后每当有人发起呼叫时我都会打电话:
getAudio(
function(MediaStream){
console.log('now calling ' + to);
var call = peer.call(to, MediaStream);
call.on('stream', onReceiveStream);
});
Run Code Online (Sandbox Code Playgroud)
然后onReceiveStream将媒体流转换为URL,然后将其分配给音频元素:
function onReceiveStream(stream){
var audio = document.querySelector('audio');
audio.src = window.URL.createObjectURL(stream);
audio.onloadedmetadata = function(e){
console.log('now playing the audio');
audio.play();
}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?提前致谢.
更新
似乎真正的问题是无法从手机中捕获音频,因为它在navigator.getUserMedia调用时不会请求访问麦克风.我确认navigator.getUserMedia在使用genymotion进行测试时可以访问.虽然它也没有要求在genymotion中访问.我正在使用recordRTC作为垫片提供者.
更新2
好吧,我放弃了这个.它真的不可能要求麦克风.我现在正在尝试的是PhoneRTC.但我再次陷入困境.我安装插件时它没有建立.有关更多详细信息,请在项目Github页面上查看此问题:https: //github.com/alongubkin/phonertc/issues/151
我正在使用PeerJS,但认为这个问题WebRTC一般都可以,希望你能帮助我:
我正在尝试编写一个简单的点对点文件共享.我使用serialisation: "none"的PeerJS连接DataChannel,因为我只发送纯ArrayBuffers.
对于10mb左右的文件,一切都很好但是我在发送更大的文件(30+ mb)时遇到问题,例如在发送10-20个第一块900mb zip文件连接之后,在同行之间开始投掷Connection is not open. You should listen for the "open" event before sending messages.(Sender旁边)
我的设置:
文件被拖动拖放,Sender用于FileReader以ArrayBuffer64x1024字节(与16x1024没有区别)的块读取它,并且一读取每个块 - 它通过peer.send(ChunkArrayBuffer)发送.
Recieverblob从每个接收到的块创建,在传输完成后创建完整blob的那些并给出用户的链接.
我的对等连接设置:
var con = peer.connect(peerid, {
label: "file",
reliable: true,
serialization: "none"
})
Run Code Online (Sandbox Code Playgroud)
我的发送功能:
function sliceandsend(file, sendfunction) {
var fileSize = file.size;
var name = file.name;
var mime = file.type; …Run Code Online (Sandbox Code Playgroud) 我想访问一些已记录的变量chrome://webrtc-internals/,但我没有在谷歌上找到任何东西 - 甚至没有我能看到的图表的描述.
我特别感兴趣packetsLost,googCurrentDelayMs并且googNacksSent.
为什么我要访问webrtc-internals
我正在编写一个共享视频流的谷歌浏览器应用程序(p2p).它使用peerjs与其他对等体共享流,后者又使用googles webrtc实现.为了使我的应用程序完美,我需要知道何时发生大的延迟.由于我可以看到记录的延迟,chrome://webrtc-internals/我想知道我是否可以通过javascript访问它.
我的猜测是chrome://webrtc-internals/-menu 没有API .
我正在评估PeerJS,以实现一个简单的双人在线游戏.似乎一旦我将id一个玩家的连接转移到另一个玩家的连接,他们就可以通过PeerJS打开一个频道并且很好.
但是如果两个玩家想玩不相识的玩家,那么最优雅的方式是什么呢?有没有办法向PeerJS经纪人询问所有连接客户的列表,可能附加了一些元数据(例如"状态:想要玩")?或者是向所有客户广播的方式?
这是我与 PeerJS 连接的代码:
var peer = new Peer({ key: '[PeerJSID]', debug: 3});
peer.on('open', function(){
$('#my-id').text(peer.id);
});
// Receiving a call
peer.on('call', function(call){
// Answer the call automatically (instead of prompting user) for demo purposes
call.answer(window.localStream);
step3(call);
});
peer.on('error', function(err){
alert(err.message);
// Return to step 2 if error occurs
step2();
});
// Click handlers setup
$(function(){
$('#make-call').click(function(){
// Initiate a call!
var call = peer.call($('#callto-id').val(), window.localStream);
step3(call);
});
$('#end-call').click(function(){
window.existingCall.close();
step2();
});
// Retry if getUserMedia fails
$('#step1-retry').click(function(){
$('#step1-error').hide();
step1();
}); …Run Code Online (Sandbox Code Playgroud) 我的测试应用程序编译正常,但我收到此警告:“关键依赖项:依赖项的请求是一个表达式”
(base) marco@pc01:~/webMatters/vueMatters/PeerJS-VueJS-Test$ npm run serve
> testproject@0.1.0 serve /home/marco/webMatters/vueMatters/PeerJS-VueJS-Test
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
WARNING Compiled with 1 warnings
7:22:25 PM
warning in ./node_modules/peerjs/dist/peerjs.min.js
Critical dependency: the request of a dependency is an expression
App running at:
- Local: http://localhost:8080
- Network: http://ggc.world/
Note that the development build is not optimized.
To create a production build, run npm run build.
Run Code Online (Sandbox Code Playgroud)
我读到它可能依赖于 webpack,但没有找到如何解决它。
这是 webpack.config.js :
{
"mode": "development",
"output": {
"path": __dirname+'/static',
"filename": …Run Code Online (Sandbox Code Playgroud) 我从git-hub获得了以下代码,但我不知道如何使用和执行.
$> npm install peer --->where i want to install this node_module ?
//Run the server:
$> peerjs --port 9000 --key peerjs
or
var PeerServer = require('peer').PeerServer;
var server = new PeerServer({port: 9000, path: '/myapp'});
Run Code Online (Sandbox Code Playgroud)
上述步骤之间有什么区别.何时何地使用这些步骤.
我有 PeerJS 服务器的问题。我从这里使用了“部署到 Heroku”按钮:https : //github.com/peers/peerjs-server
我不知道如何与部署的云连接。我找不到关于 PeerJS Server 的明确文档。
我不知道我的应用程序的主机、端口和路径是什么。
var peer = new Peer('someid', {host: 'localhost', port: 9000, path: '/myapp'});
Run Code Online (Sandbox Code Playgroud)
请指教。
我们一直在使用 PeerJS for web 开发一个 WebRTC 应用程序。
服务器端:NodeJS
客户端:HTML5/CSS/Javascript/Angularjs
我们 90% 在那里,它在 chrome firefox 中运行良好,但在 safari 中不起作用。我知道 safari 不支持 WebRTC。
是否有任何解决方法可以使它像任何插件一样在 safari 中工作?
我的第二个问题是,如果我复制我的网络代码并将其放入 phonegap 或 ionic 中,它是否可以在 Android 和 IOS 中使用。 我的意思是现在我们已经使用 peerJS 进行了一次聊天,它纯粹是一个 javascript 代码,可以在 Android 和 IOS 平台的 phonegap 或 ionic 应用程序中进行聊天
请分享您的想法,非常感谢。谢谢:-)
我正在尝试最简单的例子,直接从他们的网站上提取。这是我的整个 html 文件,代码完全取自https://peerjs.com/index.html:
<script src="https://unpkg.com/peerjs@1.3.1/dist/peerjs.min.js"></script>
<script>
var peer = new Peer();
var conn = peer.connect('another-peers-id');
// on open will be launch when you successfully connect to PeerServer
conn.on('open', function(){
// here you have conn.id
conn.send('hi!');
});
</script>
Run Code Online (Sandbox Code Playgroud)
在 Chrome 和 Edge 中,我在控制台中得到了这个:
peerjs.min.js:64 GET https://0.peerjs.com/peerjs/id?ts=15956160926060.016464029424720694 net::ERR_CONNECTION_REFUSED
Run Code Online (Sandbox Code Playgroud)
在 Firefox 中,我得到了这个:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://0.peerjs.com/peerjs/id?ts=15956162489620.8436734374800061. (Reason: CORS request did not succeed).
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?