motion-net-service 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +9 -0
- data/Gemfile +5 -0
- data/Rakefile +14 -0
- data/app/app_delegate.rb +22 -0
- data/lib/motion-net-service.rb +5 -0
- data/lib/motion-net-service/net_service.rb +73 -0
- data/lib/motion-net-service/net_service_browser.rb +47 -0
- data/lib/motion-net-service/version.rb +3 -0
- data/motion-net-service.gemspec +19 -0
- data/resources/Default-568h@2x.png +0 -0
- metadata +93 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
$:.unshift("/Library/RubyMotion/lib")
|
3
|
+
require 'motion/project'
|
4
|
+
require "bundler/gem_tasks"
|
5
|
+
Bundler.setup
|
6
|
+
Bundler.require
|
7
|
+
|
8
|
+
$:.unshift("./lib/")
|
9
|
+
require './lib/motion-net-service'
|
10
|
+
|
11
|
+
Motion::Project::App.setup do |app|
|
12
|
+
# Use `rake config' to see complete project settings.
|
13
|
+
app.name = 'MotionNetService'
|
14
|
+
end
|
data/app/app_delegate.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
class AppDelegate
|
2
|
+
def application(application, didFinishLaunchingWithOptions:launchOptions)
|
3
|
+
@service = NetService.new(:name => "foobar", :port => 8080).tap do |ns|
|
4
|
+
ns.on_did_publish do
|
5
|
+
puts "HELLO"
|
6
|
+
end
|
7
|
+
ns.on_did_not_resolve do |error|
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
@service.publish
|
12
|
+
|
13
|
+
p "SEARCHING NOW."
|
14
|
+
@n = NetServiceBrowser.search('_ssh._tcp') do |service, more_coming|
|
15
|
+
s = service.instance_variable_get(:@net_service)
|
16
|
+
p "name: #{s.name}, addresses: #{s.addresses.first}"
|
17
|
+
p "SERVICE FOUND: #{s.hostName}"
|
18
|
+
p "MORE COMING: #{more_coming}"
|
19
|
+
end
|
20
|
+
true
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class NetService
|
2
|
+
def initialize(options = {})
|
3
|
+
default_options = {
|
4
|
+
domain: "",
|
5
|
+
type: "_http._tcp.",
|
6
|
+
}
|
7
|
+
options.merge!(default_options)
|
8
|
+
|
9
|
+
if options[:net_service]
|
10
|
+
@net_service = options[:net_service]
|
11
|
+
else
|
12
|
+
@net_service = NSNetService.alloc.initWithDomain(
|
13
|
+
options[:domain],
|
14
|
+
type:options[:type],
|
15
|
+
name:options[:name],
|
16
|
+
port:options[:port]
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
@net_service.setDelegate(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.from_ns_net_service(ns_net_service)
|
24
|
+
new(:net_service => ns_net_service)
|
25
|
+
end
|
26
|
+
|
27
|
+
def publish
|
28
|
+
@net_service.publish
|
29
|
+
end
|
30
|
+
|
31
|
+
def resolve(timeout = 1, &block)
|
32
|
+
on_did_resolve_address(&block) if block
|
33
|
+
@net_service.resolveWithTimeout(timeout)
|
34
|
+
end
|
35
|
+
|
36
|
+
[
|
37
|
+
:on_will_publish, :on_did_not_publish, :on_did_publish, :on_will_resolve, :on_did_not_resolve,
|
38
|
+
:on_did_resolve_address, :on_did_update_txt_record_data, :on_did_stop
|
39
|
+
].each do |callback|
|
40
|
+
define_method callback do |&block|
|
41
|
+
instance_variable_set("@#{callback}", block)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
protected
|
46
|
+
def netServiceWillPublish(sender)
|
47
|
+
@on_publish.call if @on_publish
|
48
|
+
end
|
49
|
+
|
50
|
+
def netService(sender, didNotPublish:errors)
|
51
|
+
@on_did_not_publish.call(errors) if @on_did_not_publish
|
52
|
+
end
|
53
|
+
|
54
|
+
def netServiceDidPublish(sender)
|
55
|
+
@on_did_publish.call if @on_did_publish
|
56
|
+
end
|
57
|
+
|
58
|
+
def netServiceWillResolve(sender)
|
59
|
+
@on_will_resolve.call if @on_will_resolve
|
60
|
+
end
|
61
|
+
|
62
|
+
def netService(sender, didNotResolve:errors)
|
63
|
+
@on_did_not_resolve.call(errors) if @on_did_not_resolve
|
64
|
+
end
|
65
|
+
|
66
|
+
def netServiceDidResolveAddress(sender)
|
67
|
+
@on_did_resolve_address.call if @on_did_resolve_address
|
68
|
+
end
|
69
|
+
|
70
|
+
def netServiceDidStop(sender)
|
71
|
+
@on_did_stop.call if @on_did_stop
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class NetServiceBrowser
|
2
|
+
def initialize(search_type, options={})
|
3
|
+
default_options = {
|
4
|
+
search_type: search_type,
|
5
|
+
domain: ""
|
6
|
+
}
|
7
|
+
@options = options.merge(default_options)
|
8
|
+
|
9
|
+
@net_service_browser = NSNetServiceBrowser.alloc.init
|
10
|
+
@net_service_browser.setDelegate(self)
|
11
|
+
end
|
12
|
+
|
13
|
+
[
|
14
|
+
:on_will_search,
|
15
|
+
:on_did_find_domain, :on_did_remove_domain, :on_did_find_service, :on_did_remove_service,
|
16
|
+
:on_did_not_search, :on_did_stop_search
|
17
|
+
].each do |callback|
|
18
|
+
define_method callback do |&block|
|
19
|
+
instance_variable_set("@#{callback}", block)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.search(search_type, options={}, &block)
|
24
|
+
NetServiceBrowser.new(search_type, options).tap do |browser|
|
25
|
+
browser.search(&block)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def search(&block)
|
30
|
+
if block
|
31
|
+
on_did_find_service do |service, more_coming|
|
32
|
+
service.resolve do
|
33
|
+
block.call(service, more_coming)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
@net_service_browser.searchForServicesOfType @options[:search_type], inDomain: @options[:domain]
|
38
|
+
end
|
39
|
+
|
40
|
+
def netServiceBrowser(netServiceBrowser, didFindService: service, moreComing: moreComing)
|
41
|
+
@on_did_find_service.call(NetService.from_ns_net_service(service), moreComing) if @on_did_find_service
|
42
|
+
end
|
43
|
+
|
44
|
+
def netServiceBrowser(netServiceBrowser, didNotSearch: errorInfo)
|
45
|
+
@on_did_not_search.call(errorInfo) if @on_did_not_search
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/motion-net-service/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "motion-net-service"
|
6
|
+
s.version = MotionNetService::VERSION
|
7
|
+
s.authors = ["Jamie van Dyke", "Thomas Kadauke"]
|
8
|
+
s.email = ["jamie@fearoffish.com", "thomas.kadauke@googlemail.com"]
|
9
|
+
s.homepage = "https://github.com/fearoffish/motion-net-service"
|
10
|
+
s.summary = "Wrapper around NSNetService for RubyMotion"
|
11
|
+
s.description = "Wrapper around NSNetService for RubyMotion."
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($\)
|
14
|
+
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
15
|
+
s.require_paths = ["lib"]
|
16
|
+
|
17
|
+
s.add_dependency 'bubble-wrap'
|
18
|
+
s.add_development_dependency 'rake'
|
19
|
+
end
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: motion-net-service
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jamie van Dyke
|
9
|
+
- Thomas Kadauke
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2013-03-29 00:00:00 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: bubble-wrap
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: *id001
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: *id002
|
38
|
+
description: Wrapper around NSNetService for RubyMotion.
|
39
|
+
email:
|
40
|
+
- jamie@fearoffish.com
|
41
|
+
- thomas.kadauke@googlemail.com
|
42
|
+
executables: []
|
43
|
+
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files: []
|
47
|
+
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- Rakefile
|
52
|
+
- app/app_delegate.rb
|
53
|
+
- lib/motion-net-service.rb
|
54
|
+
- lib/motion-net-service/net_service.rb
|
55
|
+
- lib/motion-net-service/net_service_browser.rb
|
56
|
+
- lib/motion-net-service/version.rb
|
57
|
+
- motion-net-service.gemspec
|
58
|
+
- resources/Default-568h@2x.png
|
59
|
+
homepage: https://github.com/fearoffish/motion-net-service
|
60
|
+
licenses: []
|
61
|
+
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
hash: -2733567938995359562
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
hash: -2733567938995359562
|
82
|
+
segments:
|
83
|
+
- 0
|
84
|
+
version: "0"
|
85
|
+
requirements: []
|
86
|
+
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.19
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Wrapper around NSNetService for RubyMotion
|
92
|
+
test_files: []
|
93
|
+
|