Thinkai's Blog

Autohotkey|Python|php|aardio|VOIP|IT 爱好者

VaxSIPUserAgentOCX.ocx 软电话控件简单使用 AutoHotkey 169

作者为 发表

AutohotkeyVOIP

首先从网上下载VaxSIPUserAgentOCX.ocx (版本7.0.4.8) 参见:http://www.pudn.com/Download/item/id/853476.html

然后执行:

regsvr32 /s VaxSIPUserAgentOCX.ocx

进行控件注册,注册后还需要有SIP账号,此版本控件经测试支持局域网拨打,互联网拨打NAT转换地址会有问题,服务器端显示离线。

Gui Add, ActiveX, x0 y0 w0 h0 vVaxSIPUserAgentOCX, {2935849A-3F6A-4DF8-8395-CF9AB3BE1835}
Gui, Add, text, x0 y10 w20 h20, IP
Gui, Add, Edit, x20 y10 w170 h20 vip, 192.168.1.2
Gui, Add, text, x200 y10 w30 h20, Port
Gui, Add, Edit, x230 y10 w70 h20 vport, 5060
Gui, Add, Button, x300 y10 w100 h20 gconnect, 连接
Gui, Add, Button, x400 y10 w100 h20 gclose, 关闭
Gui, Add, Button, x500 y10 w100 h20 ganswer, 接听
Gui, Add, Button, x600 y10 w100 h20 ghangup, 挂断
Gui, Add, Button, x600 y10 w100 h20 greject, 拒接

Gui, Add, Edit, x0 y40 w100 h20 vphone,
Gui, Add, Button, x100 y40 w100 h20 gcall, 拨打

Gui, Add, Button, x0 y70 w100 h20 gtransfer, 转接
Gui, Add, Button, x100 y70 w100 h20 ghold, 保持

Gui, Add, ListView, x0 y100 w800 h600 vlv, ID|Type|Msg
gui, Show
ComObjConnect(VaxSIPUserAgentOCX, VaxSIPUserAgentOCX_Events)
LV_ModifyCol(2,100)
LV_ModifyCol(3,1000)
global id,lv,phone,VaxSIPUserAgentOCX
id := 0
holded := false
VaxSIPUserAgentOCX.SetLicenceKey("VAXVOIP.COM-191P238P55P253P97P229P51P76P-100.") ;设置LicenceKey
;MsgBox % VaxSIPUserAgentOCX.GetMyIP()
;MsgBox % VaxSIPUserAgentOCX.GetAudioInDevTotal()
;MsgBox % VaxSIPUserAgentOCX.GetAudioInDevName(0)
return

connect:
Gui, Submit, NoHide
MyIP := VaxSIPUserAgentOCX.GetMyIP()
;VARIANT_BOOL Initialize(VARIANT_BOOL BindToListenIP, BSTR ListenIP, long ListenPort, BSTR FromURI, BSTR SIPOutBoundProxy, BSTR SIPProxy, BSTR LoginId, BSTR LoginPwd, VARIANT_BOOL UseSoundDevice, long TotalLine);
login := VaxSIPUserAgentOCX.Initialize(false,MyIP,5060,"1010<sip:1010@192.168.1.2>","","192.168.1.2","1001","password",True,1)
VaxSIPUserAgentOCX.OpenLine(0, False, MyIP, 7000) ;打开1号通道
VaxSIPUserAgentOCX.RegisterToProxy(3600) ;注册间隔
VaxSIPUserAgentOCX.EnableKeepAlive(60) ;保活
MsgBox % (login=-1 ? "登录成功" : "登录失败:" GetErrorMessage()) "!"
return

hold:
holded := !holded
if holded
	VaxSIPUserAgentOCX.HoldLine(0)
else
	VaxSIPUserAgentOCX.UnHoldLine(0)
return

transfer:
GuiControlGet, phone
VaxSIPUserAgentOCX.TransferCall(0,"sip:" phone "@192.168.1.2>")
return

reject:
GuiControlGet, phone
VaxSIPUserAgentOCX.RejectCall("CLI:" phone)
return

answer:
GuiControlGet, phone
VaxSIPUserAgentOCX.AcceptCall(0, "CLI:" phone, 0, 0)
return

