Пример #1
0
        public void SendWebrtcConnData(PrivateMessage data)
        {
            //CHECK WHAT TYPE OF MESSAGE COMING FRO A WEBRTC CLIENT


            //when a user connects to our sever
            // Call the broadcastMessage method to update clients.
            Clients.Client(Context.ConnectionId).Connect("Connected to Webrtc server!");

            //when server gets a message from a connected user
            //Analize the message

            switch (data.type)
            {
            case "login":
                onLogin(data.name, data.p);   //key is password
                break;

            case "offer":
                //This connectionid will contain the connection of the user you want to call
                Clients.Client(Context.ConnectionId).Connect("I entered the switch for offer");
                onOffer(data);
                break;

            case "answer":
                onAnswer(data);
                break;

            case "candidate":
                LogMsg("Ice Switch", "I entered the Ice Switch");
                LogMsg("candidate", data.candidate.ToString());
                LogMsg("From", data.From);
                LogMsg("To", data.To);


                onCandidate(data);
                break;

            case "msg":
                onMsg(data);
                break;

            case "leave":
                onLeave(data);
                break;

            case "openV":
                onOpenVideoCall(data);
                break;


            case "trafficQuestion":
                onTrafficQuestion(data);
                break;

            case "trafficAnswer":
                onTrafficAnswer(data);
                break;


            default:
                break;
            }
        }
Пример #2
0
 public void SendLoginResponse(PrivateMessage data)
 {
     Clients.Client(Context.ConnectionId).LoginResponse(data);
 }
Пример #3
0
 public void SendAnswer(PrivateMessage data)
 {
     Clients.Client(data.ToConn).AnswerResponse(data);
     LogMsg("SendAnswer", "SendAnswer was called");
 }
Пример #4
0
 public void Sendto(PrivateMessage data)
 {
     Clients.Client(data.ToConn).LoginResponse(data);
     LogMsg("SendTo", "SendTo was called");
 }
Пример #5
0
        public void onLogin(string name, string password)
        {
            //Get the connectionid of the user from the database
            string fromConn = GetConnection(name);



            if (ConfirmMemberlogin(name, password))//name is email
            {
                LogMsg("Confirm Login", "Login Passed");

                //if anyone is logged in with this username then refuse
                //Block 1
                if (fromConn != "" && fromConn != null && fromConn != Context.ConnectionId)//Someone is using this name and it is not a Reconnnection
                {
                    LogMsg("Block 1", "I entered Block 1");
                    PrivateMessage respons = new PrivateMessage();
                    respons.type    = "login";
                    respons.success = "true";


                    //UPDATE THE CONNECTION ID
                    UpdateConnection(fromConn, Context.ConnectionId);
                    LogMsg(name, "My Connection has been updated");
                    LogMsg(name, Context.ConnectionId);
                    SendLoginResponse(respons);
                    //Clients.Client(Context.ConnectionId).Connect("I entered the login area");
                }

                //Block 2
                else if (fromConn != "" && fromConn != null && fromConn == Context.ConnectionId)//This user is Reconnecting
                {
                    LogMsg("Block 2", "I entered Block 2");

                    PrivateMessage respons = new PrivateMessage();
                    respons.type    = "login";
                    respons.success = "true";

                    //do nothing
                    SendLoginResponse(respons);
                    //Clients.Client(Context.ConnectionId).Connect("I entered the login area");
                }


                //Block 3
                else if (fromConn == "" || fromConn != null)
                {
                    LogMsg("Block 3", "I entered Block 3");

                    PrivateMessage respons = new PrivateMessage();
                    respons.type    = "login";
                    respons.success = "true";

                    //save the name and connectionid in the database
                    SaveUserData(name, Context.ConnectionId);

                    //do nothing
                    SendLoginResponse(respons);
                    //Clients.Client(Context.ConnectionId).Connect("I entered the login area");
                }


                //Block 4
                else
                {
                    LogMsg("Block 4", "I entered Block 4");

                    PrivateMessage respons = new PrivateMessage();
                    respons.type    = "login";
                    respons.success = "true";

                    //save the name and connectionid in the database
                    SaveUserData(name, Context.ConnectionId);


                    SendLoginResponse(respons);
                    //Clients.Client(Context.ConnectionId).Connect("I entered the login area");
                }
            }
            else
            {
                //Block 5


                PrivateMessage respons = new PrivateMessage();
                respons.type    = "login";
                respons.success = "false";
                SendLoginResponse(respons);

                LogMsg("Block 5", "Confirm Login failed");
                LogMsg("Email", name);
                LogMsg("Password", password);
            }
        }
