em-midori 0.0.7.1 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2f7f8a1b850464054976e3121d2af323f7d262d7
4
- data.tar.gz: 895e02b6b9d960b27ad632aed6914ceb55325b64
3
+ metadata.gz: a8ed2aa28d8f33b3189c8580e3710ee0c9082f24
4
+ data.tar.gz: f72b5ff4d67f06b619776484da4f8581b56c27df
5
5
  SHA512:
6
- metadata.gz: 7b34dccdc4c7bd99483a7a2848ea95668fd24d1c305f720ad112be9aaa18de0a0f9adb35f097701d049a5f782ef3cfa238164789f2f1b24311e185ad8c446ef7
7
- data.tar.gz: fa306bae699e386b308f248151aea2656231c85893daaddc36db3a422375e77c8bfd68a184bdfb0dcafa2e84d88cdef36e966c969d34404e071b1d88c37aaf68
6
+ metadata.gz: 1de935f59439205ea7d3b909410979fe4feade4d3a38a25541ef9ae79b96d82f99598ff274a942dab10ba627168f81473319d7e0822eb350e1e29be7ae0d9ab9
7
+ data.tar.gz: 5663cf9ab2ebbe09dd9c0cde0a36becc8cdc9c9f4809a91bb8957283d0a2aa1676fac04be0f1255045b9320655e0c3c31dd2225036aa08d51cab65e4ea8a41d2
@@ -1,24 +1,41 @@
1
- # Contributor Code of Conduct
1
+ # Contributor Covenant Code of Conduct
2
2
 
3
- As contributors and maintainers of this project, and in the interest of
4
- fostering an open and welcoming community, we pledge to respect all people who
5
- contribute through reporting issues, posting feature requests, updating
6
- documentation, submitting pull requests or patches, and other activities.
3
+ ## Our Pledge
7
4
 
8
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
12
22
 
13
23
  Examples of unacceptable behavior by participants include:
14
24
 
15
- * The use of sexualized language or imagery
16
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
18
28
  * Public or private harassment
19
- * Publishing other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
22
39
 
23
40
  Project maintainers have the right and responsibility to remove, edit, or
24
41
  reject comments, commits, code, wiki edits, issues, and other contributions
@@ -26,24 +43,32 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
26
43
  permanently any contributor for other behaviors that they deem inappropriate,
27
44
  threatening, offensive, or harmful.
28
45
 
29
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
33
54
 
34
- This code of conduct applies both within project spaces and in public spaces
35
- when an individual is representing the project or its community.
55
+ ## Enforcement
36
56
 
37
57
  Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
- reported by contacting a project maintainer at delton@heckpsi.com. All
58
+ reported by contacting the project team at dsh0416@gmail.com. All
39
59
  complaints will be reviewed and investigated and will result in a response that
40
- is deemed necessary and appropriate to the circumstances. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
43
69
 
44
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
- version 1.3.0, available at
46
- [http://contributor-covenant.org/version/1/3/0/][version]
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
47
72
 
48
73
  [homepage]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/lib/em-midori.rb CHANGED
@@ -1,17 +1,20 @@
1
1
  require 'digest/sha1'
2
2
  require 'stringio'
3
3
  require 'eventmachine'
4
+ require 'fiber'
4
5
 
5
- require 'em-midori/version'
6
- require 'em-midori/string'
7
- require 'em-midori/const'
8
- require 'em-midori/define_class'
9
- require 'em-midori/error'
10
- require 'em-midori/clean_room'
11
- require 'em-midori/em_midori'
12
- require 'em-midori/request'
13
- require 'em-midori/response'
14
- require 'em-midori/api'
15
- require 'em-midori/route'
16
- require 'em-midori/server'
17
- require 'em-midori/websocket'
6
+ require_relative 'em-midori/version'
7
+ require_relative 'em-midori/string'
8
+ require_relative 'em-midori/promise'
9
+ require_relative 'em-midori/const'
10
+ require_relative 'em-midori/define_class'
11
+ require_relative 'em-midori/error'
12
+ require_relative 'em-midori/clean_room'
13
+ require_relative 'em-midori/em_midori'
14
+ require_relative 'em-midori/request'
15
+ require_relative 'em-midori/response'
16
+ require_relative 'em-midori/api'
17
+ require_relative 'em-midori/route'
18
+ require_relative 'em-midori/server'
19
+ require_relative 'em-midori/websocket'
20
+ require_relative 'em-midori/eventsource'
data/lib/em-midori/api.rb CHANGED
@@ -191,6 +191,14 @@ class Midori::API
191
191
  }, '')
192
192
  result = -> { clean_room.instance_exec(connection.websocket, *matched, &route.function) }.call
193
193
  return Midori::Response.new
