Skip to content

Commit

Permalink
Merge pull request #6 from jobseekerltd/jsm-860-update-name
Browse files Browse the repository at this point in the history
fix: Avoid nameclash with gem parser
  • Loading branch information
keang authored Dec 7, 2021
2 parents 1d03b2c + b3718de commit 98a5f58
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/socket_io.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'socket_io/web_socket'
require 'rest_client'
require 'json'
require 'parser'
require 'socket_parser'

module SocketIO

Expand Down Expand Up @@ -65,7 +65,7 @@ def connect_transport
def start_recieve_loop
@thread = Thread.new() do
while data = @transport.receive()
decoded = Parser.decode(data)
decoded = SocketParser.decode(data)
case decoded[:type]
when '0'
@on_disconnect.call if @on_disconnect
Expand Down
4 changes: 2 additions & 2 deletions lib/parser.rb → lib/socket_parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Parser
module SocketParser
@regexp = /([^:]+):([0-9]+)?(\+)?:([^:]+)?:?([\s\S]*)?/

# returns hash as {type: '1', id: '1', end_point: '4', data: [{key: value}]}
Expand All @@ -10,4 +10,4 @@ def self.decode(string)
end
end

end
end
2 changes: 1 addition & 1 deletion socketio-client.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)

Gem::Specification.new do |s|
s.name = "socketio-client"
s.version = "0.1.0"
s.version = "0.1.1"
s.authors = ["Lyon"]
s.email = ["lyon@delorum.com"]
s.homepage = "http://github.com/lyondhill/socket.io-ruby-client"
Expand Down
22 changes: 0 additions & 22 deletions spec/parser_spec.rb

This file was deleted.

22 changes: 22 additions & 0 deletions spec/socket_parser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require 'socket_io'

describe SocketParser do

it 'should be able to decode all valid messages' do
described_class.decode("0").should == {type: "0"}
described_class.decode("1::").should == {type: "1", id: nil, end_point: nil, data: ""}
described_class.decode("2::").should == {type: "2", id: nil, end_point: nil, data: ""}
described_class.decode("3:::hay you").should == {type: "3", id: nil, end_point: nil, data: "hay you"}
described_class.decode("4:::{\"can\":\"youcall\"}").should == {type: "4", id: nil, end_point: nil, data: "{\"can\":\"youcall\"}"}
described_class.decode("5:::hay you").should == {type: "5", id: nil, end_point: nil, data: "hay you"}
described_class.decode("6:::").should == {type: "6", id: nil, end_point: nil, data: ""}
described_class.decode("7:::there is an error").should == {type: "7", id: nil, end_point: nil, data: "there is an error"}
described_class.decode("8:::").should == {type: "8", id: nil, end_point: nil, data: ""}
end

it "should give a disconnect if bad input" do
described_class.decode("hay dude").should == {type: "0"}
described_class.decode("9").should == {type: "0"}
end

end

0 comments on commit 98a5f58

Please sign in to comment.