Пример #6
0
        public void onTrafficQuestion(PrivateMessage data)
        {
            //Get the connectionid of the user from the database
            string fromConn = GetConnection(data.From);

            LogMsg("From", data.From);

            //Select the connectionid of all users at the specified location from the database
            //Add the selected connectionIds to a new group
            //Send the request to all of them
            LogMsg("Traffic", "I entered traffic block");
            Stack <string>         usersAtLocation  = new Stack <string>();
            Stack <ConidAndAnswer> usersAtLocation2 = new Stack <ConidAndAnswer>();

            usersAtLocation2 = getUserByLocatnAndTimeForTraffic(data.MinLat, data.MaxLat, data.MinLongi, data.MaxLongi, data.tim);
            ConidAndAnswer ConnectionIds = null;

            if (usersAtLocation2.Count > 0)
            {
                LogMsg("Level1", "inside level1");
                LogMsg("Count", usersAtLocation2.Count.ToString());
                int veryfree    = 0;
                int movinslowly = 0;
                int standstill  = 0;
                //Analyse the data

                while (usersAtLocation2.Count > 0)
                {
                    LogMsg("Level2", "inside level2");

                    ConnectionIds = usersAtLocation2.Pop();

                    if (ConnectionIds.answer == "Very Free")
                    {
                        veryfree += 1;
                    }
                    else if (ConnectionIds.answer == "Moving Slowly")
                    {
                        movinslowly += 1;
                    }
                    else if (ConnectionIds.answer == "Standstill")
                    {
                        standstill += 1;
                    }
                }

                //Find the highest answer
                String result = "Very Free";
                int    high   = veryfree;
                if (high < movinslowly)
                {
                    LogMsg("Level3", "inside level3");
                    high   = movinslowly;
                    result = "Moving Slowly";
                }
                else if (high < standstill)
                {
                    high   = standstill;
                    result = "Standstill";
                }

                //Send anawer back
                PrivateMessage trafficData = new PrivateMessage();
                trafficData.type          = "trafficAnswer";
                trafficData.trafficAnswer = result;
                trafficData.From          = "activeAnswer";
                trafficData.To            = fromConn;
                trafficData.msgId         = data.msgId;

                Clients.Client(fromConn).TrafficAnswer(trafficData);
            }
            else
            {
                LogMsg("Level4", "inside level4");
                usersAtLocation = getUserByLocatnForTraffic(data.MinLat, data.MaxLat, data.MinLongi, data.MaxLongi);

                PrivateMessage trafficData = new PrivateMessage();
                trafficData.type  = data.type;
                trafficData.msgId = data.msgId;
                trafficData.From  = data.From;

                //  Clients.Client(Context.ConnectionId).TrafficQuestion(trafficData);//Remove later----------------

                while (usersAtLocation.Count > 0)
                {
                    LogMsg("Level5", "inside level5");
                    LogMsg("TrafficCon", usersAtLocation.Count.ToString());

                    string ConnectionIdss = usersAtLocation.Pop();
                    trafficData.ToConn = ConnectionIdss;
                    LogMsg("TrafficCon", ConnectionIdss);

                    Clients.Client(ConnectionIdss).TrafficQuestion(trafficData);
                }
            }
        }