Exemplo n.º 1
0
        //constructs a new message from a JSON blob
        public static PlantronicsMessage ParseMessageFromJSON(String json)
        {
            if (json == null || json.Trim().Length == 0)
            {
                return(null);
            }

            Hashtable t = (Hashtable)JSON.JsonDecode(json);

            if (t == null)
            {
                return(null);
            }

            if (!t.ContainsKey(TYPE))
            {
                return(null);
            }

            PlantronicsMessage message = new PlantronicsMessage((String)t[TYPE], (String)t[ID]);

            if (t.ContainsKey(PAYLOAD))
            {
                Hashtable payload = (Hashtable)t[PAYLOAD];
                foreach (String key in payload.Keys)
                {
                    message.AddToPayload(key, payload[key]);
                }
            }
            return(message);
        }
Exemplo n.º 2
0
        //Sends a message out to all websocket connections
        private static void BroadcastMessage(PlantronicsMessage message)
        {
            String json = JSON.JsonEncode(message.GetObjectAsHashtable());

            Console.WriteLine("Sending Message: " + json);
            foreach (var socket in allSockets.ToList())
            {
                socket.Send(json);
            }
        }
Exemplo n.º 3
0
        static public void m_deviceButtonEvents(object sender, _DeviceListenerEventArgs e)
        {
            PlantronicsMessage eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_BUTTON_PRESS);

            switch (e.HeadsetButtonPressed)
            {
            case HeadsetButton.HeadsetButton_Talk:
                //WebSocket.buttonPressResponse();
                eventMessage.AddToPayload("buttonName", "talk");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_Mute:
                eventMessage.AddToPayload("buttonName", "mute");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_VolumeUp:
                eventMessage.AddToPayload("buttonName", "volumeUp");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_VolumeDown:
                eventMessage.AddToPayload("buttonName", "volumeDown");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_MuteHeld:
                eventMessage.AddToPayload("buttonName", "muteHeld");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_VolumeUpHeld:
                eventMessage.AddToPayload("buttonName", "volumeUpHeld");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_VolumeDownHeld:
                eventMessage.AddToPayload("buttonName", "volumeDownHeld");
                BroadcastMessage(eventMessage);
                break;

            case HeadsetButton.HeadsetButton_Flash:
                eventMessage.AddToPayload("buttonName", "flash");
                BroadcastMessage(eventMessage);
                break;
            }
        }
Exemplo n.º 4
0
 public static void m_deviceButtonEvents(object sender, _DeviceListenerEventArgs e)
 {
     PlantronicsMessage eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_BUTTON_PRESS);
     switch (e.HeadsetButtonPressed)
     {
         case HeadsetButton.HeadsetButton_Talk:
             //WebSocket.buttonPressResponse();
             eventMessage.AddToPayload("buttonName", "talk");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_Mute:
             eventMessage.AddToPayload("buttonName", "mute");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_VolumeUp:
             eventMessage.AddToPayload("buttonName", "volumeUp");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_VolumeDown:
             eventMessage.AddToPayload("buttonName", "volumeDown");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_MuteHeld:
             eventMessage.AddToPayload("buttonName", "muteHeld");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_VolumeUpHeld:
             eventMessage.AddToPayload("buttonName", "volumeUpHeld");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_VolumeDownHeld:
             eventMessage.AddToPayload("buttonName", "volumeDownHeld");
             BroadcastMessage(eventMessage);
             break;
         case HeadsetButton.HeadsetButton_Flash:
             eventMessage.AddToPayload("buttonName", "flash");
             BroadcastMessage(eventMessage);
             break;
     }
 }
Exemplo n.º 5
0
        // print session events
        static void m_sessionEvents_CallStateChanged(object sender, _CallStateEventArgs e)
        {
            string id = e.CallId != null?e.CallId.Id.ToString() : "none";

            IHostCommandExt hostCommandExt = m_activeDevice.HostCommand as IHostCommandExt;

            //the user has accepted the call
            if (e.Action.Equals(CallState.CallState_AcceptCall))
            {
                Console.WriteLine("Call has been answered by headset - sending event to web browser, audio link state = " + hostCommandExt.AudioLinkState);
                PlantronicsMessage m = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_ACCEPT_CALL);
                m.AddToPayload("offer", offer);
                BroadcastMessage(m);
            }
            else if (e.Action.Equals(CallState.CallState_TerminateCall))
            {
                Console.WriteLine("Call has been terminated, killing audio channel");
                PlantronicsMessage m = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_CALL_TERMINATE);
                BroadcastMessage(m);
                offer  = null;
                callId = 0;
            }
        }
