问题描述
我遇到了一个非常具体的问题,但我希望人们能为我指出正确的方向,以进行调试或修复.我正在尝试编写一个本地客户端,该客户端可以运行和测试我使用SocketIO构建的网页.
I am having a pretty specific problem but I hope people can point me in the right direction for how to debug or even fix it. I am trying to write a local client which can run and test a webpage I had built which uses SocketIO.
我正在使用命令行选项--web-security = false运行Phantom,因为否则,没有入站或出站连接是合法的,因为我的本地测试仪与我正在测试的网站不属于同一来源(必须修复)在听之前就可以了.
I am running Phantom with the command line option --web-security=false since otherwise no in or out connections are legal as my local tester is not considered part of the same origin as my website I am testing (had to fix that before the listening would work).
使用PhantomJS我无法从SocketIO中获取发射功能.它只是默默地失败而没有任何错误.我知道套接字已有效连接,因为它可以很好地监听传入的事件(因此on()方法有效).我可以在Web浏览器中运行相同的发射代码,并且效果很好.
Using PhantomJS I can't get the emit function from SocketIO to work. It just fails silently without any error. I know the socket is validly connected because it can listen to incoming events just fine (so the on() method works). I can run the same emitting code in a web browser and it works just fine.
有人知道不存在emit()的替代方法吗,或者我可能会修补哪些级别较低的emit()调用的东西,或者接下来应该如何测试?任何帮助表示赞赏.
Does anyone know alternatives to emit(), what lower level things emit() invokes that maybe I could patch, or how I should test things next? Any help is appreciated.
推荐答案
经过大量研究,phantomjs似乎还不支持这种形式的套接字.当应该是新的2.0版本时,应该是这样,但是在那之前,其他选择会更好.我试图找一个垫片,但是没有成功.
After a lot of research it looks like this form of sockets simply aren't yet supported in phantomjs. When the new 2.0 releases they are supposed to be but until then other options are better. I tried to find a shim for a while but was unsuccessful.
最后,我改为使用node.js运行主脚本,建立套接字连接,然后使用phantomjs节点模块进行浏览器交互,而不是将脚本作为纯幻像脚本运行.这意味着api交互逻辑已被推送到节点应用程序,并且幻象代码仅与页面进行交互,但是我能够以这种方式实现测试目标,因此我将其视为成功.
In the end, I instead used node.js to run the main script, make the socket connections and then used the phantomjs node module to do the browser interactions rather than running the script as a pure phantom script. This meant that the api interaction logic got pushed to the node application and the phantom code was just about interacting with the page but I was able to achieve the testing goal this way so I count it as success.
这篇关于SocketIO + PhantomJS发出不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!