/// <summary> /// Constructor for a new subscription /// </summary> /// <param name="subscribeOnReconnected"></param> /// <param name="onMessage"></param> public ChannelSubscription(bool subscribeOnReconnected, OnMessageDelegate onMessage) { SubscribeOnReconnected = subscribeOnReconnected; OnMessage = onMessage; IsSubscribed = false; IsSubscribing = false; }
public ChannelSubscription(bool subscribeOnReconnected, OnMessageDelegate onMessage) { this.SubscribeOnReconnected = subscribeOnReconnected; this.OnMessage = onMessage; this.IsSubscribed = false; this.IsSubscribing = false; }
public static void removeListener( MessageType messageType, OnMessageDelegate handler ) { if( eventTable.ContainsKey( messageType ) ) { eventTable[messageType] = (OnMessageDelegate)eventTable[messageType] - handler; MessengerInternal.onRemoveListener( messageType ); } }
static public void removeListener(MessageType messageType, OnMessageDelegate handler) { if (eventTable.ContainsKey(messageType)) { eventTable[messageType] = (OnMessageDelegate)eventTable[messageType] - handler; MessengerInternal.onRemoveListener(messageType); } }
public void AddHandler(Topics topic, OnMessageDelegate handler) { if (handlers.ContainsKey(topic)) { handlers [topic] += handler; } else { handlers.Add(topic, handler); } }
public async Task OnClientConnectedAsync(string connectionId, OnMessageDelegate onMessageDelegate) { _connections.Add(connectionId, onMessageDelegate); var subscriber = Cache.Multiplexer.GetSubscriber(); // Subscribe to messages for the client await subscriber.SubscribeAsync( GetRedisKeyForConnectionId(connectionId), async (channel, message) => await InvokeOnMessage(connectionId, message) ).ConfigureAwait(false); }
static public void postMessage(MessageType messageType) { Delegate d; if (eventTable.TryGetValue(messageType, out d)) { OnMessageDelegate OnMessageDelegate = d as OnMessageDelegate; if (OnMessageDelegate != null) { OnMessageDelegate(); } } }
public void RemoveHandler(Topics topic, OnMessageDelegate handler) { if (handlers.ContainsKey(topic)) { foreach (Delegate existingHandler in handlers[topic].GetInvocationList()) { if (existingHandler == handler) { handlers[topic] -= handler; } } } }
/// <summary> /// subscribes to a channel /// </summary> /// <param name="channel"></param> /// <param name="onMessage"></param> public void Subscribe(string channel, OnMessageDelegate onMessage) { if (Client.IsConnected && !IsConnecting) { if (!Client.IsSubscribed(channel) && !SubscribingChannels.Exists(str => str == channel)) { SubscribingChannels.Add(channel); Client.Subscribe(channel, onMessage); } } else { if (!PendingSubscriptions.ContainsKey(channel)) { PendingSubscriptions.Add(channel, onMessage); } } }
/// <summary> /// Subscribes to a channel. /// </summary> /// <param name="channel">Channel name.</param> /// <param name="subscribeOnReconnected">Subscribe to the specified channel on reconnect.</param> /// <param name="onMessage"><see cref="OnMessageDelegate"/> callback.</param> /// <example> /// <code> /// ortcClient.Subscribe("channelName", true, OnMessageCallback); /// private void OnMessageCallback(object sender, string channel, string message) /// { /// // Do something /// } /// </code> /// </example> public void Subscribe(string channel, bool subscribeOnReconnected, OnMessageDelegate onMessage) { if (!IsConnected) { DelegateExceptionCallback(new OrtcNotConnectedException("Not connected")); } else if (String.IsNullOrEmpty(channel)) { DelegateExceptionCallback(new OrtcEmptyFieldException("Channel is null or empty")); } else if (!channel.OrtcIsValidInput()) { DelegateExceptionCallback(new OrtcInvalidCharactersException("Channel has invalid characters")); } else if (channel.Length > Constants.MAX_CHANNEL_SIZE) { DelegateExceptionCallback(new OrtcMaxLengthException(String.Format("Channel size exceeds the limit of {0} characters", Constants.MAX_CHANNEL_SIZE))); } else if (_client._subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _client._subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { if (channelSubscription.IsSubscribing) { DelegateExceptionCallback(new OrtcSubscribedException(String.Format("Already subscribing to the channel {0}", channel))); } else if (channelSubscription.IsSubscribed) { DelegateExceptionCallback(new OrtcSubscribedException(String.Format("Already subscribed to the channel {0}", channel))); } else { _client.subscribe(channel, subscribeOnReconnected, onMessage, false); } } } else { _client.subscribe(channel, subscribeOnReconnected, onMessage, false); } }
private void Form1_Load(object sender, EventArgs e) { OnMsg = new OnMessageDelegate(OnMsgRun); OnCount = new OnCountDelegate(OnCountRun); }
/// <summary> /// Subscribes to a channel. /// </summary> /// <param name="channel">Channel name.</param> /// <param name="onMessage"><see cref="OnMessageDelegate"/> callback.</param> /// <example> /// <code> /// ortcClient.Subscribe("channelName", true, OnMessageCallback); /// private void OnMessageCallback(object sender, string channel, string message) /// { /// // Do something /// } /// </code> /// </example> public override void Subscribe(string channel, OnMessageDelegate onMessage) { #region Sanity Checks bool sanityChecked = true; if (!IsConnected) { DelegateExceptionCallback(new OrtcException("Not connected")); sanityChecked = false; } else if (String.IsNullOrEmpty(channel)) { DelegateExceptionCallback(new OrtcException("Channel is null or empty")); sanityChecked = false; } else if (!channel.OrtcIsValidInput()) { DelegateExceptionCallback(new OrtcException("Channel has invalid characters")); sanityChecked = false; } else if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { if (channelSubscription.IsSubscribing) { DelegateExceptionCallback(new OrtcException(String.Format("Already subscribing to the channel {0}", channel))); sanityChecked = false; } else if (channelSubscription.IsSubscribed) { DelegateExceptionCallback(new OrtcException(String.Format("Already subscribed to the channel {0}", channel))); sanityChecked = false; } } } else { byte[] channelBytes = Encoding.UTF8.GetBytes(channel); if (channelBytes.Length > MAX_CHANNEL_SIZE) { if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { channelSubscription.IsSubscribing = false; } } DelegateExceptionCallback(new OrtcException(String.Format("Channel size exceeds the limit of {0} characters", MAX_CHANNEL_SIZE))); sanityChecked = false; } } #endregion if (sanityChecked) { var domainChannelCharacterIndex = channel.IndexOf(':'); var channelToValidate = channel; if (domainChannelCharacterIndex > 0) { channelToValidate = channel.Substring(0, domainChannelCharacterIndex + 1) + "*"; } string hash = GetChannelHash(channel, channelToValidate); if (_permissions != null && _permissions.Count > 0 && String.IsNullOrEmpty(hash)) { DelegateExceptionCallback(new OrtcException(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 = true, OnMessage = onMessage }); } try { if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); channelSubscription.IsSubscribing = true; channelSubscription.IsSubscribed = false; channelSubscription.SubscribeOnReconnected = true; channelSubscription.OnMessage = onMessage; } string s = String.Format("subscribe;{0};{1};{2};{3}", _applicationKey, _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 (IsConnected) { DoDisconnect(); } break; default: DelegateExceptionCallback(new OrtcException(String.Format("Unable to subscribe: {0}", ex))); break; } } } } }
public Task OnClientConnectedAsync(string connectionId, OnMessageDelegate onMessageDelegate) { _connections.Add(connectionId, onMessageDelegate); return(Task.CompletedTask); }
protected static extern void RegisterOnMessageDelegate(OnMessageDelegate callback);
private static extern int open_websocket(IntPtr websocketHandle, [MarshalAs(UnmanagedType.LPStr)] string uri, OnConnectDelegate onConnect, OnMessageDelegate onMessage, OnErrorDelegate onError, OnCloseDelegate onClose);
public override void Subscribe(string channel, OnMessageDelegate onMessage) { #region Sanity Checks bool sanityChecked = true; if (!IsConnected) { RaiseOnException(new OrtcException("Not connected")); sanityChecked = false; } else if (String.IsNullOrEmpty(channel)) { RaiseOnException(new OrtcException("Channel is null or empty")); sanityChecked = false; } else if (!channel.OrtcIsValidInput()) { RaiseOnException(new OrtcException("Channel has invalid characters")); sanityChecked = false; } else if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { if (channelSubscription.IsSubscribing) { RaiseOnException(new OrtcException(String.Format("Already subscribing to the channel {0}", channel))); sanityChecked = false; } else if (channelSubscription.IsSubscribed) { RaiseOnException(new OrtcException(String.Format("Already subscribed to the channel {0}", channel))); sanityChecked = false; } } } else { byte[] channelBytes = Encoding.UTF8.GetBytes(channel); if (channelBytes.Length > MAX_CHANNEL_SIZE) { if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { channelSubscription.IsSubscribing = false; } } RaiseOnException(new OrtcException(String.Format("Channel size exceeds the limit of {0} characters", MAX_CHANNEL_SIZE))); sanityChecked = false; } } #endregion if (sanityChecked) { if (!_subscribedChannels.ContainsKey(channel)) { _subscribedChannels.Add(channel, new ChannelSubscription { IsSubscribing = true, IsSubscribed = false, SubscribeOnReconnected = true, OnMessage = onMessage }); } if (_subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _subscribedChannels.TryGetValue(channel, out channelSubscription); channelSubscription.IsSubscribing = true; channelSubscription.IsSubscribed = false; channelSubscription.SubscribeOnReconnected = true; channelSubscription.OnMessage = onMessage; } Task.RunOnMain(() => { IosOrtcClientFactory.Subscribe(_id, channel); }); } }
/// <summary> /// Subscribes to a channel. /// </summary> /// <param name="channel">Channel name.</param> /// <param name="onMessage"><see cref="OnMessageDelegate" /> callback.</param> /// <example> /// <code> /// ortcClient.Subscribe("channelName", true, OnMessageCallback); /// private void OnMessageCallback(object sender, string channel, string message) /// { /// // Do something /// } /// </code> /// </example> public abstract void Subscribe(string channel, OnMessageDelegate onMessage);
/// <summary> /// Subscribes to a channel with notifications. /// </summary> /// <param name="channel">Channel name.</param> /// <param name="subscribeOnReconnected">Subscribe to the specified channel on reconnect.</param> /// <param name="onMessage"><see cref="OnMessageDelegate"/> callback.</param> /// <example> /// <code> /// ortcClient.SubscribeWithNotifications("channelName", true, OnMessageCallback); /// private void OnMessageCallback(object sender, string channel, string message) /// { /// // Do something /// } /// </code> /// </example> public void SubscribeWithNotifications(string channel, bool subscribeOnReconnected, OnMessageDelegate onMessage) { if (Device.OS == TargetPlatform.iOS || Device.OS == TargetPlatform.Android) { if (!IsConnected) { DelegateExceptionCallback(new OrtcNotConnectedException("Not connected")); } else if (String.IsNullOrEmpty(channel)) { DelegateExceptionCallback(new OrtcEmptyFieldException("Channel is null or empty")); } else if (!channel.OrtcIsValidInput()) { DelegateExceptionCallback(new OrtcInvalidCharactersException("Channel has invalid characters")); } else if (channel.Length > Constants.MAX_CHANNEL_SIZE) { DelegateExceptionCallback(new OrtcMaxLengthException(String.Format("Channel size exceeds the limit of {0} characters", Constants.MAX_CHANNEL_SIZE))); } else if (_client._subscribedChannels.ContainsKey(channel)) { ChannelSubscription channelSubscription = null; _client._subscribedChannels.TryGetValue(channel, out channelSubscription); if (channelSubscription != null) { if (channelSubscription.IsSubscribing) { DelegateExceptionCallback(new OrtcSubscribedException(String.Format("Already subscribing to the channel {0}", channel))); } else if (channelSubscription.IsSubscribed) { DelegateExceptionCallback(new OrtcSubscribedException(String.Format("Already subscribed to the channel {0}", channel))); } else { _client.subscribe(channel, subscribeOnReconnected, onMessage, true); } } } else if (Device.OS == TargetPlatform.Android && String.IsNullOrEmpty(_googleProjectNumber)) { DelegateExceptionCallback(new OrtcGcmException("You have to provide a your Google Project ID to use the GCM notifications")); } else { _client.subscribe(channel, subscribeOnReconnected, onMessage, true); } } else { DelegateExceptionCallback(new OrtcNotSupportedPlatformException("Subscribe with notifications is only available on platforms Android/iOS")); } }
public static void addListener( MessageType messageType, OnMessageDelegate handler ) { MessengerInternal.onAddListener( messageType, handler ); eventTable[messageType] = (OnMessageDelegate)eventTable[messageType] + handler; }
static public void addListener(MessageType messageType, OnMessageDelegate handler) { MessengerInternal.onAddListener(messageType, handler); eventTable[messageType] = (OnMessageDelegate)eventTable[messageType] + handler; }
/// <summary> /// Subscribes to a channel. /// </summary> /// <param name="channel">Channel name.</param> /// <param name="subscribeOnReconnected">Subscribe to the specified channel on reconnect.</param> /// <param name="onMessage"><see cref="OnMessageDelegate"/> callback.</param> /// <example> /// <code> /// ortcClient.Subscribe("channelName", true, OnMessageCallback); /// private void OnMessageCallback(object sender, string channel, string message) /// { /// // Do something /// } /// </code> /// </example> public virtual void Subscribe(string channel, bool subscribeOnReconnected, OnMessageDelegate onMessage) { throw new NotImplementedException(); }
/// <summary> /// subscribes to a channel /// </summary> /// <param name="channel"></param> /// <param name="onMessage"></param> public void Subscribe(string channel, OnMessageDelegate onMessage) { if (Client.IsConnected && !IsConnecting) { if (!Client.IsSubscribed(channel) && !SubscribingChannels.Exists(str => str == channel)) { SubscribingChannels.Add(channel); Client.Subscribe(channel, onMessage); } } else { if (!PendingSubscriptions.ContainsKey(channel)) PendingSubscriptions.Add(channel, onMessage); } }
private static extern int read_websocket(IntPtr websocketHandle, OnMessageDelegate onMessage);
private void Form1_Load(object sender, EventArgs e) { OnMessage = new OnMessageDelegate(OnMessageView); }