Exemplo n.º 6
0
        static void m_deviceListenerEvents_HandlerMethods(object sender, _DeviceListenerEventArgs e)
        {
            PlantronicsMessage eventMessage = null;

            switch (e.DeviceEventType)
            {
            case DeviceEventType.DeviceEventType_HeadsetStateChanged:
                switch (e.HeadsetStateChange)
                {
                case HeadsetStateChange.HeadsetStateChange_Don:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_WEAR_STATE_CHANGED);
                    eventMessage.Payload.Add("worn", "true");
                    BroadcastMessage(eventMessage);
                    break;

                case HeadsetStateChange.HeadsetStateChange_Doff:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_WEAR_STATE_CHANGED);
                    eventMessage.Payload.Add("worn", "false");
                    BroadcastMessage(eventMessage);
                    break;

                case HeadsetStateChange.HeadsetStateChange_Near:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_PROXIMITY);
                    eventMessage.Payload.Add("proximity", "near");
                    BroadcastMessage(eventMessage);
                    break;

                case HeadsetStateChange.HeadsetStateChange_Far:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_PROXIMITY);
                    eventMessage.Payload.Add("proximity", "far");
                    BroadcastMessage(eventMessage);
                    break;

                case HeadsetStateChange.HeadsetStateChange_ProximityDisabled:
                    break;

                case HeadsetStateChange.HeadsetStateChange_ProximityEnabled:
                    break;

                case HeadsetStateChange.HeadsetStateChange_ProximityUnknown:
                    break;

                case HeadsetStateChange.HeadsetStateChange_InRange:
                    RegisterForProximity(true);
                    break;

                case HeadsetStateChange.HeadsetStateChange_OutofRange:
                    break;

                case HeadsetStateChange.HeadsetStateChange_Docked:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_DOCKED);
                    eventMessage.Payload.Add("docked", "true");
                    BroadcastMessage(eventMessage);
                    break;

                case HeadsetStateChange.HeadsetStateChange_UnDocked:
                    eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_DOCKED);
                    eventMessage.Payload.Add("docked", "false");
                    BroadcastMessage(eventMessage);
                    break;

                default:
                    break;
                }
                break;

            default:
                break;
            }
        }
Exemplo n.º 7
0
        //Responsible for processing messages that have arrived via a websocket connection
        private static void HandleMessage(String message)
        {
            if (m_activeDevice == null)
            {
                Console.WriteLine("no active device, ignoring message");
                return;
            }

            PlantronicsMessage m = PlantronicsMessage.ParseMessageFromJSON(message);

            if (m.Type == PlantronicsMessage.MESSAGE_TYPE_SETTING)
            {
                if (m.Id == PlantronicsMessage.SETTING_HEADSET_INFO)
                {
                    PlantronicsMessage response = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_SETTING, PlantronicsMessage.SETTING_HEADSET_INFO);
                    Device             device   = new Device();
                    device.InternalName     = m_activeDevice.InternalName;
                    device.ManufacturerName = m_activeDevice.ManufacturerName;
                    device.ProductName      = m_activeDevice.ProductName;
                    device.VendorId         = String.Format("0x{0:X}", m_activeDevice.VendorID);
                    device.ProductId        = String.Format("0x{0:X}", m_activeDevice.ProductID);
                    device.VersionNumber    = m_activeDevice.VersionNumber;

                    //TODO fixup CAB - make this eventually come from Spokes or a dictionary lookup
                    device.NumberOfChannels = 1;
                    device.SampleRate       = 16000;

                    response.AddToPayload("device", device);
                    BroadcastMessage(response);
                }
            }
            else if (m.Type == PlantronicsMessage.MESSAGE_TYPE_COMMAND)
            {
                if (m.Id == PlantronicsMessage.COMMAND_RING_ON)
                {
                    Console.WriteLine("Ringing headset");
                    Object o = null;
                    if (!m.Payload.TryGetValue("offer", out o))
                    {
                        Console.WriteLine("Unable to get caller id from the message skipping headset ring operation");
                        return;
                    }
                    offer = o as Hashtable;
                    ContactCOM contact = new ContactCOM()
                    {
                        Name = offer["from"] as String
                    };
                    callId = (int)(double)m.Payload["callId"];
                    CallCOM call = new CallCOM()
                    {
                        Id = callId
                    };
                    m_comSession.CallCommand.IncomingCall(call, contact, RingTone.RingTone_Unknown, AudioRoute.AudioRoute_ToHeadset);
                }
                else if (m.Id == PlantronicsMessage.COMMAND_HANG_UP)
                {
                    CallCOM call = new CallCOM()
                    {
                        Id = callId
                    };
                    m_comSession.CallCommand.TerminateCall(call);
                }
                else if (m.Id == PlantronicsMessage.COMMAND_RING_OFF)
                {
                    Console.WriteLine("Turning ring off headset");
                    m_activeDevice.HostCommand.Ring(false);
                }
                else if (m.Id == PlantronicsMessage.COMMAND_MUTE_ON)
                {
                    Console.WriteLine("Muting headset");
                    m_activeDevice.DeviceListener.Mute = true;
                }
                else if (m.Id == PlantronicsMessage.COMMAND_MUTE_OFF)
                {
                    Console.WriteLine("Unmuting headset");
                    m_activeDevice.DeviceListener.Mute = false;
                }
            }
            else if (m.Type == PlantronicsMessage.MESSAGE_TYPE_EVENT)
            {
                Console.WriteLine("Event message received");
            }
        }
