Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS: remove Ti.Network.TCPSocket #11362

Merged
merged 5 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion apidoc/Titanium/Network/BonjourBrowser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ methods:
summary: Conduct a search for Bonjour services matching the type and domain specified during creation
- name: stopSearch
summary: Halt an ongoing search
events:

events:
- name: updatedservices
summary: Fired when the discovered services list is updated
properties:
Expand All @@ -36,9 +36,12 @@ properties:
- name: domain
summary: The domain the browser is searching in
type: String
default: "local."
- name: isSearching
summary: Whether or not the browser is currently searching
type: Boolean
default: false
- name: serviceType
summary: The type of the service the browser searches for
type: String
default: null
148 changes: 139 additions & 9 deletions apidoc/Titanium/Network/BonjourService.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,41 +11,171 @@ description: |
service and wish to close the socket it uses, it is strongly recommended that you stop
the service first. When a window which publishes a Bonjour service is closed, you must
stop the service if the associated socket is also to be closed, or if it is no longer
necessary to publish. Unlike other network operations, Bonjour service resolution and
publishing is synchronous, so be aware that your code may block while resolution is going
on. In particular, you may wish to display UI elements indicating background activity
before beginning resolution.
necessary to publish. Bonjour service resolution and publishing is asynchronous.
extends: Titanium.Proxy
since: "1.2.0"
platforms: [iphone, ipad]
methods:
- name: publish
summary: Publish a Bonjour service to the network. Only works if isLocal is TRUE
summary: Asynchronously publish a Bonjour service to the network. Only works if isLocal is TRUE
parameters:
- name: socket
summary: a TCPSocket object to associate with the Bonjour service.
type: Object
type: Titanium.Network.Socket.TCP
- name: callback
summary: Asynchronous callback function to receive the result of the publish operation
optional: true
type: Callback<Error, Boolean>
- name: resolve
summary: Resolve a Bonjour service from the network. Must be done before attempting to access the service's socket information, if a remote service. You cannot resolve a locally published service.
summary: Asynchronously resolve a Bonjour service from the network. Must be done before attempting to access the service's socket information, if a remote service. You cannot resolve a locally published service.
parameters:
- name: timeout
summary: the timeout for service resolution, in seconds. Optional, default is 120s.
default: 120
optional: true
type: Number
- name: callback
summary: Asynchronous callback function to receive the result of the resolve operation
optional: true
type: Callback<Error, Boolean>
- name: stop
summary: Halts publication of a service.
summary: Asynchronously halts a currently running attempt to publish or resolve a service.
parameters:
- name: callback
summary: Asynchronous callback function to receive the result of the stop operation
optional: true
type: Callback<Error, Boolean>
properties:
- name: domain
summary: the domain of the service
type: String
- name: isLocal
summary: whether or not the service is local to the device
type: Boolean
default: true
- name: name
summary: the name of the service
type: String
- name: socket
summary: the TCPSocket object that is used to connect to the service
type: Object
type: Titanium.Network.Socket.TCP
- name: type
summary: the type of the service
type: String

events:
- name: publish
summary: Fired when the service has been published (or errored).
properties:
- name: code
type: Number
summary: Error code
- name: error
type: String
summary: Error message
- name: success
type: Boolean
summary: Reports if the publish operation was successful
- name: source
type: Titanium.Network.BonjourService
summary: the service whose publish operation was completed/errored.
- name: resolve
summary: Fired when the service has been resolved (or errored). If successful, the [socket](Titanium.Network.BonjourService.socket) property should now be available.
properties:
- name: code
type: Number
summary: Error code
- name: error
type: String
summary: Error message
- name: success
type: Boolean
summary: Reports if the resolve operation was successful
- name: source
type: Titanium.Network.BonjourService
summary: the service whose resolve operation was completed/errored.
- name: stop
summary: Fired when a service's publish or resolution was stopped via <Titanium.Network.BonjourService.stop>
properties:
- name: code
type: Number
summary: Error code
- name: error
type: String
summary: Error message
- name: success
type: Boolean
summary: Reports if the stop operation was successful
- name: source
type: Titanium.Network.BonjourService
summary: the service whose publish or resolve operation was stopped.

