internal ChannelSubscription(bool subscribeOnReconnected, OrtcClient.OnMessageDelegate onMessage) { this.SubscribeOnReconnected = subscribeOnReconnected; this.OnMessage = onMessage; this.IsSubscribed = false; this.IsSubscribing = false; }
internal ChannelSubscription(bool subscribeOnReconnected, OrtcClient.OnMessageDelegate onMessage, bool withNotification) { this.SubscribeOnReconnected = subscribeOnReconnected; this.OnMessage = onMessage; this.IsSubscribed = false; this.IsSubscribing = false; this.isWithNotification = withNotification; }
internal void subscribe(string channel, bool subscribeOnReconnected, OrtcClient.OnMessageDelegate onMessage) { var domainChannelCharacterIndex = channel.IndexOf(':'); var channelToValidate = channel; if (domainChannelCharacterIndex > 0) { channelToValidate = channel.Substring(0, domainChannelCharacterIndex + 1) + "*"; } string hash = _permissions.Where(c => c.Key == channel || c.Key == channelToValidate).FirstOrDefault().Value; if (_permissions != null && _permissions.Count > 0 && String.IsNullOrEmpty(hash)) { context.DelegateExceptionCallback(new OrtcNotConnectedException(String.Format("No permission found to subscribe to the channel '{0}'", channel))); } else { if (!_subscribedChannels.ContainsKey(channel)) { _subscribedChannels.TryAdd(channel, new ChannelSubscription { IsSubscribing = true, IsSubscribed = false, SubscribeOnReconnected = subscribeOnReconnected, OnMessage = onMessage }); } try { if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); channelSubscription.IsSubscribing = true; channelSubscription.IsSubscribed = false; channelSubscription.SubscribeOnReconnected = subscribeOnReconnected; channelSubscription.OnMessage = onMessage; } string s = String.Format("subscribe;{0};{1};{2};{3}", context._applicationKey, context._authenticationToken, channel, hash); DoSend(s); } catch (Exception ex) { string exName = null; if (ex.InnerException != null) { exName = ex.InnerException.GetType().Name; } switch (exName) { case "OrtcNotConnectedException": // Server went down if (context.IsConnected) { DoDisconnect(); } break; default: context.DelegateExceptionCallback(new OrtcGenericException(String.Format("Unable to subscribe: {0}", ex))); break; } } } }
internal void subscribe(string channel, bool subscribeOnReconnected, OrtcClient.OnMessageDelegate onMessage, bool withNotifications) { var domainChannelCharacterIndex = channel.IndexOf(':'); var channelToValidate = channel; if (domainChannelCharacterIndex > 0) { channelToValidate = channel.Substring(0, domainChannelCharacterIndex + 1) + "*"; } string hash = _permissions.Where(c => c.Key == channel || c.Key == channelToValidate).FirstOrDefault().Value; if (_permissions != null && _permissions.Count > 0 && String.IsNullOrEmpty(hash)) { context.DelegateExceptionCallback(new OrtcNotConnectedException(String.Format("No permission found to subscribe to the channel '{0}'", channel))); } else { if (!_subscribedChannels.ContainsKey(channel)) { _subscribedChannels.Add(channel, new ChannelSubscription { IsSubscribing = true, IsSubscribed = false, SubscribeOnReconnected = subscribeOnReconnected, OnMessage = onMessage, isWithNotification = withNotifications }); } try { if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); channelSubscription.IsSubscribing = true; channelSubscription.IsSubscribed = false; channelSubscription.SubscribeOnReconnected = subscribeOnReconnected; channelSubscription.OnMessage = onMessage; channelSubscription.isWithNotification = withNotifications; } if (withNotifications) { if (Device.OS == TargetPlatform.Android) { if (String.IsNullOrEmpty(context._registrationId)) { context.DelegateExceptionCallback(new OrtcGcmException("The application is not registered with GCM yet!")); return; } else { string s = String.Format("subscribe;{0};{1};{2};{3};{4};GCM", context._applicationKey, context._authenticationToken, channel, hash, context._registrationId); DoSend(s); } } else if (Device.OS == TargetPlatform.iOS) { if (String.IsNullOrEmpty(Realtime.Messaging.Helpers.Settings.Token)) { context.DelegateExceptionCallback(new OrtcApnsException("The application is not registered with Apns yet!")); return; } else { string s = String.Format("subscribe;{0};{1};{2};{3};{4};Apns", context._applicationKey, context._authenticationToken, channel, hash, Realtime.Messaging.Helpers.Settings.Token); DoSend(s); } } } else { string s = String.Format("subscribe;{0};{1};{2};{3}", context._applicationKey, context._authenticationToken, channel, hash); DoSend(s); } } catch (Exception ex) { string exName = null; if (ex.InnerException != null) { exName = ex.InnerException.GetType().Name; } switch (exName) { case "OrtcNotConnectedException": // Server went down if (context.IsConnected) { DoDisconnect(); } break; default: context.DelegateExceptionCallback(new OrtcGenericException(String.Format("Unable to subscribe: {0}", ex))); break; } } } }