Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CThemperatureButton"/> class.
        /// </summary>
        /// <param name="caption">
        /// The caption.
        /// </param>
        public CThemperatureButton(int x, int y, IRemoteDevice device) : base(x, y)
        {
            this._myDevice = device;

            this._thempIcon = new ImageSurface("./Icons/thermometer.png");
            this._caption = this._myDevice.Name;
            this.Name = "tmpObj";
            this.SetSizeRequest(MainWidth, MainHeight);

            //text1.Activated+=new EventHandler(Menu1Clicked);
            //Gtk.MenuItem text2 = new MenuItem(&quot;Test2&quot;);
            //text2.Activated+=new EventHandler(Menu2Clicked)
        }
Example #2
0
        public Task HandleAsync(
            IRemoteDevice remoteDevice,
            Guid?peerConnectionId,
            RTCSessionDescription offer,
            TransceiverMetadata[] transceivers)
        {
            Require.NotNull(offer.Sdp);
            Require.NotNull(offer.Type);

            // Ensure the user has logged in
            var deviceData = remoteDevice.GetCustomData();

            if (null == deviceData.User)
            {
                throw new UnauthorizedAccessException();
            }

            // Get or create new PeerConnection, depending on the client's requests
            IPeerConnection peerConnection = null;

            if (peerConnectionId != null)
            {
                peerConnection = deviceData.PeerConnections.First(p => p.Id == peerConnectionId.Value);
            }
            else
            {
                if (deviceData.PeerConnections.Count > 3)
                {
                    throw new InvalidOperationException($"Max 3 PeerConnection allowed per device");
                }
                peerConnection = CreatePeerConnection(remoteDevice, deviceData.User);
            }

            // Save
            deviceData.PeerConnections.Add(peerConnection);
            remoteDevice.SetCustomData(deviceData);

            // Let the negotiation service handle the rest
            // Notes - queue transceiver metadata first before queuing the remote sdp,
            // so at the time processing remote sdp (which has remote transceivers)
            // we know transceviers' metadata inhand.
            // Fail to do so will cause errors.
            _negotiationService.EnqueueRemoteTransceiverMetadata(peerConnection, transceivers);
            _negotiationService.EnqueueRemoteOffer(peerConnection, offer);
            return(Task.CompletedTask);
        }
Example #3
0
        private async Task <bool> InitializeRfcommClient(IRemoteDevice remoteServer)
        {
            var accessStatus = DeviceAccessInformation.CreateFromId(remoteServer.DeviceId).CurrentStatus;

            if (accessStatus == DeviceAccessStatus.DeniedByUser)
            {
                Debug.Write("This app does not have access to connect to the remote device (please grant access in Settings > Privacy > Other Devices");
                return(false);
            }

            var success = await remoteServer.TryAndConnectToDevice();

            var bluetoothDevice = (RemoteBluetoothDevice)remoteServer;

            m_socket = await bluetoothDevice.EstablishSocketEndPoint();

            m_messageOutstream = new DataWriter(m_socket.OutputStream);
            m_messageInStream  = new DataReader(m_socket.InputStream);
            return(success);
        }
        public Task AddAsync(IRemoteDevice remoteDevice, Guid peerConnectionId, RTCIceCandidate iceCandidate)
        {
            var peerConnection = remoteDevice.GetCustomData().PeerConnections.FirstOrDefault(p => p.Id == peerConnectionId);

            if (null == peerConnection)
            {
                throw new InvalidOperationException(
                          $"Could not find PeerConnection with Id {peerConnectionId} in {remoteDevice}"
                          );
            }

            if (null == peerConnection.Room)
            {
                throw new UnauthorizedAccessException(
                          $"Device must join a room first before sending ICE candidates");
            }

            _negotiationService.EnqueueRemoteIceCandidate(peerConnection, iceCandidate);
            return(Task.CompletedTask);
        }
