---
title: "IntercomClass (_IntercomClass)"
canonical: "https://docs.cuesystem.com/space/CVCHELP/512983074/IntercomClass%20(_IntercomClass)"
format: markdown
---
> Macro (toc)

---

The intercom works as a two-point half-duplex **between two CUE touch panels**. Also, only one side of the communication can speak, and the opposite side listens. 

#### **Communication principles **

Communication uses the IP UDP connection. It can be established only if both devices are on the same local subnet. UDP port 45678 is used. Data transmission is on UDP speed. Lost packets do not repeat. If the opposite side does not answer for some time (actually about 5 seconds) the connection is canceled.  

#### **API **

The controller has a built-in variable of the name **InterCom **of the type** **_IntercomClass. These commands are as you see below. 

#### **Commands** 

# Call

```visualbasic
Public Function Call(oppositeIntercom As AddressOf _IntercomClass, callTimeout As  Time)
```

The function calls the opposite side of the communication. The function does not wait for a real connection answer. If the connection fails, the event OnConnectionError is raised. If the connection succeeds, the event OnAnswer is raised. 

#### Parameters 

*oppositeIntercom * 

It is the name of the requested opposite side for the communication. 

*callTimeout* 

Timeout, the system will try to set the communication with the opposite side. If the timeout is less or equal to one second, then a minimum timeout of one second is used. 

#### Example 

```visualbasic
Intercom.Call(GetIntercom("John Mrazek"))
```

# HangUp

```visualbasic
Public Function HangUp(Optional oppositeIntercom As AddressOf _IntercomClass := Nothing)
```

The function hangs up the actual talk. The talk is finished. On the opposite side is raised the event OnConnectionError. On the side, it hangs up, the event is not raised, because the side is the source of the hang-up action. 

#### Parameters 

*oppositeIntercom* 

It is the name of the opposite side of the communication to be hung up. If it is Nothing, all actual talks are hang-upped. 

#### Example 

```visualbasic
Intercom.HangUp() // hangs up all talks
```

# Decline

```visualbasic
Public Function Decline(Optional callingIntercom As AddressOf  _IntercomClass:= Nothing)
```

The function for refusing the incoming call. It is typically used inside the composite graphical object where the user selects* *if the call from the caller has to be accepted or not.  

#### Parameters 

*callingIntercom * 

It is the name of the calling side, that has to be refused. If it is Nothing, all actual calls are refused. 

#### Example 

```visualbasic
Process OnRefuseButtonPush(refusedIntercom As AddressOf  _IntercomClass) Link RefuseButton.OnPush 
  Var msg As Text[100] 

  Intercom.Decline(refusedIntercom) // refuses the call 
  ConcatenateText(msg, "Call with the ", GetIntercomName(refusedIntercom)," is not acceptable." 
  MyPanel.ShowMessage(msg) 
End Process
```

# Answer

```
Public Function Answer(Optional callingIntercom As _IntercomClass:= Nothing)
```

The function is designed for a positive answer to the call. Typically it is used inside the composite graphical object if the call has to be accepted. 

#### Parameters 

*callingIntercom * 

It is the name of the calling side, that has to be accepted. If it is Nothing, the actual talks are hang-upped. 

#### Example 

```visualbasic
Process OnAnswerButtonPush(callingIntercom As AddressOf _IntercomClass) Link AnswerButton.OnPush 
  Var msg As Text[100] 

  Intercom.Answer(callingIntercom) // accepts the call 
  ConcatenateText(msg, "Call with the ", GetIntercomName(callingIntercom)," is accepted." 
  MyPanel.ShowMessage(msg) 
End Process
```

# OnRing

```visualbasic
Public Event OnRing As Process(callingIntercom As _IntercomClass)
```

This is not the function. It is the event raised when there is an incoming call. The callback process linked to that event is typically used to show the message about the call request. The event is generated on the destination side of the call request. If on the one side is used the *Call* command, then on the other side event *OnRing* is raised. 

#### Parameters 

*callingIntercom * 

It is the name of the calling side, that is calling. 

#### Example 

```visualbasic
Process OnRing(callingIntercom As _IntercomClass) Link Intercom.OnRing 
  Var msg As Text[100] 

  ConcatenateText(msg, "The call with the ", GetIntercomName(callingIntercom)," is not requested." 
  MyPanel.ShowMessage(msg) 
End Process
```

# OnAnswer

