Exemple #1
0
        private bool HTTPGetOffers()
        {
            HttpWebRequest request =
                (HttpWebRequest)WebRequest.Create($"{m_url}/signaling/offer?fromtime={m_lastTimeGetOfferRequest}");

            request.Method      = "GET";
            request.ContentType = "application/json";
            request.Headers.Add("Session-Id", m_sessionId);
            request.KeepAlive = false;

            HttpWebResponse  response = HTTPGetResponse(request);
            OfferResDataList list     = HTTPParseJsonResponse <OfferResDataList>(response);

            if (list == null)
            {
                return(false);
            }

            m_lastTimeGetOfferRequest = DateTimeExtension.ParseHttpDate(response.Headers[HttpResponseHeader.Date])
                                        .ToJsMilliseconds();

            foreach (var offer in list.offers)
            {
                m_mainThreadContext.Post(d => OnOffer?.Invoke(this, offer), null);
            }

            return(true);
        }
Exemple #2
0
        private void RaiseOnOfferIfValid(O2GOfferTableRow row)
        {
            if (!instruments.Contains(row.Instrument))
            {
                return;
            }

            if (row.isTimeValid && row.isBidValid && row.isAskValid)
            {
                var tickOn = new DateTime(row.Time.Ticks, DateTimeKind.Utc).ToEstFromUtc();

                if (!testingMode && tickOn.IsTickOn())
                {
                    return;
                }

                var symbol = row.Instrument.ToSymbol();

                var offer = new Offer()
                {
                    Symbol  = symbol,
                    TickOn  = tickOn,
                    BidRate = row.Bid.ToRoundedRate(symbol),
                    AskRate = row.Ask.ToRoundedRate(symbol),
                };

                OnOffer?.Invoke(this, new GenericArgs <Offer>(offer));
            }
        }
    private void ProcessMessage(AntMediaSignalingMessage msg)
    {
        switch (msg.command)
        {
        case "start":
            OnStart.Invoke(msg.streamId);
            break;

        case "takeConfiguration":
            if (msg.type == "offer")
            {
                OnOffer.Invoke(msg);
            }
            else if (msg.type == "answer")
            {
                OnAnswer.Invoke(msg);
            }
            break;

        case "takeCandidate":
            OnIceCandidate.Invoke(msg);
            break;

        case "error":
            OnSignalingError.Invoke(msg.definition);
            break;
        }
    }