Example #5
0
        public void RemovePeerConnection(IRemoteDevice remoteDevice, IPeerConnection peerConnection)
        {
            _signallingThread.EnsureCurrentThread();
            // Remove all video links that was created for this PeerConnection
            _localVideoLinks.RemoveByPeerConnection(peerConnection);
            _logger.Info($"Removed all video links for {peerConnection} from {_localVideoLinks}");

            // Remove all video links that was created for this PeerConnetion's remote tracks
            _remoteVideoLinks.RemoveByPeerConnection(peerConnection);
            _logger.Info($"Removed all video links for {peerConnection} from {_remoteVideoLinks}");

            // Remove this PeerConnection from VideoClient
            var client  = _clients.GetOrThrow(remoteDevice.Id);
            var removed = client.PeerConnections.Remove(peerConnection);

            if (!removed)
            {
                throw new InvalidProgramException("PeerConnection did not removed from memory");
            }
            _logger.Info($"Removed {peerConnection} from {client}, remaining PeerConnections for this client={client.PeerConnections.Count}");
        }
Example #6
0
        public void AddPeerConnection(IRemoteDevice remoteDevice, IPeerConnection peerConnection)
        {
            Require.NotNull(peerConnection);
            _signallingThread.EnsureCurrentThread();

            // Add PeerConnection into VideoClient
            var client = _clients.GetOrThrow(remoteDevice.Id);

            if (client.PeerConnections.Contains(peerConnection))
            {
                throw new InvalidProgramException($"{peerConnection} already added into {client}");
            }
            client.PeerConnections.Add(peerConnection);
            _logger.Info($"Added {peerConnection} into {client}, total PeerConnections for this client={client.PeerConnections.Count}");

            // If this PeerConnetion has some existing transceivers,
            // add them.
            // TODO: listen for future transceivers and add them too, too lazy to implement this for now.
            var currenTransceivers = peerConnection.Native.GetTransceivers();

            foreach (var transceiver in currenTransceivers)
            {
                OnRemoteTrackAdded(client, peerConnection, transceiver);
            }

            // Link this PeerConnection with any existing local VideoSources
            foreach (var other in _clients
                     .OtherThan(client)
                     .Where(other => other.VideoSources.ContainsKey(client.DesiredMediaQuality)))
            {
                var localVideoLink = new LocalVideoLink(
                    this,
                    other.VideoSources[client.DesiredMediaQuality],
                    peerConnection);
                _localVideoLinks.Add(localVideoLink);
                _logger.Debug($"Added {localVideoLink} into {_localVideoLinks}");
            }
        }
Example #7
0
        private void ProcessSentQ(IRemoteDevice remoteDevice)
        {
            var packet = remoteDevice.DequeuePacketFromSentQueue();

            if (packet != null)
            {
                int bufLength = ((byte[])packet.Data).Length;

                _sentBuffer[0] = (byte)(packet.SrcAddress | RFM12B_JEE_HDR_ACK_BIT);
                _sentBuffer[1] = 0;

                Buffer.BlockCopy((byte[])packet.Data, 0, _sentBuffer, _constPacketHeaderSize, bufLength);

                var err = this._deviceLayer.WriteToDevice(_sentBuffer, (ulong)(bufLength + _constPacketHeaderSize));
                Console.WriteLine("sended: " + err.ToString());
            }
        }
Example #8
0
        public MediaQuality DesiredMediaQuality => MediaQuality.High; // todo - support multiple quality streams

        public Client(IRemoteDevice device)
        {
            Device = device ?? throw new ArgumentNullException(nameof(device));
        }
Example #9
0
 /// <summary>Remove a device from the pool.</summary>
 /// <param name="dev">The device to remove from the pool.</param>
 public virtual void Remove(IRemoteDevice dev)
 {
     this.List.Remove(dev);
 }
Example #10
0
 /// <summary>Adds a device to this pool.</summary>
 /// <param name="dev">The device to add. </param>
 public virtual void Add(IRemoteDevice dev)
 {
     this.List.Add(dev);
 }
        public async Task <bool> ConnectDeviceAsync(IRemoteDevice device)
        {
            await Task.CompletedTask;

            return(false);
        }