hangup:
VaxSIPUserAgentOCX.Disconnect(0)
return

call:
GuiControlGet, phone
MsgBox % VaxSIPUserAgentOCX.Connect(0,"sip:" phone "@192.168.1.2>",0,0)
return

class VaxSIPUserAgentOCX_Events
{
	OnIncomingDiagnostic(MsgSIP,FromIP,FromPort)
	{
		;id++,LV_Add("",id,"OnIncomingDiagnostic:" FromIP,MsgSIP) //调试SIP消息 消息太多不作显示
	}
	OnOutgoingDiagnostic(MsgSIP,ToIP,ToPort)
	{
		;id++,LV_Add("",id,"OnIncomingDiagnostic:" ToIP,MsgSIP)
	}
	OnTryingToReRegister()
	{
		id++,LV_Add("",id,"OnTryingToReRegister")
	}
	OnSuccessToReRegister()
	{
		id++,LV_Add("",id,"OnTryingToReRegister")
	}
	OnFailToRegister()
	{
		id++,LV_Add("",id,"OnFailToRegister")
	}
	OnFailToReRegister()
	{
		id++,LV_Add("",id,"OnFailToReRegister")
	}
	OnIncomingCall(CallId,DisplayName,UserName,FromURI,ToURI) ;来电
	{
		id++,LV_Add("",id,"OnIncomingCall", CallId)
		GuiControl, , phone, % CallId
		SoundBeep, , 500
	}
	OnDisconnectCall(LineNo)
	{
		id++,LV_Add("",id,"OnDisconnectCall", LineNo)
	}

}

GuiClose:
close:
VaxSIPUserAgentOCX.UnInitialize()
ExitApp

GetErrorMessage()
{
	ErrNo = VaxSIPUserAgentOCX.GetVaxObjectError()
	if(ErrNo = 10)
		return "You are not Online, please click the 'Online' button first."
	if(ErrNo = 11)
		return "Cann't open local communication port. Another softphone (x-Ten, x-lite or skype etc) is already running. Please close it first."
	if(ErrNo = 12)
		return "License Key is not valid."
	if(ErrNo = 13)
		return "Fail to initialize VaxVoIP task window."
	if(ErrNo = 14)
		return "Cann't access Input/Mic device or device is already in use."
	if(ErrNo = 15)
		return "Cann't access Output/Speaker device or device is already in use."
	if(ErrNo = 16)
		return "Input/Mic device is not open."
	if(ErrNo = 17)
		return "Output/Speaker device is not open."
	if(ErrNo = 18)
		return "Your sound device does not support mic volume."
	if(ErrNo = 19)
		return "Your sound device does not support speaker volume."
	if(ErrNo = 20)
		return "Recording media initialization fail."
	if(ErrNo = 21)
		return "Cann't open the wave file."
	if(ErrNo = 22)
		return "Provided SIP URI is not valid."
	if(ErrNo = 23)
		return "Codec is not supported."
	if(ErrNo = 24)
		return "Error to create SDP (Session Description Protocol) request."
	if(ErrNo = 25)
		return "Error to create CONNECTION request. Please check the provided SIP URI is valid."
	if(ErrNo = 26)
		return "Error to create REGISTER request. Please check the provided SIP URI is valid."
	if(ErrNo = 27)
		return "Error to create UN-REGISTER request. Please check the provided SIP URI is valid."
	if(ErrNo = 28)
		return "Error to create DISCONNECT request."
	if(ErrNo = 29)
		return "Line No is not valid."
	if(ErrNo = 30)
		return "Line is already busy."
	if(ErrNo = 31)
		return "Line is not open."
	if(ErrNo = 32)
		return "Invalid Call-Id."
	if(ErrNo = 33)
		return "Provided value is not valid."
	if(ErrNo = 34)
		return "Selected line is not in voice session."
	if(ErrNo = 35)
		return "Fail to read wave file."
	if(ErrNo = 36)
		return "Fail to write wave file."
	if(ErrNo = 37)
		return "Unsupported wave file format."
}

以下是该库的接口定义:

// Generated .IDL file (by the OLE/COM Object Viewer)
// 
// typelib filename: VaxSIPUserAgentOCX.ocx

