public void OnConnect(string name, string connectionId, string endpointData)
        {
            if (Connections.Add(name, connectionId))
            {
                var info = new EndpointConnectionInfo(name, endpointData);
                lock (Endpoints)
                {
                    Endpoints[name] = info;
                }

                EndpointAdded?.Invoke(name, connectionId, info);
            }
        }
        public void OnConnect(string name, string connectionId, string signalrUrl, string webUrl)
        {
            if (Connections.Add(name, connectionId))
            {
                var info = new EndpointConnectionInfo(name, signalrUrl, webUrl);
                lock (Endpoints)
                {
                    Endpoints[name] = info;
                }

                EndpointAdded?.Invoke(name, connectionId, info);
            }
        }
        public Guid RegisterOrUpdate(string monitorType, string address, string group, string name, string[] tags, string password = null)
        {
            if (!_healthMonitorTypeRegistry.GetMonitorTypes().Contains(monitorType))
            {
                throw new UnsupportedMonitorException(monitorType);
            }
            var encryptedPassword = password?.ToSha256Hash();
            var newIdentifier     = new EndpointIdentity(Guid.NewGuid(), monitorType, address);
            var endpoint          = _endpoints.AddOrUpdate(newIdentifier.GetNaturalKey(),
                                                           new Endpoint(_timeCoordinator, newIdentifier, new EndpointMetadata(name, group, tags), encryptedPassword),
                                                           (k, e) => e.UpdateEndpoint(group, name, tags, encryptedPassword));

            _endpointsByGuid[endpoint.Identity.Id] = endpoint;
            _endpointConfigurationRepository.SaveEndpoint(endpoint);

            if (endpoint.Identity == newIdentifier)
            {
                EndpointAdded?.Invoke(endpoint);
            }
            return(endpoint.Identity.Id);
        }
        protected override void CreateProxy()
        {
            base.CreateProxy();

            proxy.On <EndpointConnectionInfo>("EndpointAdded", info =>
            {
                Console.WriteLine($"Endpoint added: {info}");
                EndpointAdded?.Invoke(info);
            });

            proxy.On <string>("EndpointRemoved", name =>
            {
                Console.WriteLine($"Endpoint removed: {name}");
                EndpointRemoved?.Invoke(name);
            });

            proxy.On <IEnumerable <EndpointConnectionInfo> >("EndpointListUpdated", infos =>
            {
                Console.WriteLine($"Endpoint list updated: {string.Join(", ", infos)}");
                EndpointListUpdated?.Invoke(infos);
            });

            base.CreateProxy();
        }
示例#5
0
        public void OnEvent(CallSdkEvent callEvent)
        {
            Debug.Log($"Event {callEvent.Event} received by Call {CallId}");
            if (callEvent.Event.Equals("Connected"))
            {
                Connected?.Invoke(this, callEvent.GetEventArgs <CallConnectedEventArgs>());
            }
            else if (callEvent.Event.Equals("Disconnected"))
            {
                Disconnected?.Invoke(this, callEvent.GetEventArgs <CallDisconnectedEventArgs>());
            }
            else if (callEvent.Event.Equals("Ringing"))
            {
                Ringing?.Invoke(this, callEvent.GetEventArgs <CallRingingEventArgs>());
            }
            else if (callEvent.Event.Equals("Failed"))
            {
                Failed?.Invoke(this, callEvent.GetEventArgs <CallFailedEventArgs>());
            }
            else if (callEvent.Event.Equals("AudioStarted"))
            {
                AudioStarted?.Invoke(this);
            }
            else if (callEvent.Event.Equals("SIPInfoReceived"))
            {
                SIPInfoReceived?.Invoke(this, callEvent.GetEventArgs <CallSIPInfoReceivedEventArgs>());
            }
            else if (callEvent.Event.Equals("MessageReceived"))
            {
                MessageReceived?.Invoke(this, callEvent.GetEventArgs <CallMessageReceivedEventArgs>());
            }
            else if (callEvent.Event.Equals("LocalVideoStreamAdded"))
            {
                var eventArgs   = callEvent.GetEventArgs <CallLocalVideoStreamAddedEventArgs>();
                var videoStream = CreateVideoStream(eventArgs.streamId);
                _localVideoStreams[eventArgs.streamId] = videoStream;
                eventArgs.VideoStream = videoStream;

                LocalVideoStreamAdded?.Invoke(this, eventArgs);
            }
            else if (callEvent.Event.Equals("LocalVideoStreamRemoved"))
            {
                var eventArgs = callEvent.GetEventArgs <CallLocalVideoStreamRemovedEventArgs>();
                if (!_localVideoStreams.ContainsKey(eventArgs.streamId))
                {
                    return;
                }

                var videoStream = _localVideoStreams[eventArgs.streamId];
                _localVideoStreams.Remove(eventArgs.streamId);

                eventArgs.VideoStream = videoStream;
                videoStream.Dispose();

                LocalVideoStreamRemoved?.Invoke(this, eventArgs);
            }
            else if (callEvent.Event.Equals("ICETimeout"))
            {
                ICETimeout?.Invoke(this);
            }
            else if (callEvent.Event.Equals("ICECompleted"))
            {
                ICECompleted?.Invoke(this);
            }
            else if (callEvent.Event.Equals("EndpointAdded"))
            {
                var eventArgs = callEvent.GetEventArgs <CallEndpointAddedEventArgs>();

                if (_endpoints.ContainsKey(eventArgs.endpointId))
                {
                    return;
                }

                eventArgs.Endpoint = AddEndpoint(eventArgs.endpointId);

                EndpointAdded?.Invoke(this, eventArgs);
            }
            else if (callEvent.Event.Equals("ActionCompleted"))
            {
                var eventArgs  = callEvent.GetEventArgs <CallActionEventArgs>();
                var completion = CallActions[eventArgs.RequestGuid];
                completion?.Invoke(null);
                CallActions.Remove(eventArgs.RequestGuid);
            }
            else if (callEvent.Event.Equals("ActionFailed"))
            {
                var eventArgs  = callEvent.GetEventArgs <CallActionFailedEventArgs>();
                var completion = CallActions[eventArgs.RequestGuid];
                completion?.Invoke(new Error(eventArgs.Code, eventArgs.Error));
                CallActions.Remove(eventArgs.RequestGuid);
            }
            else
            {
                Debug.LogError($"Unexpected Event {callEvent.Event} for Call {CallId}");
            }
        }