examples:
- title: Resolve local HTTP/TCP services
example: |
The following code excerpt looks for http-based TCP zeroconf services on the local network.
It then attempts to resolve the service, establishing a socket that can be used for communications.

// Create the Bonjour Browser (looking for http)
var httpBonjourBrowser = Ti.Network.createBonjourBrowser({
serviceType: '_http._tcp',
domain: 'local'
});

// Handle updated services
httpBonjourBrowser.addEventListener('updatedservices', function (e) {
for (var service of e.services) {
// callback style
service.resolve(120, (err, success) => {
console.log(service.socket);
console.log(service.socket.port);
console.log(service.socket.host);
});
}
});

// Start searching
httpBonjourBrowser.search();

- title: Create and Publish a local HTTP/TCP service
example: |
The following code excerpt creates a zeroconf bonjour service and publishes it out to the local network.
A TCP Socket is used to handle listening for clients and communicating.

// Create the Bonjour Service
var localService = Ti.Network.createBonjourService({
name: 'example',
type: '_test._tcp',
domain: 'local.'
});

// Create the socket we'll tie to the service
var bonjourSocket = Ti.Network.Socket.createTCP({
host: '127.0.0.1',
port: 40401,
accepted: function (e) {
// Here you handle clients connecting
Ti.API.info("Listening socket <" + e.socket + "> accepted incoming connection <" + e.inbound + ">");
e.inbound.write(Ti.createBuffer({
value: 'You have been connected to a listening socket.\r\n'
}));
e.inbound.close();
},
error: function (e) {
// handle errors...
Ti.API.error("Socket <" + e.socket + "> encountered error when listening");
Ti.API.error(" error code <" + e.errorCode + ">");
Ti.API.error(" error description <" + e.error + ">");
}
});

// Make the socket listen for connections
bonjourSocket.listen();

// Make the socket accept incoming connections
bonjourSocket.accept({ timeout: 10000 });

// Publish the service
localService.publish(bonjourSocket, fnction (err, bool) {
// Now you can find the service on your network (including using a Ti.Network.BonjourBrowser)
});
9 changes: 9 additions & 0 deletions apidoc/Titanium/Network/Network.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ methods:
- name: createTCPSocket
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: Use [Titanium.Network.Socket.createTCP](Titanium.Network.Socket.createTCP) instead.
summary: |
Legacy method to create and return an instance of <Titanium.Network.TCPSocket>.
Expand Down Expand Up @@ -524,6 +525,7 @@ properties:
- name: READ_MODE
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -537,6 +539,7 @@ properties:
- name: READ_WRITE_MODE
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -550,6 +553,7 @@ properties:
- name: SOCKET_CLOSED
deprecated:
since: "1.7.0"
removed: "1.8.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -563,6 +567,7 @@ properties:
- name: SOCKET_CONNECTED
deprecated:
since: "1.7.0"
removed: "1.8.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -576,6 +581,7 @@ properties:
- name: SOCKET_ERROR
deprecated:
since: "1.7.0"
removed: "1.8.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -589,6 +595,7 @@ properties:
- name: SOCKET_INITIALIZED
deprecated:
since: "1.7.0"
removed: "1.8.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -602,6 +609,7 @@ properties:
- name: SOCKET_LISTENING
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand All @@ -615,6 +623,7 @@ properties:
- name: WRITE_MODE
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: |
Used with the deprecated [Titanium.Network.TCPSocket](Titanium.Network.TCPSocket) only.