Exemplo n.º 8
0
        // print session events
        static void m_sessionEvents_CallStateChanged(object sender, _CallStateEventArgs e)
        {
            string id = e.CallId != null ? e.CallId.Id.ToString() : "none";
            IHostCommandExt hostCommandExt = m_activeDevice.HostCommand as IHostCommandExt;
            //the user has accepted the call
            if (e.Action.Equals(CallState.CallState_AcceptCall))
            {

                Console.WriteLine("Call has been answered by headset - sending event to web browser, audio link state = " + hostCommandExt.AudioLinkState);
                PlantronicsMessage m = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_ACCEPT_CALL);
                m.AddToPayload("offer", offer);
                BroadcastMessage(m);

            }
            else if (e.Action.Equals(CallState.CallState_TerminateCall))
            {
                Console.WriteLine("Call has been terminated, killing audio channel");
                PlantronicsMessage m = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_CALL_TERMINATE);
                BroadcastMessage(m);
                offer = null;
                callId = 0;

            }
        }
Exemplo n.º 9
0
 static void m_deviceListenerEvents_HandlerMethods(object sender, _DeviceListenerEventArgs e)
 {
     PlantronicsMessage eventMessage = null;
     switch (e.DeviceEventType)
     {
         case DeviceEventType.DeviceEventType_HeadsetStateChanged:
             switch (e.HeadsetStateChange)
             {
                 case HeadsetStateChange.HeadsetStateChange_Don:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_WEAR_STATE_CHANGED);
                     eventMessage.Payload.Add("worn", "true");
                     BroadcastMessage(eventMessage);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_Doff:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_WEAR_STATE_CHANGED);
                     eventMessage.Payload.Add("worn", "false");
                     BroadcastMessage(eventMessage);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_Near:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_PROXIMITY);
                     eventMessage.Payload.Add("proximity", "near");
                     BroadcastMessage(eventMessage);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_Far:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_PROXIMITY);
                     eventMessage.Payload.Add("proximity", "far");
                     BroadcastMessage(eventMessage);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_ProximityDisabled:
                     break;
                 case HeadsetStateChange.HeadsetStateChange_ProximityEnabled:
                     break;
                 case HeadsetStateChange.HeadsetStateChange_ProximityUnknown:
                     break;
                 case HeadsetStateChange.HeadsetStateChange_InRange:
                     RegisterForProximity(true);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_OutofRange:
                     break;
                 case HeadsetStateChange.HeadsetStateChange_Docked:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_DOCKED);
                     eventMessage.Payload.Add("docked", "true");
                     BroadcastMessage(eventMessage);
                     break;
                 case HeadsetStateChange.HeadsetStateChange_UnDocked:
                     eventMessage = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_EVENT, PlantronicsMessage.EVENT_DOCKED);
                     eventMessage.Payload.Add("docked", "false");
                     BroadcastMessage(eventMessage);
                     break;
                 default:
                     break;
             }
             break;
         default:
             break;
     }
 }
