Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions LaravelEchoIOS/Echo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SocketIO


/// This class is the primary API for interacting with broadcasting.
class Echo {
public class Echo {


/// The broadcasting connector.
Expand All @@ -24,7 +24,7 @@ class Echo {
/// Create a new class instance.
///
/// - Parameter options: options
init(options: [String: Any]){
public init(options: [String: Any]){
self.options = options
//No Pusher support
self.connector = SocketIOConnector(options: self.options);
Expand All @@ -34,8 +34,10 @@ class Echo {
/// when connected to the socket
///
/// - Parameter callback: callback
func connected(callback: @escaping NormalCallback){
return self.on(event: "connect", callback: callback)
public func connected(callback: @escaping NormalCallback){
self.on(event: "connect", callback: callback)
self.connector.connect()
return
}


Expand All @@ -44,7 +46,7 @@ class Echo {
/// - Parameters:
/// - event: event name
/// - callback: callback
func on(event: String, callback: @escaping NormalCallback){
public func on(event: String, callback: @escaping NormalCallback){
return self.connector.on(event: event, callback: callback)
}

Expand All @@ -56,7 +58,7 @@ class Echo {
/// - event: event name
/// - callback: callback
/// - Returns: the channel listened
func listen(channel: String, event: String, callback: @escaping NormalCallback) -> IChannel{
public func listen(channel: String, event: String, callback: @escaping NormalCallback) -> IChannel{
return self.connector.listen(name: channel, event: event, callback: callback);
}

Expand All @@ -65,7 +67,7 @@ class Echo {
///
/// - Parameter channel: channel name
/// - Returns: the channel
func channel(channel: String) -> IChannel {
public func channel(channel: String) -> IChannel {
return self.connector.channel(name: channel);
}

Expand All @@ -74,7 +76,7 @@ class Echo {
///
/// - Parameter channel: channel name
/// - Returns: the private channel
func privateChannel(channel: String) -> IChannel{
public func privateChannel(channel: String) -> IChannel{
return self.connector.privateChannel(name:channel);
}

Expand All @@ -83,29 +85,29 @@ class Echo {
///
/// - Parameter channel: channel name
/// - Returns: the private channel
func join(channel: String) -> IPresenceChannel {
public func join(channel: String) -> IPresenceChannel {
return self.connector.presenceChannel(name:channel)
}


/// Leave the given channel.
///
/// - Parameter channel: the channel name
func leave(channel: String) {
public func leave(channel: String) {
self.connector.leave(name: channel)
}


/// Get the Socket ID for the connection.
///
/// - Returns: the socket id
func socketId() -> String {
public func socketId() -> String {
return self.connector.socketId()
}


/// Disconnect from the Echo server.
func disconnect(){
public func disconnect(){
self.connector.disconnect();
}

Expand Down
2 changes: 1 addition & 1 deletion LaravelEchoIOS/channel/IChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import SocketIO

/// This class represents a basic channel protocol.
protocol IChannel {
public protocol IChannel {

/// Listen for an event on the channel instance.
///
Expand Down
2 changes: 1 addition & 1 deletion LaravelEchoIOS/channel/IPresenceChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import SocketIO


/// This protocol represents a presence channel.
protocol IPresenceChannel: IChannel{
public protocol IPresenceChannel: IChannel{


/// Register a callback to be called anytime the member list changes.
Expand Down
2 changes: 1 addition & 1 deletion LaravelEchoIOS/channel/IPrivateChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import SocketIO


/// This protocol represents a private channel.
protocol IPrivateChannel: IChannel{
public protocol IPrivateChannel: IChannel{


/// Trigger client event on the channel.
Expand Down
41 changes: 21 additions & 20 deletions LaravelEchoIOS/connector/SocketIOConnector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SocketIOConnector: IConnector {


/// The Socket.io connection instance.
var socket: SocketIOClient?
var manager: SocketManager?


/// Default connector options.
Expand All @@ -30,11 +30,14 @@ class SocketIOConnector: IConnector {
///
/// - Parameter options: options
init(options: [String: Any]){
self.socket = nil
self.manager = nil
self.options = options
self.channels = [:]
//self.setOptions(options: options)
self.connect()
if let url = self.options["host"] as? String {
let nurl: URL! = URL(string: url)
let socketConfig: SocketIOClientConfiguration = [.log(true), .compress]
self.manager = SocketManager(socketURL: nurl, config: socketConfig)
}
}


Expand All @@ -48,13 +51,11 @@ class SocketIOConnector: IConnector {

/// Create a fresh Socket.io connection.
func connect(){
if let url = self.options["host"] as? String {
let nurl: URL! = URL(string: url)
let socketConfig: SocketIOClientConfiguration = [.log(true), .compress]
self.socket = SocketIOClient(socketURL: nurl, config: socketConfig)
self.socket?.connect(timeoutAfter: 5, withHandler: {
print("ERROR")
})
if let socket = manager?.defaultSocket {
socket.on(clientEvent: .connect) {data, ack in
print("socket connected")
}
socket.connect()
}
}

Expand All @@ -65,7 +66,7 @@ class SocketIOConnector: IConnector {
/// - event: event name
/// - callback: callback
func on(event: String, callback: @escaping NormalCallback){
self.socket!.on(event, callback: callback)
self.manager!.defaultSocket.on(event, callback: callback)
}


Expand All @@ -87,7 +88,7 @@ class SocketIOConnector: IConnector {
/// - Returns: the channel
func channel(name: String) -> IChannel{
if(self.channels[name] == nil){
let socket: SocketIOClient! = self.socket
let socket: SocketIOClient! = self.manager?.defaultSocket
self.channels[name] = SocketIoChannel(
socket: socket, name: name, options: self.options
)
Expand All @@ -102,9 +103,9 @@ class SocketIOConnector: IConnector {
/// - Returns: the private channel
func privateChannel(name: String) -> IPrivateChannel{
if(self.channels["private-" + name] == nil){
let socket: SocketIOClient! = self.socket
let socket: SocketIOClient! = self.manager?.defaultSocket
self.channels["private-" + name] = SocketIOPrivateChannel(
socket: socket, name: "private-" + name, options: self.options
socket: socket, name: "private-" + name, options: self.options
)
}
return self.channels["private-" + name]! as! IPrivateChannel
Expand All @@ -117,9 +118,9 @@ class SocketIOConnector: IConnector {
/// - Returns: the presence channel
func presenceChannel(name: String) -> IPresenceChannel{
if(self.channels["presence-" + name] == nil){
let socket: SocketIOClient! = self.socket
let socket: SocketIOClient! = self.manager?.defaultSocket
self.channels["presence-" + name] = SocketIOPresenceChannel(
socket: socket, name: "presence-" + name, options: self.options
socket: socket, name: "presence-" + name, options: self.options
)
}
return self.channels["presence-" + name]! as! IPresenceChannel
Expand All @@ -144,16 +145,16 @@ class SocketIOConnector: IConnector {
///
/// - Returns: the socket id
func socketId() -> String {
if let socket: SocketIOClient = self.socket{
return socket.sid!
if let socket: SocketIOClient = self.manager?.defaultSocket{
return socket.sid
}
return ""
}


/// Disconnect from the Echo server.
func disconnect(){
let socket: SocketIOClient! = self.socket
let socket: SocketIOClient! = self.manager?.defaultSocket
socket.disconnect()
}

Expand Down
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ inhibit_all_warnings!
platform :ios, '9.0'

target 'LaravelEchoIOS' do
pod 'Socket.IO-Client-Swift', '~> 12.1.2'
pod 'Socket.IO-Client-Swift'
end
21 changes: 13 additions & 8 deletions Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
PODS:
- Socket.IO-Client-Swift (12.1.2):
- Starscream (~> 2.1.1)
- Starscream (2.1.1)
- Socket.IO-Client-Swift (15.0.0):
- Starscream (~> 3.1)
- Starscream (3.1.0)

DEPENDENCIES:
- Socket.IO-Client-Swift (~> 12.1.2)
- Socket.IO-Client-Swift (~> 15.0.0)

SPEC REPOS:
https://github.com/cocoapods/specs.git:
- Socket.IO-Client-Swift
- Starscream

SPEC CHECKSUMS:
Socket.IO-Client-Swift: ba3cb1c4bf0a6ca90080406a2c22685c25ad1f60
Starscream: 142bd8ef24592d985daee9fa48c936070b85b15f
Socket.IO-Client-Swift: c039a808195d22a7192962841b8c035cb61ea49e
Starscream: 08172b481e145289c4930cb567230fb55897cfa4

PODFILE CHECKSUM: e0ccc0bd4d7a60216afe8e6eae9d860cdb93aa42
PODFILE CHECKSUM: ff5c3ecffdf3404f5cc7f24537976d01b48c0b5b

COCOAPODS: 1.3.1
COCOAPODS: 1.6.1