// TODO: Add OnCallStateChanged and OnChatMessageStateChanged. void OnCallStateChanged(IntPtr lc, IntPtr call, LinphoneCallState cstate, string message) { if (linphoneCore == IntPtr.Zero || !running) { return; } #if (TRACE) Console.WriteLine("OnCallStateChanged: {0}", cstate); #endif Call.State newstate = Call.State.Idle; Call.CallType newtype = Call.CallType.None; string from = ""; string to = ""; string peer_name = nameFromAddress(linphone_call_get_remote_address(call)); IntPtr addressStringPtr; // detecting direction, state and source-destination data by state switch (cstate) { case LinphoneCallState.LinphoneCallIncomingReceived: newstate = Call.State.IncomingRinging; newtype = Call.CallType.Incoming; addressStringPtr = linphone_call_get_remote_address_as_string(call); if (addressStringPtr != IntPtr.Zero) { from = Marshal.PtrToStringAnsi(addressStringPtr); to = this.identity; } break; case LinphoneCallState.LinphoneCallIncomingEarlyMedia: newstate = Call.State.IncomingEarlyMedia; newtype = Call.CallType.Incoming; addressStringPtr = linphone_call_get_remote_address_as_string(call); if (addressStringPtr != IntPtr.Zero) { from = Marshal.PtrToStringAnsi(addressStringPtr); to = this.identity; } break; case LinphoneCallState.LinphoneCallConnected: newstate = Call.State.Connected; break; case LinphoneCallState.LinphoneCallStreamsRunning: newstate = Call.State.StreamsRunning; break; case LinphoneCallState.LinphoneCallPausedByRemote: newstate = Call.State.PausedByRemote; break; case LinphoneCallState.LinphoneCallUpdatedByRemote: newstate = Call.State.UpdatedByRemote; break; case LinphoneCallState.LinphoneCallOutgoingInit: newstate = Call.State.OutgoingStart; addressStringPtr = linphone_call_get_remote_address_as_string(call); if (addressStringPtr != IntPtr.Zero) { from = this.identity; to = Marshal.PtrToStringAnsi(addressStringPtr); } break; case LinphoneCallState.LinphoneCallOutgoingProgress: newstate = Call.State.InProgress; break; case LinphoneCallState.LinphoneCallOutgoingRinging: newstate = Call.State.OutgoingRinging; break; case LinphoneCallState.LinphoneCallOutgoingEarlyMedia: newstate = Call.State.OutgoingEarlyMedia; newtype = Call.CallType.Outcoming; addressStringPtr = linphone_call_get_remote_address_as_string(call); if (addressStringPtr != IntPtr.Zero) { from = this.identity; to = Marshal.PtrToStringAnsi(addressStringPtr); } break; case LinphoneCallState.LinphoneCallError: newstate = Call.State.Error; break; case LinphoneCallState.LinphoneCallReleased: newstate = Call.State.Released; break; case LinphoneCallState.LinphoneCallEnd: newstate = Call.State.Ended; //hangupCall(call); if (linphone_call_params_get_record_file(calls_default_params) != IntPtr.Zero) { linphone_call_stop_recording(call); } break; default: break; } //Change the calls state or create a new call if it doesn't exist yet LinphoneCall existCall = FindCall(call); if (existCall == null) { existCall = new LinphoneCall(); existCall.state = newstate; existCall.call_type = newtype; existCall.from = from; existCall.to = to; existCall.ptr = call; existCall.peer_name = peer_name; calls.Add(existCall); if ((CallStateChangedEvent != null)) { CallStateChangedEvent(existCall); } } else { if (existCall.state != newstate) { existCall.state = newstate; CallStateChangedEvent(existCall); } } }
private void linkCallStateChangedEventBody() { //Seperate the single CallStateChangedEvent event from core into CallState events core_wrapper.CallStateChangedEvent += (Call call) => { current_call = call; Call.State state = call.state; switch (state) { case Call.State.Idle: case Call.State.OutgoingEarlyMedia: line_state = LineState.Busy; if (OutgoingEarlyMediaEvent != null) { OutgoingEarlyMediaEvent(call); } break; case Call.State.OutgoingStart: line_state = LineState.Busy; if (OutgoingStartEvent != null) { OutgoingStartEvent(call); } break; case Call.State.InProgress: line_state = LineState.Busy; if (InProgressEvent != null) { InProgressEvent(call); } break; case Call.State.OutgoingRinging: line_state = LineState.Busy; if (OutgoingRingingEvent != null) { OutgoingRingingEvent(call); } break; case Call.State.IncomingRinging: line_state = LineState.Busy; if (IncomingRingingEvent != null) { IncomingRingingEvent(call); } break; case Call.State.IncomingEarlyMedia: line_state = LineState.Busy; if (IncomingEarlyMediaEvent != null) { IncomingEarlyMediaEvent(call); } break; case Call.State.Connected: line_state = LineState.Busy; if (ConnectedEvent != null) { ConnectedEvent(call); } break; case Call.State.StreamsRunning: line_state = LineState.Busy; if (StreamsRunningEvent != null) { StreamsRunningEvent(call); } break; case Call.State.Pausing: if (PausingEvent != null) { PausingEvent(call); } break; case Call.State.PausedByUs: if (PausedByUsEvent != null) { PausedByUsEvent(call); } break; case Call.State.PausedByRemote: if (PausedByRemoteEvent != null) { PausedByRemoteEvent(call); } break; case Call.State.Resuming: if (ResumeEvent != null) { ResumeEvent(call); } break; case Call.State.UpdatedByUs: if (UpdatedByUsEvent != null) { UpdatedByUsEvent(call); } break; case Call.State.UpdatedByRemote: if (UpdatedByRemoteEvent != null) { UpdatedByRemoteEvent(call); } break; case Call.State.Referred: if (ReferredEvent != null) { ReferredEvent(call); } break; case Call.State.Ended: if (EndedEvent != null) { EndedEvent(call); } break; case Call.State.Released: line_state = LineState.Free; if (ReleasedEvent != null) { ReleasedEvent(call); } break; case Call.State.Error: if (CallErrorEvent != null) { CallErrorEvent(call, CallError.CallError, "Call has encountered an error."); } if (ReleasedEvent != null) { ReleasedEvent(call); } break; } }; }