Exemplo n.º 10
0
        //Responsible for processing messages that have arrived via a websocket connection
        private static void HandleMessage(String message)
        {
            if (m_activeDevice == null)
            {
                Console.WriteLine("no active device, ignoring message");
                return;
            }

            PlantronicsMessage m = PlantronicsMessage.ParseMessageFromJSON(message);
            if (m.Type == PlantronicsMessage.MESSAGE_TYPE_SETTING)
            {
                if (m.Id == PlantronicsMessage.SETTING_HEADSET_INFO)
                {
                    PlantronicsMessage response = new PlantronicsMessage(PlantronicsMessage.MESSAGE_TYPE_SETTING, PlantronicsMessage.SETTING_HEADSET_INFO);
                    Device device = new Device();
                    device.InternalName = m_activeDevice.InternalName;
                    device.ManufacturerName = m_activeDevice.ManufacturerName;
                    device.ProductName = m_activeDevice.ProductName;
                    device.VendorId = String.Format("0x{0:X}", m_activeDevice.VendorID);
                    device.ProductId = String.Format("0x{0:X}", m_activeDevice.ProductID);
                    device.VersionNumber = m_activeDevice.VersionNumber;

                    //TODO fixup CAB - make this eventually come from Spokes or a dictionary lookup
                    device.NumberOfChannels = 1;
                    device.SampleRate = 16000;

                    response.AddToPayload("device", device);
                    BroadcastMessage(response);
                }

            }
            else if (m.Type == PlantronicsMessage.MESSAGE_TYPE_COMMAND)
            {
                if (m.Id == PlantronicsMessage.COMMAND_RING_ON)
                {
                    Console.WriteLine("Ringing headset");
                    Object o = null;
                    if (!m.Payload.TryGetValue("offer", out o))
                    {
                        Console.WriteLine("Unable to get caller id from the message skipping headset ring operation");
                        return;
                    }
                    offer = o as Hashtable;
                    ContactCOM contact = new ContactCOM() { Name = offer["from"] as String };
                    callId = (int)(double)m.Payload["callId"];
                    CallCOM call = new CallCOM() { Id = callId };
                    m_comSession.CallCommand.IncomingCall(call, contact, RingTone.RingTone_Unknown, AudioRoute.AudioRoute_ToHeadset);

                }
                else if (m.Id == PlantronicsMessage.COMMAND_HANG_UP)
                {
                    CallCOM call = new CallCOM() { Id = callId };
                    m_comSession.CallCommand.TerminateCall(call);

                }
                else if (m.Id == PlantronicsMessage.COMMAND_RING_OFF)
                {
                    Console.WriteLine("Turning ring off headset");
                    m_activeDevice.HostCommand.Ring(false);

                }
                else if (m.Id == PlantronicsMessage.COMMAND_MUTE_ON)
                {
                    Console.WriteLine("Muting headset");
                    m_activeDevice.DeviceListener.Mute = true;

                }
                else if (m.Id == PlantronicsMessage.COMMAND_MUTE_OFF)
                {
                    Console.WriteLine("Unmuting headset");
                    m_activeDevice.DeviceListener.Mute = false;

                }
            }
            else if (m.Type == PlantronicsMessage.MESSAGE_TYPE_EVENT)
            {
                Console.WriteLine("Event message received");
            }
        }
Exemplo n.º 11
0
        //Sends a message out to all websocket connections
        private static void BroadcastMessage(PlantronicsMessage message)
        {
            String json = JSON.JsonEncode(message.GetObjectAsHashtable());

            Console.WriteLine("Sending Message: " + json);
            foreach (var socket in allSockets.ToList())
            {
                socket.Send(json);
            }
        }
        //constructs a new message from a JSON blob
        public static PlantronicsMessage ParseMessageFromJSON(String json)
        {
            if (json == null || json.Trim().Length == 0)
            {
                return null;
            }

            Hashtable t = (Hashtable)JSON.JsonDecode(json);
            if (t == null)
            {
                return null;
            }

            if (!t.ContainsKey(TYPE))
            {
               return null;
            }

            PlantronicsMessage message = new PlantronicsMessage((String)t[TYPE], (String)t[ID]);

            if (t.ContainsKey(PAYLOAD))
            {
                Hashtable payload = (Hashtable)t[PAYLOAD];
                foreach (String key in payload.Keys)
                {
                    message.AddToPayload(key, payload[key]);
                }
            }
            return message;
        }