194
+ elsif request.eventsource?
195
+ connection.send_data Midori::Response.new(200, {
196
+ 'Content-Type' => 'text-event-stream',
197
+ 'Cache-Control' => 'no-cache',
198
+ 'Connection' => 'keep-alive'
199
+ }, '')
200
+ result = -> { clean_room.instance_exec(connection.eventsource, *matched, &route.function) }.call
201
+ return Midori::Response.new
194
202
  else
195
203
  result = -> { clean_room.instance_exec(*matched, &route.function) }.call
196
204
  end
@@ -5,4 +5,5 @@ module Midori::Error
5
5
  class NotMasked < StandardError; end
6
6
  class FrameEnd < StandardError; end
7
7
  class PingPongSizeTooLarge < StandardError; end
8
+ class EventSourceTypeError < StandardError; end
8
9
  end
@@ -0,0 +1,13 @@
1
+ class Midori::EventSource
2
+ attr_accessor :connection
3
+
4
+ def initialize(connection)
5
+ @connection = connection
6
+ end
7
+
8
+ def send(data)
9
+ raise Midori::Error::EventSourceTypeError unless data.is_a?String
10
+ @connection.send_data(data.split("\n").map {|str| "data: #{str}\n"}.join + "\n")
11
+ @connection.close_connection_after_writing
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ # Referenced from {Qiita}[http://qiita.com/south37/items/99a60345b22ef395d424]
2
+ class Promise
3
+ def initialize(callback)
4
+ @callback = callback
5
+ end
6
+
7
+ def then(resolve = ->() {}, reject = ->() {})
8
+ @callback.call(resolve, reject)
9
+ end
10
+ end
11
+
12
+ def async_internal(fiber)
13
+ chain = ->(result) {
14
+ return if result.class != Promise
15
+ result.then(->(val) {
16
+ chain.call(fiber.resume(val))
17
+ })
18
+ }
19
+ chain.call(fiber.resume)
20
+ end
21
+
22
+ def async(method_name, &block)
23
+ define_singleton_method method_name, ->(*args) {
24
+ async_internal(Fiber.new {block.call(*args)})
25
+ }
26
+ end
27
+
28
+ def await(promise)
29
+ Fiber.yield promise
30
+ end
@@ -1,24 +1,27 @@
1
1
  module Midori::Server
2
- attr_accessor :request, :api, :websocket
2
+ attr_accessor :request, :api, :websocket, :eventsource
3
3
 
4
4
  def initialize(api)
5
5
  @api = api
6
6
  @request = Midori::Request.new
7
7
  @websocket = Midori::WebSocket.new(self)
8
+ @eventsource = Midori::EventSource.new(self)
8
9
  end
9
10
 
10
11
  def receive_data(data)
11
- start_time = Time.now
12
- data = StringIO.new(data)
13
- port, ip = Socket.unpack_sockaddr_in(get_peername)
14
- @request.ip = ip
15
- @request.port = port
16
- if @request.parsed?
17
- websocket_request(data)
18
- else
19
- receive_new_request(data)
20
- end
21
- puts "#{@request.ip} - - [#{Time.now.inspect}] \"#{@request.method} #{@request.path} #{@request.protocol}\" #{@response.status} #{(Time.now.to_f - start_time.to_f).round(5)}".green
12
+ ->() {async_internal(Fiber.new do
13
+ start_time = Time.now
14
+ data = StringIO.new(data)
15
+ port, ip = Socket.unpack_sockaddr_in(get_peername)
16
+ @request.ip = ip
17
+ @request.port = port
18
+ if @request.parsed?
19
+ websocket_request(data)
20
+ else
21
+ receive_new_request(data)
22
+ end
23
+ puts "#{@request.ip} - - [#{Time.now.inspect}] \"#{@request.method} #{@request.path} #{@request.protocol}\" #{@response.status} #{(Time.now.to_f - start_time.to_f).round(5)}".green
24
+ end)}.call
22
25
  end
23
26
 
24
27
  def receive_new_request(data)
@@ -1,3 +1,3 @@
1
1
  module Midori
2
- VERSION = '0.0.7.1'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
data/logo.png ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: em-midori
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7.1
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - HeckPsi Lab
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-11 00:00:00.000000000 Z
11
+ date: 2016-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: eventmachine
@@ -51,6 +51,8 @@ files:
51
51
  - lib/em-midori/define_class.rb
52
52
  - lib/em-midori/em_midori.rb
53
53
  - lib/em-midori/error.rb
54
+ - lib/em-midori/eventsource.rb
55
+ - lib/em-midori/promise.rb
54
56
  - lib/em-midori/request.rb
55
57
  - lib/em-midori/response.rb
56
58
  - lib/em-midori/route.rb
@@ -58,6 +60,7 @@ files:
58
60
  - lib/em-midori/string.rb
59
61
  - lib/em-midori/version.rb
60
62
  - lib/em-midori/websocket.rb
63
+ - logo.png
61
64
  homepage: https://github.com/heckpsi-lab/em-midori
62
65
  licenses:
63
66
  - MIT