[
  uuid(148188FB-A6D9-48BC-AE37-65786376CD8E),
  version(1.0),
  helpstring("VaxSIPUserAgentOCX ActiveX Control module"),
  helpfile("VaxSIPUserAgentOCX.hlp"),
  helpcontext(00000000),
  custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 83951780),
  custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1246968603)

]
library VAXSIPUSERAGENTOCXLib
{
    // TLib : OLE Automation : {00020430-0000-0000-C000-000000000046}
    importlib("stdole2.tlb");

    // Forward declare all types defined in this typelib
    dispinterface _DVaxSIPUserAgentOCX;
    dispinterface _DVaxSIPUserAgentOCXEvents;

    [
      uuid(9858F01E-3474-40B6-996B-7867195B6A6C),
      helpstring("Dispatch interface for VaxSIPUserAgentOCX Control"),
      hidden
    ]
    dispinterface _DVaxSIPUserAgentOCX {
        properties:
        methods:
            [id(0x00000001)]
            void UnInitialize();
            [id(0x00000002)]
            VARIANT_BOOL SetLicenceKey(BSTR LicenceKey);
            [id(0x00000003)]
            long GetVaxObjectError();
            [id(0x00000004)]
            VARIANT_BOOL CloseLine(long LineNo);
            [id(0x00000005)]
            VARIANT_BOOL Connect(
                            long LineNo, 
                            BSTR ToURI, 
                            long InputDeviceId, 
                            long OutputDeviceId);
            [id(0x00000006)]
            VARIANT_BOOL Disconnect(long LineNo);
            [id(0x00000007)]
            VARIANT_BOOL AcceptCall(
                            long LineNo, 
                            BSTR CallId, 
                            long InputDeviceId, 
                            long OutputDeviceId);
            [id(0x00000008)]
            VARIANT_BOOL RejectCall(BSTR CallId);
            [id(0x00000009)]
            VARIANT_BOOL TransferCall(
                            long LineNo, 
                            BSTR ToURI);
            [id(0x0000000a)]
            VARIANT_BOOL HoldLine(long LineNo);
            [id(0x0000000b)]
            VARIANT_BOOL UnHoldLine(long LineNo);
            [id(0x0000000c)]
            VARIANT_BOOL RegisterToProxy(long Expire);
            [id(0x0000000d)]
            VARIANT_BOOL UnRegisterToProxy();
            [id(0x0000000e)]
            VARIANT_BOOL IsLineOpen(long LineNo);
            [id(0x0000000f)]
            VARIANT_BOOL IsLineHold(long LineNo);
            [id(0x00000010)]
            VARIANT_BOOL IsLineBusy(long LineNo);
            [id(0x00000011)]
            VARIANT_BOOL EnableKeepAlive(long Seconds);
            [id(0x00000012)]
            void DisableKeepAlive();
            [id(0x00000013)]
            void DeselectAllVoiceCodec();
            [id(0x00000014)]
            void SelectAllVoiceCodec();
            [id(0x00000015)]
            VARIANT_BOOL SelectVoiceCodec(long CodecNo);
            [id(0x00000016)]
            VARIANT_BOOL DeselectVoiceCodec(long CodecNo);
            [id(0x00000017)]
            BSTR GetMyIP();
            [id(0x00000018)]
            VARIANT_BOOL DigitDTMF(
                            long LineNo, 
                            BSTR Digit);
            [id(0x00000019)]
            VARIANT_BOOL MuteMic(VARIANT_BOOL Mute);
            [id(0x0000001a)]
            VARIANT_BOOL MuteSpk(VARIANT_BOOL Mute);
            [id(0x0000001b)]
            long GetMicVolume();
            [id(0x0000001c)]
            VARIANT_BOOL SetMicVolume(long Volume);
            [id(0x0000001d)]
            long GetSpkVolume();
            [id(0x0000001e)]
            VARIANT_BOOL SetSpkVolume(long Volume);
            [id(0x0000001f)]
            VARIANT_BOOL EnableMicBoost();
            [id(0x00000020)]
            VARIANT_BOOL DisableMicBoost();
            [id(0x00000021)]
            VARIANT_BOOL IsMicBoostEnable();
            [id(0x00000022)]
            VARIANT_BOOL EnableAGC(long Level);
            [id(0x00000023)]
            VARIANT_BOOL DisableAGC();
            [id(0x00000024)]
            VARIANT_BOOL EnableEchoNoiseCancellation();
            [id(0x00000025)]
            VARIANT_BOOL DisableEchoNoiseCancellation();
            [id(0x00000026)]
            VARIANT_BOOL IsRecording(long LineNo);
            [id(0x00000027)]
            VARIANT_BOOL StopRecording(long LineNo);
            [id(0x00000028)]
            VARIANT_BOOL ResetRecording(long LineNo);
            [id(0x00000029)]
            VARIANT_BOOL SaveRecordingToWaveFile(
                            long LineNo, 
                            BSTR FileName);
            [id(0x0000002a)]
            VARIANT_BOOL IsWaveFilePlaying(long LineNo);
            [id(0x0000002b)]
            VARIANT_BOOL PlayWaveOpen(
                            long LineNo, 
                            BSTR FileName);
            [id(0x0000002c)]
            VARIANT_BOOL PlayWaveSkipTo(
                            long LineNo, 
                            long Seconds);
            [id(0x0000002d)]
            long PlayWaveTotalTime(long LineNo);
            [id(0x0000002e)]
            VARIANT_BOOL PlayWavePause(long LineNo);
            [id(0x0000002f)]
            VARIANT_BOOL PlayWaveStart(
                            long LineNo, 
                            VARIANT_BOOL Listen);
            [id(0x00000030)]
            VARIANT_BOOL PlayWaveStop(long LineNo);
            [id(0x00000031)]
            long PlayWavePosition(long LineNo);
            [id(0x00000032)]
            void EnableDonotDisturb();
            [id(0x00000033)]
            void DisableDonotDisturb();
            [id(0x00000034)]
            VARIANT_BOOL SetTOS(
                            long LineNo, 
                            long Value);
            [id(0x00000035)]
            long GetTOS(long LineNo);
            [id(0x00000036)]
            VARIANT_BOOL EnableForceInbandDTMF(long LineNo);
            [id(0x00000037)]
            VARIANT_BOOL DisableForceInbandDTMF(long LineNo);
            [id(0x00000038)]
            VARIANT_BOOL SetDTMFVolume(long Volume);
            [id(0x00000039)]
            long GetDTMFVolume();
            [id(0x0000003a)]
            VARIANT_BOOL Initialize(
                            VARIANT_BOOL BindToListenIP, 
                            BSTR ListenIP, 
                            long ListenPort, 
                            BSTR FromURI, 
                            BSTR SIPOutBoundProxy, 
                            BSTR SIPProxy, 
                            BSTR LoginId, 
                            BSTR LoginPwd, 
                            VARIANT_BOOL UseSoundDevice, 
                            long TotalLine);
            [id(0x0000003b)]
            VARIANT_BOOL StartRecording(
                            long LineNo, 
                            long RecordVoice, 
                            VARIANT_BOOL RecordCompress);
            [id(0x0000003c)]
            long GetMicSoundLevel();
            [id(0x0000003d)]
            long GetSpkSoundLevel();
            [id(0x0000003e)]
            long GetOutboundCodec(long LineNo);
            [id(0x0000003f)]
            long GetInboundCodec(long LineNo);
            [id(0x00000040)]
            VARIANT_BOOL OpenLine(
                            long LineNo, 
                            VARIANT_BOOL BindToRTPRxIP, 
                            BSTR RTPRxIP, 
                            long RTPRxPort);
            [id(0x00000041)]
            long GetAudioInDevTotal();
            [id(0x00000042)]
            long GetAudioOutDevTotal();
            [id(0x00000043)]
            BSTR GetAudioOutDevName(long DeviceId);
            [id(0x00000044)]
            BSTR GetAudioInDevName(long DeviceId);
            [id(0x00000045)]
            BSTR GetVersionSDK();
            [id(0x00000046)]
            BSTR GetVersionFile();
            [id(0x00000047)]
            VARIANT_BOOL JoinTwoLine(
                            long LineNoA, 
                            long LineNoB);
    };

    [
      uuid(747FAA95-5D00-4EA1-9F1F-035D2A88FDA4),
      helpstring("Event interface for VaxSIPUserAgentOCX Control")
    ]
    dispinterface _DVaxSIPUserAgentOCXEvents {
        properties:
        methods:
            [id(0x00000001)]
            void OnIncomingDiagnostic(
                            BSTR MsgSIP, 
                            BSTR FromIP, 
                            long FromPort);
            [id(0x00000002)]
            void OnOutgoingDiagnostic(
                            BSTR MsgSIP, 
                            BSTR ToIP, 
                            long ToPort);
            [id(0x00000003)]
            void OnDTMFDigit(
                            long LineNo, 
                            BSTR Digit);
            [id(0x00000004)]
            void OnPlayWaveDone(long LineNo);
            [id(0x00000005)]
            void OnMsgNOTIFY(BSTR Msg);
            [id(0x00000006)]
            void OnTryingToUnRegister();
            [id(0x00000007)]
            void OnFailToUnRegister();
            [id(0x00000008)]
            void OnSuccessToUnRegister();
            [id(0x00000009)]
            void OnTryingToRegister();
            [id(0x0000000a)]
            void OnFailToRegister();
            [id(0x0000000b)]
            void OnSuccessToRegister();
            [id(0x0000000c)]
            void OnFailToConnect(long LineNo);
            [id(0x0000000d)]
            void OnConnecting(long LineNo);
            [id(0x0000000e)]
            void OnIncomingCallRingingStart(BSTR CallId);
            [id(0x0000000f)]
            void OnIncomingCallRingingStop(BSTR CallId);
            [id(0x00000010)]
            void OnDisconnectCall(long LineNo);
            [id(0x00000011)]
            void OnCallTransferAccepted(long LineNo);
            [id(0x00000012)]
            void OnProvisionalResponse(
                            long LineNo, 
                            long StatusCode, 
                            BSTR ReasonPhrase);
            [id(0x00000013)]
            void OnRedirectionResponse(
                            long LineNo, 
                            long StatusCode, 
                            BSTR ReasonPhrase, 
                            BSTR Contact);
            [id(0x00000014)]
            void OnRequestFailureResponse(
                            long LineNo, 
                            long StatusCode, 
                            BSTR ReasonPhrase);
            [id(0x00000015)]
            void OnServerFailureResponse(
                            long LineNo, 
                            long StatusCode, 
                            BSTR ReasonPhrase);
            [id(0x00000016)]
            void OnGeneralFailureResponse(
                            long LineNo, 
                            long StatusCode, 
                            BSTR ReasonPhrase);
            [id(0x00000017)]
            void OnSuccessToConnect(
                            long LineNo, 
                            BSTR ToRTPIP, 
                            long ToRTPPort);
            [id(0x00000018)]
            void OnIncomingCall(
                            BSTR CallId, 
                            BSTR DisplayName, 
                            BSTR UserName, 
                            BSTR FromURI, 
                            BSTR ToURI);
            [id(0x00000019)]
            void OnVoiceMailMsg(
                            VARIANT_BOOL IsMsgWaiting, 
                            long NewMsgCount, 
                            long OldMsgCount, 
                            long NewUrgentMsgCount, 
                            long OldUrgentMsgCount, 
                            BSTR MsgAccount);
            [id(0x0000001a)]
            void OnTryingToReRegister();
            [id(0x0000001b)]
            void OnFailToReRegister();
            [id(0x0000001c)]
            void OnSuccessToReRegister();
    };

    [
      uuid(2935849A-3F6A-4DF8-8395-CF9AB3BE1835),
      helpstring("VaxSIPUserAgentOCX Control"),
      control
    ]
    coclass VaxSIPUserAgentOCX {
        [default] dispinterface _DVaxSIPUserAgentOCX;
        [default, source] dispinterface _DVaxSIPUserAgentOCXEvents;
    };
};



来了就留个评论吧! 没有评论




友情链接:Autohotkey中文论坛Autohotkey中文帮助Autohotkey官网我的B站直播间Autohotkey中文网联系作者免GooglePlay APK下载

 主题设计 • skyfrit.com  Thinkai's Blog | 保留所有权利

62 queries in 2.923 seconds |