- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在我的应用程序中使用了 atmosphere 框架。
https://github.com/Atmosphere/atmosphere
我扩展了 AbstractReflectorAtmosphereHandler 类并实现了
-onRequest
-destroy
-onstatechanged
方法。
当客户端想要向服务器发送消息时:
subSocket.push(jQuery.stringifyJSON({ data: "blahblah", source:"client" }));
onRequest函数被调用;然而消息
Object message = atmosphereResource.getAtmosphereResourceEvent().getMessage();
为空。
比我尝试使用每次调用的 onstatechanged
(1) The remote connection gets closed, either by a browser or a proxy
(2) The remote connection reach its maximum idle time (AtmosphereResource.suspend))
(3) Everytime a broadcast operation is executed (broadcaster.broadcast)
然而即使在过滤掉 1 和 2 之后
public void onStateChange(AtmosphereResourceEvent event)
throws IOException {
if (source.equals("client") && !event.isResumedOnTimeout() && !event.isResuming()){
System.out.println("message form client");
System.out.println(message.toString());
} else {
//normal onstatechanged code from AbstractReflectorAtmosphereHandler
}
但是消息会随机打印 2 到 4 次。它应该只被调用一次。
所以我的问题是:我能否在 onRequest 方法中访问消息,或者为什么 onStateChange 被调用了这么多次。
编辑:根据 jF 给出的答案,我已经能够访问 onRequest 函数内的消息。 (不过我不确定这是否是他真正的意思)。
public void onRequest(AtmosphereResource resource) throws IOException {
//Object message = resource.getAtmosphereResourceEvent().getMessage(); //is empty why?
//leave connection open
resource.suspend();
BufferedReader reader = resource.getRequest().getReader();
Object message = reader.readLine();
if (message !=null){
System.out.println("**onRequest: "+message.toString());
}
}
最佳答案
您需要在您的 onStateChange
中读取请求的主体:
atmosphereResource.getRequest().getReader (or getInputStream).
关于java - onStateChange 在 Atmosphere 框架中被多次调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15524521/
直到大约两周前,我一切都运转良好。我没有更改任何代码。 function loadYtVideo(video, advert, advert_link, splash, splash_link){
当您更改 YouTube 视频 ID 时,相同代码的行为会有所不同。 问题是,当您拉动进度 slider 时,它会在一个视频上触发 onStateChange 事件,但不会在另一个视频上触发。检查下面
player = new YT.Player(A, { videoId: z.videoId, height: z.he
我遇到了 YouTube 播放器 OnStateChange 未触发的问题。我看过其他帖子,它们不太适合我的情况,因为我可能使用不同的(chromeless javascript)版本。 HTML:
我有一个 iframe,可以在开始时间和结束时间之间播放视频。当到达结束时间时(case 0),我想加载几乎相同的 URL(在 autoplay=0 处有所不同)。 问题是 OnStateChange
我正在为 Chrome 构建一个笔记应用程序,我希望该应用程序在用户停止输入时保存其进度,但我无法让 chrome.idle 触发状态更改 chrome.idle.setDetectionInterv
引用问题:http://jsfiddle.net/yusaf/VVEY9/55/ 当视频播放器状态发生变化时 onStateChange(0) 即视频结束时,我将如何隐藏 .pause 元素并添加一个
我在我的应用程序中使用了 atmosphere 框架。 https://github.com/Atmosphere/atmosphere 我扩展了 AbstractReflectorAtmospher
在Flutter中,有没有像onStateChanged这样的方法,在页面状态发生变化时调用? setState(() { widget._loadCompleted = true; widg
我只是一个js初学者,所以可能我只是理解不正确。但是,当您之前使用 History.stateObj 更改状态时,当您点击浏览器的后退/前进按钮时,window.onstatechange 不应该触发
我想使用 Youtube API 提供的 onStateChange 事件来收听视频的结尾,然后在播放器中播放一个新视频。但是,由于某种原因,这似乎是不可能的。 function onPlayerSt
我正在使用 Youtube iFrame API 开发一个小应用程序,让您可以与其他人同步观看视频。 onStateChange 事件让我知道播放器是否播放或暂停了视频,但它是否包含有关该操作是否通过
我的javascript: function onYouTubePlayerReady() { playerObj = document.getElementById("player_embed"
请告诉我我哪里做错了。 我使用的是 History.js HTML5 版本。当我的网址类似于 example.com/?param=1 我把它改成 example.com/?param=2 使用 Hi
我有两个 colorbox 弹出框,每个框都显示一个 YouTube 视频。当他们玩完后,我试图让他们自动关闭 colorbox 窗口。下面的代码在 Firefox 中完美运行,但在 IE 中我无法使
我正在使用 iframe YouTube API,我想跟踪事件,例如,在用户开始和停止视频时将数据发送到谷歌分析。 我看了https://developers.google.com/youtube/
这个问题在这里已经有了答案: YouTube iframe player API - OnStateChange not firing (2 个回答) 7年前关闭。 直到美国东部标准时间下午 6 点左
这个问题已经有答案了: YouTube iFrame API 'onStateChange' not firing in Firefox (1 个回答) 已关闭 9 年前。 我只是想在 YouTube
我正在用 C++ 开发 Firefox 扩展我想获取我已为 STATE_IS_NETWORK 获得 STATE_STOP 的选项卡窗口的选项卡索引。即我想找到与请求关联的选项卡索引。 如何获取? 请帮
我集成了 History.js,这段代码在 URL 更改时运行: History.Adapter.bind(window,'statechange',function(){ var State
我是一名优秀的程序员,十分优秀!