⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conf.bas

📁 三汇CTI示例程序源码
💻 BAS
📖 第 1 页 / 共 2 页
字号:
Attribute VB_Name = "Conf"
Option Explicit
'Event struct
 Type EVENT_SET_INFO
    dwWorkMode As Long
    lpHandlerParam As Long
    dwOutCondition As Long
    dwOutParamVal As Long
    dwUser As Long
End Type
Public Declare Function SsmSetEvent Lib "SHP_A3.dll" (ByVal wEvent As Integer, _
                                                      ByVal nReference As Integer, _
                                                      ByVal bEnable As Boolean, _
                                                      ByRef pEventSet As EVENT_SET_INFO) As Integer
Public Declare Function SsmGetLastErrMsgA Lib "SHP_A3.dll" () As String
Const CH_IDLE = 0
Const CH_TALK = 1
Const CH_WAIT_TALK = 2

Const CO_IDLE = 0
Const CO_IN_CONFERENCE = 1
Const CO_CREATE_OR_JOIN = 2             ' Alias: WAIT_1
Const CO_HOW_TO_JOIN = 3                'Alias: WAIT_2
Const CO_WHO_TO_TALK_SECURELY = 4       ' Alias: WAIT_3

' User's Messages
Const TO_START = &H40   ' Synway reserved ,
Const TO_END = &H41


'Tag for master channel.
Const NOT_MASTER = 0
Const MASTER_BUSY = 1
Const MASTER_IDLE = 2
Const master_num = 4

Public Type ConfToMaster
    nConfGrpId As Integer
    nMaster As Integer
    bInUse As Boolean

End Type


Public Type channel


    state_channel As Integer        'See channel flowchart
    state_conference As Integer     'See conference flowchart
    type As Integer                 'Channel type
    dtmf_str As String              'My own dtmf buffer, never use system's buffer when you are in the event mode
    conf_to_join As Integer         'Store conf_id temporarily before joining
    master As Integer               'Whether being reserved for master
    nMaster As Integer
    creater As Boolean              'Creator?
    IsPlayingBgSound As Boolean     'Whether playing background sound;
    last_join_mode As Integer       'ENG: Used to support talk securely
    ch_to_talk_securely As Long     'Used to support talk securely;
