diff --git a/Sources/Realtime/Channel.swift b/Sources/Realtime/Channel.swift index 0953103..19e01ff 100644 --- a/Sources/Realtime/Channel.swift +++ b/Sources/Realtime/Channel.swift @@ -95,21 +95,10 @@ public class Channel { /// Initialize a Channel /// - parameter topic: Topic of the Channel - /// - parameter options: Optional. Options to configure channel broadcast and presence + /// - parameter options: Optional. Options to configure channel broadcast and presence. Leave nil for postgres channel. /// - parameter socket: Socket that the channel is a part of - convenience init(topic: ChannelTopic, options: ChannelOptions = ChannelOptions(), socket: RealtimeClient) { - let params = [ - "config": [ - "presence": [ - "key": options.presenceKey ?? "" - ], - "broadcast": [ - "ack": options.broadcastAcknowledge, - "self": options.broadcastSelf - ] - ] - ] - self.init(topic: topic, params: params, socket: socket) + convenience init(topic: ChannelTopic, options: ChannelOptions? = nil, socket: RealtimeClient) { + self.init(topic: topic, params: options?.params ?? [:], socket: socket) } /// Initialize a Channel diff --git a/Sources/Realtime/Defaults.swift b/Sources/Realtime/Defaults.swift index 897acd9..7277fec 100644 --- a/Sources/Realtime/Defaults.swift +++ b/Sources/Realtime/Defaults.swift @@ -233,6 +233,22 @@ public struct ChannelOptions { self.broadcastSelf = broadcastSelf self.broadcastAcknowledge = broadcastAcknowledge } + + /// Parameters used to configure the channel + var params: [String: [String: Any]] { + [ + "config": [ + "presence": [ + "key": presenceKey ?? "" + ], + "broadcast": [ + "ack": broadcastAcknowledge, + "self": broadcastSelf + ] + ] + ] + } + } /// Represents the different status of a push diff --git a/Sources/Realtime/RealtimeClient.swift b/Sources/Realtime/RealtimeClient.swift index 578404e..3133a2d 100644 --- a/Sources/Realtime/RealtimeClient.swift +++ b/Sources/Realtime/RealtimeClient.swift @@ -590,11 +590,11 @@ public class RealtimeClient: TransportDelegate { /// let channel = socket.channel("rooms", options: ChannelOptions(presenceKey: "user123")) /// /// - parameter topic: Topic of the channel - /// - parameter options: Optional. Options for the channel + /// - parameter options: Optional. Options to configure channel broadcast and presence. Leave nil for postgres channel. /// - return: A new channel public func channel( _ topic: ChannelTopic, - options: ChannelOptions = ChannelOptions() + options: ChannelOptions? = nil ) -> Channel { let channel = Channel(topic: topic, options: options, socket: self) channels.append(channel)