Expand Down
1 change: 1 addition & 0 deletions apidoc/Titanium/Network/TCPSocket.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Titanium.Network.TCPSocket
extends: Titanium.Proxy
deprecated:
since: "1.7.0"
removed: "9.0.0"
notes: |
Use [Titanium.Network.Socket.TCP](Titanium.Network.Socket.TCP) where possible.
summary: |
Expand Down
10 changes: 0 additions & 10 deletions iphone/Classes/NetworkModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@
#import <TitaniumKit/KrollCallback.h>
#import <TitaniumKit/TiModule.h>

typedef enum {
READ_MODE = 1,
WRITE_MODE = 2,
READ_WRITE_MODE = 3 // Alias for READ | WRITE
} SocketMode;

typedef enum {
// DEFAULT TLS is 0
TLS_VERSION_1_0 = 1,
Expand Down Expand Up @@ -52,10 +46,6 @@ typedef enum {
@property (nonatomic, readonly) NSNumber *NOTIFICATION_TYPE_ALERT;
@property (nonatomic, readonly) NSNumber *NOTIFICATION_TYPE_SOUND;

@property (readonly, nonatomic) NSNumber *READ_MODE;
@property (readonly, nonatomic) NSNumber *WRITE_MODE;
@property (readonly, nonatomic) NSNumber *READ_WRITE_MODE;

@property (nonatomic, readonly) NSNumber *TLS_VERSION_1_0;
@property (nonatomic, readonly) NSNumber *TLS_VERSION_1_1;
@property (nonatomic, readonly) NSNumber *TLS_VERSION_1_2;
Expand Down
15 changes: 0 additions & 15 deletions iphone/Classes/NetworkModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ - (NSString *)apiName
return @"Ti.Network";
}

- (NSNumber *)READ_MODE
{
return [NSNumber numberWithInt:READ_MODE];
}

- (NSNumber *)WRITE_MODE
{
return [NSNumber numberWithInt:WRITE_MODE];
}

- (NSNumber *)READ_WRITE_MODE
{
return [NSNumber numberWithInt:READ_WRITE_MODE];
}

- (void)shutdown:(id)sender
{
RELEASE_TO_NIL(_operationQueue);
Expand Down
11 changes: 4 additions & 7 deletions iphone/Classes/TiNetworkBonjourBrowserProxy.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#import "TiNetworkBonjourBrowserProxy.h"
#import "TiNetworkBonjourServiceProxy.h"
#import <TitaniumKit/TiBase.h>

@implementation TiNetworkBonjourBrowserProxy

Expand All @@ -23,11 +24,6 @@ - (id)init
browser = [[NSNetServiceBrowser alloc] init];
services = [[NSMutableArray alloc] init];

[browser removeFromRunLoop:[NSRunLoop currentRunLoop]
forMode:NSDefaultRunLoopMode];
[browser scheduleInRunLoop:[NSRunLoop mainRunLoop]
forMode:NSDefaultRunLoopMode];

[browser setDelegate:self];
searching = NO;
error = nil;
Expand Down Expand Up @@ -91,6 +87,8 @@ - (void)search:(id)unused
[browser searchForServicesOfType:serviceType
inDomain:domain];

// TODO: Why isn't this breaking when run on main thread?!
// TODO: Should we remove this and make it async like BonjourService?
if (!searching && !error) {
[searchCondition lock];
[searchCondition wait];
Expand Down Expand Up @@ -140,7 +138,6 @@ - (void)fireServiceUpdateEvent
{
NSDictionary *eventObject = [NSDictionary dictionaryWithObject:[[services copy] autorelease]
forKey:@"services"];
[self fireEvent:@"updatedServices" withObject:eventObject]; //TODO: Deprecate old event.
[self fireEvent:@"updatedservices" withObject:eventObject];
}

Expand Down Expand Up @@ -196,4 +193,4 @@ - (void)netServiceBrowserDidStopSearch:(NSNetServiceBrowser *)browser_

@end

#endif
#endif