End Type

    Public Conf2Master(0 To master_num - 1) As ConfToMaster
    Public channels(0 To 1000) As channel
    Public total_ch As Integer
    Const E_CHG_RcvDTMF = &HC
    Const E_CHG_ChState = &H18
    Const E_CHG_HookState = &H24
    
    'Initialize board
    Function InitCtiBoard() As Boolean
    Dim ErrMsg As String * 260
    Dim szConfig As String * 260
    Dim szIndex As String * 260
    Dim i As Integer
    Dim nPhoNum As Integer
    
    nPhoNum = 0
    szConfig = App.Path + "\ShConfig.ini" + Chr(0)
    szIndex = App.Path + "\ShIndex.ini" + Chr(0)
    'Load configuration file and initialize system
    If (SsmStartCti(szConfig, szIndex) <> 0) Then
        SsmGetLastErrMsg (ErrMsg)       'Get error message
        MsgBox (ErrMsg)
        InitCtiBoard = False
    Else
        
    'Judge if the number of initialized boards is the same as
    '         that of boards specified in the configuration file
        If (SsmGetMaxUsableBoard() <> SsmGetMaxCfgBoard()) Then
            SsmGetLastErrMsg (ErrMsg)       ' Get error message
            MsgBox (ErrMsg)
            InitCtiBoard = False
        Else
            'Get the maximum number of the channels
            total_ch = SsmGetMaxCh()
            If (total_ch = -1) Then
                MsgBox ("Fail to call SsmGetMaxCh")
                InitCtiBoard = False
            End If
            
            If total_ch > master_num Then
                For i = 0 To total_ch - 1
                    channels(i).state_channel = CH_IDLE
                    channels(i).state_conference = CO_IDLE
                    channels(i).type = SsmGetChType(i)
                    channels(i).master = NOT_MASTER
                    channels(i).IsPlayingBgSound = False
                    channels(i).ch_to_talk_securely = -1
                Next i
                
                For i = 0 To master_num - 1
                        channels(i).master = MASTER_IDLE
                        Conf2Master(i).nConfGrpId = -1
                        Conf2Master(i).nMaster = -1
                        Conf2Master(i).bInUse = False
                      
                Next i
            Else
                MsgBox "Cannot get enough channels."
                InitCtiBoard = False
            End If
            
            InitCtiBoard = True
        End If
    End If
    End Function
    Public Sub InitCircuitListCtrl()
    Dim i%
    MainForm.ChGrid.Cols = 4
    MainForm.ChGrid.Row = 0

    MainForm.ChGrid.Col = 0
    MainForm.ChGrid.Text = "ConfGrp"

    MainForm.ChGrid.Col = 1
    MainForm.ChGrid.Text = "ID"

    MainForm.ChGrid.Col = 2
    MainForm.ChGrid.Text = "IsActive"

    MainForm.ChGrid.Col = 3
    MainForm.ChGrid.Text = "MasterCh"

    MainForm.ChGrid.ColWidth(0) = 60 * 12
    MainForm.ChGrid.ColWidth(1) = 60 * 12
    MainForm.ChGrid.ColWidth(2) = 100 * 12
    MainForm.ChGrid.ColWidth(3) = 100 * 12

    MainForm.ChGrid.Rows = 1
    For i = 0 To master_num - 1
        MainForm.ChGrid.AddItem (str(i))

    Next i

    End Sub
    Public Sub UpdateChListCtrl()
        Dim szNewStat As String * 100
        Dim szOldStat As String * 100
        Dim i As Integer
        Dim nIndex%

        nIndex = 0

        For i = 0 To master_num - 1
        
            szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 1)
            If (szOldStat <> Format(Conf2Master(i).nConfGrpId)) Then
                MainForm.ChGrid.TextMatrix(nIndex + 1, 1) = Format(Conf2Master(i).nConfGrpId)
            End If

            If Conf2Master(i).bInUse Then
                szNewStat = "Active"
            Else
                szNewStat = ""
            End If
            szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 2)
            If (szOldStat <> szNewStat) Then
                MainForm.ChGrid.TextMatrix(nIndex + 1, 2) = szNewStat
            End If

            szOldStat = MainForm.ChGrid.TextMatrix(nIndex + 1, 3)
            If (szOldStat <> Format(Conf2Master(i).nMaster)) Then
                MainForm.ChGrid.TextMatrix(nIndex + 1, 3) = Format(Conf2Master(i).nMaster)
            End If

            nIndex = nIndex + 1
        
        Next i
    End Sub
    Function EventCallbackProc(ByVal uMsg As Integer, ByVal wParam As Long, ByVal lParam As Long, ByVal dwUser As Long) As Long

    Dim nCh As Integer
    Dim i%
    Dim nEventCode As Integer
    Dim nNewState As Integer
    Dim cNewDtmf As String
    Dim nRes As Integer
    
    Dim new_state As Integer
    Dim ch As Integer
    Dim dtmf As String
    Dim master_ch As Integer
    Dim conf_id As Integer
    Dim filename As String
    Dim filenameX As String
    Dim GrpId As Long
    Dim MmbrId As Long
                            
    Dim SilenceTime As Long
    Dim JoinMode, IsSpeaking, TotalMember, TotalSpeaker, TotalSpeaking As Integer
    
    nEventCode = uMsg
    ch = wParam
    
    Select Case nEventCode
        Case E_CHG_ChState
        
            new_state = CInt(lParam And &HFFFF&)    'New state
            'Trunk and digital
            If (channels(ch).type = 0 Or _
                channels(ch).type = 4 Or _
                channels(ch).type = 6 Or _
                channels(ch).type = 7 Or _
                channels(ch).type = 8 Or _
                channels(ch).type = 11) Then
                        
                If new_state = 2 And channels(ch).state_channel = CH_IDLE Then
                    SsmPickup ch
                    channels(ch).state_channel = CH_WAIT_TALK
                ElseIf new_state = 3 And channels(ch).state_channel = CH_WAIT_TALK Then
                    EventCallbackProc TO_START, ch, 0, 0
                    channels(ch).state_channel = CH_TALK
                ElseIf channels(ch).state_channel = CH_WAIT_TALK Then
                    SsmHangup ch
                    channels(ch).state_channel = CH_IDLE
                ElseIf channels(ch).state_channel = CH_TALK Then
                    SsmHangup ch
                    EventCallbackProc TO_END, ch, 0, 0
                    channels(ch).state_channel = CH_IDLE
                End If
                    
            'Station
            ElseIf (channels(ch).type = 2) Then
                    
                If (new_state = 1 And channels(ch).state_channel = CH_IDLE) Then
                    EventCallbackProc TO_START, ch, 0, 0
                    channels(ch).state_channel = CH_TALK
                ElseIf (new_state = 0 And channels(ch).state_channel = CH_TALK) Then
                    EventCallbackProc TO_END, ch, 0, 0
                    channels(ch).state_channel = CH_IDLE
                End If
            End If
    
        'Here is about dtmf for each choice.
        Case E_CHG_RcvDTMF
            ' Arc 4
            If (channels(ch).state_conference = CO_CREATE_OR_JOIN) Then
                dtmf = Chr(&HFFFF& And lParam)      'Newly received DTMF
                If (dtmf = "#") Then
                    'To create
                    If (Len(channels(ch).dtmf_str) = 0) Then
                        'Create a conference.
                        conf_id = SsmCreateConfGroup(-1, -1, -1, -1)
                        channels(ch).creater = True
                        If (conf_id >= 0) Then
                            channels(ch).conf_to_join = conf_id
                            master_ch = get_idle()
                            If (master_ch >= 0) Then
                                'Add master
                                channels(master_ch).master = MASTER_BUSY
                                i = search_idle_confgrp
                                Conf2Master(i).nConfGrpId = conf_id
                                Conf2Master(i).nMaster = master_ch
                                Conf2Master(i).bInUse = True
                                SsmJoinConfGroup conf_id, master_ch, 0, 0, False, False
                               
                                'Record
                                filename = Format(Time, "Long Time")
                                filenameX = Format(filename, "h-m-s")
                                filenameX = "rec\\" + filenameX + ".wav"
                                SsmRecToFile master_ch, filenameX, -1, 0, -1, 0, 0
                                'Play "The id of the conference created is ..."
                                SsmClearFileList ch
                                SsmAddToFileList ch, "wav\\d.wav", -1, 0, -1
                                add_list ch, conf_id
                                'Play "Choose join-mode ..."
                                SsmAddToFileList ch, "wav\\c.wav", -1, 0, -1
                                SsmPlayFileList ch
                                'Change state.
                                channels(ch).state_conference = CO_HOW_TO_JOIN
                                
                            Else    'No more master channels
                                SsmFreeConfGroup conf_id
                                SsmClearFileList ch
                                SsmAddToFileList ch, "wav\\m.wav", -1, 0, -1
                                SsmAddToFileList ch, "wav\\a.wav", -1, 0, -1
                                SsmPlayFileList ch
                            End If
                            
                        Else    'Failed to create a conference.
                            SsmClearFileList ch
                            SsmAddToFileList ch, "wav\\m.wav", -1, 0, -1
                            SsmAddToFileList ch, "wav\\a.wav", -1, 0, -1
                            SsmPlayFileList ch
                        End If
                        
                    'To join
                    ElseIf (SsmValidateGrpId(Val(channels(ch).dtmf_str))) Then
                        'Store the conf_id, it will be used later on.
                        channels(ch).creater = False
                        channels(ch).conf_to_join = Val(channels(ch).dtmf_str)
                        channels(ch).dtmf_str = ""
                        SsmPlayFile ch, "wav\\c.wav", -1, 0, -1
                        channels(ch).state_conference = CO_HOW_TO_JOIN
                        
                    'To what? no specific conference.
                    Else
                        'Play "the id doesn't exist ..."
                        SsmClearFileList ch
                        SsmAddToFileList ch, "wav\\b.wav", -1, 0, -1
                        'Play "which to join or create...".
                        SsmAddToFileList ch, "wav\\a.wav", -1, 0, -1
                        SsmPlayFileList ch
                        'Clear my dtmf buffer.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -