{"id":4107,"date":"2014-05-01T10:02:11","date_gmt":"2014-05-01T01:02:11","guid":{"rendered":"http:\/\/www.techscore.com\/blog\/?p=4107"},"modified":"2018-11-14T16:33:51","modified_gmt":"2018-11-14T07:33:51","slug":"websocket-%e4%bd%bf%e3%81%a3%e3%81%a6-chat-%e3%81%9d%e3%81%97%e3%81%a6%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e9%80%9a%e7%9f%a5%ef%bc%81%ef%bc%81","status":"publish","type":"post","link":"https:\/\/www.techscore.com\/blog\/2014\/05\/01\/websocket-%e4%bd%bf%e3%81%a3%e3%81%a6-chat-%e3%81%9d%e3%81%97%e3%81%a6%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e9%80%9a%e7%9f%a5%ef%bc%81%ef%bc%81\/","title":{"rendered":"WebSocket \u4f7f\u3063\u3066 Chat \u305d\u3057\u3066\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\uff01\uff01"},"content":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u6751\u4e0a\u3067\u3059\u3002<\/p>\n<p>gmail\u3092\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u4f7f\u3063\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u8a2d\u5b9a\u306b\u300c\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\u300d\u3068\u3044\u3046\u306e\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u3092ON\u306b\u3059\u308b\u3068\u30bf\u30b9\u30af\u30d0\u30fc\u306e\u3042\u305f\u308a\u306b\u30d4\u30b3\u30f3\u3068\u901a\u77e5\u304c\u304d\u307e\u3059\u3002<br \/>\n\u4eca\u65e5\u306f\u305d\u308c\u3092\u3061\u3087\u3053\u3063\u3068\u3084\u3063\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<h1>Web Notifications<\/h1>\n<p>\u30d4\u30b3\u30f3\u3068\u304f\u308b\u300c\u30a2\u30ec\u300d\u306f<a href=\"http:\/\/www.w3.org\/TR\/notifications\/\">WebNotifications<\/a>\u3068\u8a00\u3046\u3089\u3057\u3044\u3067\u3059\u3002<\/p>\n<pre class=\"lang:html decode:true\"><input id=\"notification\" type=\"button\" value=\"\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\" \/><script type=\"text\/javascript\">\/\/ <![CDATA[\r\n  $(\"#notification\").click(function() {\r\n    Notification.requestPermission(function(permission){});\r\n    var notify = new Notification('\u901a\u77e5');\r\n  });\r\n\/\/ ]]><\/script><\/pre>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u3068\u30bf\u30f3\u3092\u62bc\u3057\u305f\u6642\u306b\u901a\u77e5\u8868\u793a\u306e\u8a31\u53ef\u304c\u6c42\u3081\u3089\u308c\u3066\u3001\u8a31\u53ef\u3059\u308b\u3068\u901a\u77e5\u3055\u308c\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u610f\u5916\u306b\u7c21\u5358\u3067\u3059\u3002<\/p>\n<h1>WebSocket\u3067Chat<\/h1>\n<p>\u901a\u77e5\u304c\u3042\u3063\u305f\u3089\u4fbf\u5229\u306a\u30b5\u30fc\u30d3\u30b9\u3063\u3066\u3044\u3046\u3068Chat\u3067\u3059\u3002<br \/>\nChat\u3068\u3044\u3048\u3070WebSocket\uff01\uff01<\/p>\n<p>\u3068\u3044\u3046\u3053\u3068\u3067WebSocket\u4f7f\u3063\u305fChat\u30a2\u30d7\u30ea\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002<br \/>\n\u3053\u308c\u3082\u7279\u306b\u96e3\u3057\u3044\u3053\u3068\u306f\u306a\u304f\u3001\u7c21\u5358\u306b\u3064\u304f\u308c\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/washiiku.hatenablog.com\/entry\/2013\/11\/13\/235027\">\u3053\u3053<\/a>\u3068\u304b<a href=\"http:\/\/ithijikata.hatenablog.com\/entry\/2014\/03\/06\/021948\">\u3053\u3053<\/a>\u306e\u30da\u30fc\u30b8\u3092\u53c2\u7167\u3057\u306a\u304c\u3089\u4f5c\u3063\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\nGitHub\u3067\u3082\u30bd\u30fc\u30b9\u3092\u516c\u958b\u3055\u308c\u3066\u307e\u3059\u3002<\/p>\n<p>\u4f5c\u6210\u3067\u304d\u305f\u3089<\/p>\n<pre class=\"lang:ruby decode:true\">rails s<\/pre>\n<p>\u3063\u3067\u30b5\u30fc\u30d0\u30fc\u8d77\u52d5\u3067\u3059\u3002<\/p>\n<p>\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u5165\u529b\u3059\u308b\u3068\u4e0b\u90e8\u306b\u30e1\u30c3\u30bb\u30fc\u30b8\u304c\u9806\u6b21\u8ffd\u52a0\u3055\u308c\u3066\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001\u5225\u306ePC\u3067\u958b\u304f\u3068\u540c\u3058\u3088\u3046\u306b\u8ffd\u52a0\u3055\u308c\u3066\u3044\u3063\u3066\u3044\u308b\u306e\u304c\u308f\u304b\u308b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<h1>\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5<\/h1>\n<p>\u3067\u306f\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\u3092\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u4e0a\u8a18\u306e\u30b5\u30a4\u30c8\u306e\u30b5\u30f3\u30d7\u30eb\u3069\u304a\u308a\u306b\u4f5c\u308b\u3068app\/assets\/javascripts\u306bchat.js.coffee\u304c\u3042\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u3053\u3053\u306b\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u307e\u3057\u3087\u3046\u3002<br \/>\n2\u884c\u307b\u3069\u3067\u3059\u3002<\/p>\n<p>\u307e\u3059\u3001\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\u306e\u8a31\u53ef\u3092\u3059\u308b\u90e8\u5206\u3067\u3059\u304c\u3001\u30dc\u30bf\u30f3\u304c\u62bc\u4e0b\u3055\u308c\u308b\u3068\u3053\u308d\u306b\u4ee5\u4e0b\u306e\u8a18\u8ff0\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:html decode:true\">Notification.requestPermission()<\/pre>\n<p>\u30b5\u30f3\u30d7\u30eb\u3067\u306fsendMessage\u3042\u305f\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"lang:html decode:true\">  sendMessage: (event) =&gt;\r\n    # Notification\u306e\u8a31\u53ef\r\n    Notification.requestPermission()\r\n    # \u30b5\u30fc\u30d0\u5074\u306bsend_message\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u9001\u4fe1\r\n    # \u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u30c7\u30fc\u30bf\u3092\u6307\u5b9a\r\n    user_name = $('#username').val()\r\n    msg_body = $('#msgbody').val()\r\n    @dispatcher.trigger 'new_message', { name: user_name , body: msg_body }\r\n    $('#msgbody').val('')<\/pre>\n<p>\u6b21\u306b\u901a\u77e5\u3092\u3059\u308b\u90e8\u5206\u3067\u3059\u3002<br \/>\n\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u304c\u30e1\u30c3\u30bb\u30fc\u30b8\u3092\u53d7\u4fe1\u3059\u308b\u3068\u3053\u308d\u306b\u4ee5\u4e0b\u306e\u30b3\u30fc\u30c9\u3092\u66f8\u3044\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:html decode:true\">notification = new Notification \"#{message.name} : #{message.body}\"<\/pre>\n<p>\u30b5\u30f3\u30d7\u30eb\u3067\u306f\u3001receiveMessage\u3042\u305f\u308a\u3067\u3059\u3002<\/p>\n<pre class=\"lang:html decode:true\">  receiveMessage: (message) =&gt;\r\n    # \u53d7\u3051\u53d6\u3063\u305f\u30c7\u30fc\u30bf\u3092append\r\n    $('#chat').append \"#{message.name} : #{message.body}\"\r\n    notification = new Notification \"#{message.name} : #{message.body}\"<\/pre>\n<p>\u3053\u308c\u3067OK\u3067\u3059\uff01\uff01<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2014\/04\/websocketxchatxwebnotifications.png\" rel=\"facebox\" rel=\"attachment wp-att-4124\"><img loading=\"lazy\" class=\"alignnone size-medium wp-image-4124\" alt=\"websocketxchatxwebnotifications\" src=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2014\/04\/websocketxchatxwebnotifications-300x276.png\" width=\"300\" height=\"276\" srcset=\"https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2014\/04\/websocketxchatxwebnotifications-300x276.png 300w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2014\/04\/websocketxchatxwebnotifications-1024x942.png 1024w, https:\/\/www.techscore.com\/blog\/wp\/wp-content\/uploads\/2014\/04\/websocketxchatxwebnotifications.png 1133w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>\u4e0a\u306e\u30d6\u30e9\u30a6\u30b6\u306f\u30ed\u30fc\u30ab\u30eb\u306eFirefox\u3067\u4e0b\u306e\u30d6\u30e9\u30a6\u30b6\u306fVirtualBox\u4e0a\u306eLinux\u306eFirefox\u3067\u3059\u3002<br \/>\n\u30a8\u30a8\u611f\u3058\u306b\u3067\u304d\u3066\u304a\u308a\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u3053\u3093\u306b\u3061\u306f\u6751\u4e0a\u3067\u3059\u3002<\/p>\n<p>gmail\u3092\u30d6\u30e9\u30a6\u30b6\u304b\u3089\u4f7f\u3063\u3066\u3044\u308b\u4eba\u304c\u3044\u308b\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u8a2d\u5b9a\u306b\u300c\u30c7\u30b9\u30af\u30c8\u30c3\u30d7\u901a\u77e5\u300d\u3068\u3044\u3046\u306e\u304c\u3042\u3063\u3066\u3001\u305d\u308c\u3092ON\u306b\u3059\u308b\u3068\u30bf\u30b9\u30af\u30d0\u30fc\u306e\u3042\u305f\u308a\u306b\u30d4\u30b3\u30f3\u3068\u901a\u77e5\u304c\u304d\u307e\u3059\u3002<br \/><a href=\"https:\/\/www.techscore.com\/blog\/2014\/05\/01\/websocket-%e4%bd%bf%e3%81%a3%e3%81%a6-chat-%e3%81%9d%e3%81%97%e3%81%a6%e3%83%87%e3%82%b9%e3%82%af%e3%83%88%e3%83%83%e3%83%97%e9%80%9a%e7%9f%a5%ef%bc%81%ef%bc%81\/\">\u7d9a\u304d\u3092\u8aad\u3080...<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[18],"tags":[20,22,47],"_links":{"self":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4107"}],"collection":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/comments?post=4107"}],"version-history":[{"count":21,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4107\/revisions"}],"predecessor-version":[{"id":4170,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/posts\/4107\/revisions\/4170"}],"wp:attachment":[{"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/media?parent=4107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/categories?post=4107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.techscore.com\/blog\/wp-json\/wp\/v2\/tags?post=4107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}