```visualbasic
Public Event OnAnswer As Process(calledIntercom As _IntercomClass)
```

This is not the function. It is the event raised on the calling side if the opposite side accepts the call. If the first side uses the *Call* command and the other side uses the *Answer* command, then on the first side *OnAnswer* event is raised. 

#### Parameters 

*calledIntercom*** ** 

It is the name of the calledside, that answered positively to my call. 

#### Example 

```visualbasic
Process OnAnswer(calledIntercom As _IntercomClass) Link Intercom.OnAnswer 
  Var msg As Text[100] 

  ConcatenateText(msg, "The call with the ", GetIntercomName(calledIntercom)," was accepted. You can speak and listen now." 
  MyPanel.ShowMessage(msg) 
End Process
```

# OnConnectionError

```visualbasic
Public Event OnConnectionError As Process(oppositeIntercom As _IntercomClass,error As Long)
```

This is not the function. It is the event raised if some error in the call communication ensues. 

#### Parameters 

*oppositeIntercom * 

It is the name of the opposite side, and with it the error in the call is. 

#### Errors 

|  |  |
| --- | --- |
| 1 | Opposite side is not present. It ensues in the call commsides |
| 2 | Opposite side has been lost during the csides |
| 3 | Opposite side refused the call. |
| 4 | Opposite side hangs up the call |
| 5 | Timeout of the Call command elapses |
|  |  |

#### Example 

```visualbasic
Process OnConnectionError(oppositeIntercom As _IntercomClass, error As Long) Link Intercom.OnConnectionError  
  Var msg As Text[100] 

  Select error 
    Case 1 
      FormatText("The intercom {t} is switched off.", GetIntercomName(oppositeIntercom)) 
    Case 2 
      FormatText("The connection with {t} has been lost.", GetIntercomName(oppositeIntercom)) 
    Case 3 
      FormatText("The {t} refuses the call.", GetIntercomName(oppositeIntercom)) 
    Case 4 
      FormatText("The {t} hangs up.", GetIntercomName(oppositeIntercom)) 
    Case 5 
      FormatText("The {t} does not answer.", GetIntercomName(oppositeIntercom)) 
  End Select  
End Process
```

# SetName

```visualbasic
Public Function SetName(name As Text)
```

This function sets the name of my intercom. If the function is used in all communicating controlers, then the function GetName can be used to get the name off the opposite side intercom. 

#### Parameters 

*name* 

The name to be set. 

#### Example 

```visualbasic
Process Autoexec() 
  Intercom.SetName("Bathroom") 
End Process
```

# GetName

```visualbasic
Global Function GetName(ByRef name As Text)
```

This function can be used to get the name of the opposite side (or even my side) intercom. It is good practice to set the name parameter to empty text before the call, because if the function fails because of the controller can not to be reached, then the name parameter is not set. If the parameter is not empty before the call, then it holds its value if the commands fails. 

#### Example 

```visualbasic
Process OnAnswer(calledIntercom As _IntercomClass) Link Intercom.OnAnswer 
  Var msg As Text[100] 

  MyPanel.ShowMessage(FormatText("Intercom {t} answered to the call.",calledIntercom.GetName())) 
End Process
```

# Listen

```visualbasic
Public Function Listen()
```

This function switches my intercom to the listen mode. In that mode the intercom receives talking from the opposite side. The opposite side has to be in the mode speak or slave. 

#### Example 

```visualbasic
Process OnListenButton() Link IntercomWindow.ListenButton.OnPush 
  Intercom.Listen()  
End Process
```

# Speak

```visualbasic
Public Function Speak()
```

This function switches my intercom to the speak mode. In that mode the user can speak to the microphone and the voice is transmitted to the other side of the communication. The opposite side has to be in the mode listen or slave. 

#### Example 

```visualbasic
Process OnSpeakButton() Link IntercomWindow.SpeakButton.OnPush 
  Intercom.Speak()  
End Process
```

# Slave

```visualbasic
Public Function Slave()
```

This function switches my intercom to the slave mode. In this mode user can speak, if the opposite side is in the listen mode and listen, if the opposite side is in the speak mode. The opposite side has not to be in the slave mode, because then the communication does not appear. This mode is useful, if only one side controls the direction of the communication. 

#### Example 

**// **that is the only slave intercom, the communication is directed by the opposite side 

```visualbasic
Process Autoexec () 
  Intercom.Slave()  
End Process
```