Beispiel #1
0
        /// <summary>
        /// Creates a new subscription of this session to a channel
        /// </summary>
        /// <param name="channel"></param>
        /// <returns></returns>
        public ChannelSubscription CreateSubscription(SpecificChannel channel)
        {
            string sessionId = sessionIdRepository.SessionId;
            string url       = new Uri(serverUri, "subscribe").ToString();

            var subscription = new ChannelSubscription(
                channel.ChannelName,
                sessionId
                );

            var serializedSubscription = Serializer.ToJson <ChannelSubscription>(
                subscription,
                SerializationContext.ServerToClient
                );

            http.PendingRequest().Post(url, new JsonObject {
                ["environmentId"]   = environmentId,
                ["broadcastingKey"] = broadcastingKey,
                ["channel"]         = channel.ChannelName,
                ["sessionId"]       = sessionId,
                ["subscription"]    = serializedSubscription
            });

            return(subscription);
        }
Beispiel #2
0
        /// <summary>
        /// Sends a message into a channel
        /// </summary>
        /// <param name="channel"></param>
        /// <param name="message"></param>
        public void Send(SpecificChannel channel, BroadcastingMessage message)
        {
            string url = new Uri(serverUri, "send").ToString();

            JsonValue serializedMessage = Serializer.ToJson <BroadcastingMessage>(
                message,
                SerializationContext.ServerToClient
                );

            http.PendingRequest().Post(url, new JsonObject {
                ["environmentId"]   = environmentId,
                ["broadcastingKey"] = broadcastingKey,
                ["channel"]         = channel.ChannelName,
                ["message"]         = serializedMessage
            });
        }