Exemple #4
0
        private void WSProcessMessage(object sender, MessageEventArgs e)
        {
            var content = Encoding.UTF8.GetString(e.RawData);

            Debug.Log($"Signaling: Receiving message: {content}");

            try
            {
                var routedMessage = JsonUtility.FromJson <FurioosRoutedMessage <SignalingMessage> >(content);

                SignalingMessage msg;
                if (!string.IsNullOrEmpty(routedMessage.from))
                {
                    msg = routedMessage.message;
                }
                else
                {
                    msg = JsonUtility.FromJson <SignalingMessage>(content);
                }

                if (!string.IsNullOrEmpty(msg.type))
                {
                    if (msg.type == "signIn")
                    {
                        if (msg.status == "SUCCESS")
                        {
                            Debug.Log("Signaling: Slot signed in.");
                            this.WSSend("{\"type\":\"furioos\",\"task\":\"enableStreaming\",\"streamTypes\":\"WebRTC\",\"controlType\":\"RenderStreaming\"}");

                            OnSignedIn?.Invoke(this);
                        }
                        else
                        {
                            Debug.LogError("Signaling: Sign-in error : " + msg.message);
                        }
                    }
                    else if (msg.type == "reconnect")
                    {
                        if (msg.status == "SUCCESS")
                        {
                            Debug.Log("Signaling: Slot reconnected.");
                        }
                        else
                        {
                            Debug.LogError("Signaling: Reconnect error : " + msg.message);
                        }
                    }

                    if (msg.type == "offer")
                    {
                        if (!string.IsNullOrEmpty(routedMessage.from))
                        {
                            DescData offer = new DescData();
                            offer.connectionId = routedMessage.from;
                            offer.sdp          = msg.sdp;

                            OnOffer?.Invoke(this, offer);
                        }
                        else
                        {
                            Debug.LogError("Signaling: Received message from unknown peer");
                        }
                    }
                }
                else if (!string.IsNullOrEmpty(msg.candidate))
                {
                    if (!string.IsNullOrEmpty(routedMessage.from))
                    {
                        CandidateData candidate = new CandidateData();
                        candidate.connectionId  = routedMessage.from;
                        candidate.candidate     = msg.candidate;
                        candidate.sdpMLineIndex = msg.sdpMLineIndex;
                        candidate.sdpMid        = msg.sdpMid;

                        OnIceCandidate?.Invoke(this, candidate);
                    }
                    else
                    {
                        Debug.LogError("Signaling: Received message from unknown peer");
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("Signaling: Failed to parse message: " + ex);
            }
        }
Exemple #5
0
        private void WSProcessMessage(object sender, MessageEventArgs e)
        {
            var content = Encoding.UTF8.GetString(e.RawData);

            Debug.Log($"Signaling: Receiving message: {content}");

            try
            {
                var routedMessage = JsonUtility.FromJson <RoutedMessage <SignalingMessage> >(content);

                SignalingMessage msg;
                if (!string.IsNullOrEmpty(routedMessage.type))
                {
                    msg = routedMessage.data;
                }
                else
                {
                    msg = JsonUtility.FromJson <SignalingMessage>(content);
                }

                if (!string.IsNullOrEmpty(routedMessage.type))
                {
                    if (routedMessage.type == "connect")
                    {
                        string connectionId = JsonUtility.FromJson <SignalingMessage>(content).connectionId;
                        OnCreateConnection?.Invoke(this, connectionId);
                    }
                    else if (routedMessage.type == "offer")
                    {
                        if (!string.IsNullOrEmpty(routedMessage.from))
                        {
                            DescData offer = new DescData();
                            offer.connectionId = routedMessage.from;
                            offer.sdp          = msg.sdp;

                            OnOffer?.Invoke(this, offer);
                        }
                        else
                        {
                            Debug.LogError("Signaling: Received message from unknown peer");
                        }
                    }
                    else if (routedMessage.type == "answer")
                    {
                        if (!string.IsNullOrEmpty(routedMessage.from))
                        {
                            DescData answer = new DescData
                            {
                                connectionId = routedMessage.from,
                                sdp          = msg.sdp
                            };
                            OnAnswer?.Invoke(this, answer);
                        }
                        else
                        {
                            Debug.LogError("Signaling: Received message from unknown peer");
                        }
                    }
                    else if (routedMessage.type == "candidate")
                    {
                        if (!string.IsNullOrEmpty(routedMessage.from))
                        {
                            CandidateData candidate = new CandidateData
                            {
                                connectionId  = routedMessage.@from,
                                candidate     = msg.candidate,
                                sdpMLineIndex = msg.sdpMLineIndex,
                                sdpMid        = msg.sdpMid
                            };
                            OnIceCandidate?.Invoke(this, candidate);
                        }
                        else
                        {
                            Debug.LogError("Signaling: Received message from unknown peer");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("Signaling: Failed to parse message: " + ex);
            }
        }
Exemple #6
0
        private void DoWork()
        {
            O2GSession      session        = null;
            O2GTableManager tableManager   = null;
            StatusListener  statusListener = null;
            TableListener   tableListener  = null;

            bool canUnsubscribeSessionStatus = false;

            try
            {
                session = O2GTransport.createSession();

                session.useTableManager(O2GTableManagerMode.Yes, null);

                var sessionId = Guid.NewGuid().ToString("N");

                statusListener = new StatusListener(session, sessionId);

                statusListener.OnStatus += (s, e) =>
                {
                    var status = e.Item.ToStatus();

                    OnStatus?.Invoke(this, new GenericArgs <Status>(status));

                    if (status == Status.Disconnected)
                    {
                        OnDisconnected?.Invoke(this, EventArgs.Empty);
                    }
                };

                session.subscribeSessionStatus(statusListener);

                session.login(userName, password, URL, connection.ToString());

                if (statusListener.WaitEvents() && statusListener.Connected)
                {
                    tableListener = new TableListener(testingMode);

                    tableListener.OnOffer += (s, e) =>
                                             OnOffer?.Invoke(this, new GenericArgs <Offer>(e.Item));

                    // improve this plus get rid of response listener
                    tableListener.OnOfferIds += (s, e) =>
                    {
                        //var request = GetSetSubscriptionStatusRequest(session, e.Item);

                        //if (request == null)
                        //    throw new Exception("Cannot create request");

                        //var responseListener = new ResponseListener();

                        //session.subscribeResponse(responseListener);

                        //responseListener.SetRequestID(request.RequestID);

                        //session.sendRequest(request);

                        //if (!responseListener.WaitEvents())
                        //    throw new Exception("Response waiting timeout expired");
                    };

                    tableManager = session.getTableManager();

                    var managerStatus = tableManager.getStatus();

                    // max wait
                    while (managerStatus == O2GTableManagerStatus.TablesLoading)
                    {
                        Thread.Sleep(50);

                        managerStatus = tableManager.getStatus();
                    }

                    if (managerStatus == O2GTableManagerStatus.TablesLoadFailed)
                    {
                        throw new Exception("TableManager refresh failed!");
                    }

                    tableListener.SetSymbols(
                        Enum.GetValues(typeof(Symbol)).Cast <Symbol>().ToList());

                    tableListener.SubscribeEvents(tableManager);

                    O2GOffersTable offers = null;

                    offers = (O2GOffersTable)tableManager.getTable(O2GTableType.Offers);

                    tableListener.HandleOffers(offers);

                    cancelEvent.WaitOne();

                    OnCancelled?.Invoke(this, EventArgs.Empty);
                }
            }
            catch (Exception error)
            {
                OnError?.Invoke(this, new GenericArgs <Exception>(error));
            }
            finally
            {
                Shutdown(session, statusListener, tableListener, tableManager);

                if (canUnsubscribeSessionStatus)
                {
                    session.unsubscribeSessionStatus(statusListener);
                }

                if (session != null)
                {
                    session.Dispose();
                }
            }
        }
    //private void ProcessMessage(byte[] data)
    private void ProcessMessage(string content)
    {
        //var content = Encoding.UTF8.GetString(data);
        Debug.Log($"Signaling: Receiving message: {content}");

        try
        {
            var routedMessage = JsonUtility.FromJson <RoutedMessage <SignalingMessage> >(content);

            SignalingMessage msg;
            if (!string.IsNullOrEmpty(routedMessage.type))
            {
                msg = routedMessage.data;
            }
            else
            {
                msg = JsonUtility.FromJson <SignalingMessage>(content);
            }

            if (!string.IsNullOrEmpty(routedMessage.type))
            {
                if (routedMessage.type == "connect")
                {
                    msg = JsonUtility.FromJson <SignalingMessage>(content);
                    m_mainThreadContext.Post(d => OnCreateConnection?.Invoke(this, msg.connectionId, msg.peerExists),
                                             null);
                }
                else if (routedMessage.type == "disconnect")
                {
                    msg = JsonUtility.FromJson <SignalingMessage>(content);
                    m_mainThreadContext.Post(d => OnDestroyConnection?.Invoke(this, msg.connectionId), null);
                }
                else if (routedMessage.type == "offer")
                {
                    DescData offer = new DescData();
                    offer.connectionId = routedMessage.from;
                    offer.sdp          = msg.sdp;
                    m_mainThreadContext.Post(d => OnOffer?.Invoke(this, offer), null);
                }
                else if (routedMessage.type == "answer")
                {
                    DescData answer = new DescData
                    {
                        connectionId = routedMessage.from,
                        sdp          = msg.sdp
                    };
                    m_mainThreadContext.Post(d => OnAnswer?.Invoke(this, answer), null);
                }
                else if (routedMessage.type == "candidate")
                {
                    CandidateData candidate = new CandidateData
                    {
                        connectionId  = routedMessage.@from,
                        candidate     = msg.candidate,
                        sdpMLineIndex = msg.sdpMLineIndex,
                        sdpMid        = msg.sdpMid
                    };
                    m_mainThreadContext.Post(d => OnIceCandidate?.Invoke(this, candidate), null);
                }
                else if (routedMessage.type == "error")
                {
                    msg = JsonUtility.FromJson <SignalingMessage>(content);
                    Debug.LogError(msg.message);
                }
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("Signaling: Failed to parse message: " + ex);
        }
    }