Esempio n. 1
0
func handleUseJoinedEvent(e *eventsocket.Event) VoiceUserJoinedEvent {
	memberId := getMemberIdFromEvent(e)
	callerIdNum := getCallerIdNumFromEvent(e)
	callerIdName := getCallerIdNameFromEvent(e)
	speak := getSpeakFromEvent(e)
	muted := isUserMuted(speak)
	talking := isUserTalking(e)
	confName := e.Get("Conference-Name")
	//	confSize := e.Get("Conference-Size")

	//   voiceUserId := callerIdName
	globalAudio := isUserJoinedThoughGlobalAudio(callerIdName)

	voiceUser := VoiceUserJoinedEvent{}

	if globalAudio != true {
		user, err := getUser(callerIdName)
		if err != nil {
			voiceUser := VoiceUserJoinedEvent{}
			voiceUser.ConferenceId = confName
			voiceUser.VoiceUserId = user.UserId
			voiceUser.CallerIdNum = callerIdNum
			voiceUser.CallerIdName = user.Username
			voiceUser.Muted = muted
			voiceUser.Talking = talking
			voiceUser.Locked = false
			voiceUser.UserId = memberId

		}

	}
	return voiceUser
}
Esempio n. 2
0
func isUserTalking(e *eventsocket.Event) bool {
	talk, err := strconv.ParseBool(e.Get("Talking"))
	talking := false
	if err != nil {
		if talk {
			talking = false
		} else {
			talking = true
		}
	}

	return talking
}
Esempio n. 3
0
// AddEvent parses a FreeSWITCH EventSocket event and merges contained information into the FaxResult
func (f *FaxResult) AddEvent(ev *eventsocket.Event) {
	switch ev.Get("Event-Name") {
	case "CHANNEL_CALLSTATE":
		// Call state has changed
		callstate := ev.Get("Channel-Call-State")
		f.sessionlog.Log("Call state change:", callstate)
		if callstate == "ACTIVE" {
			f.StartTs = time.Now()
		}
		if callstate == "HANGUP" {
			f.EndTs = time.Now()
			f.Hangupcause = ev.Get("Hangup-Cause")
		}

	case "CUSTOM":
		// Fax results have changed
		action := ""
		switch ev.Get("Event-Subclass") {
		case "spandsp::rxfaxnegociateresult":
			fallthrough
		case "spandsp::txfaxnegociateresult":
			f.NegotiateCount++
			if ecm := ev.Get("Fax-Ecm-Used"); ecm == "on" {
				f.Ecm = true
			}
			f.RemoteID = ev.Get("Fax-Remote-Station-Id")
			if rate, err := strconv.ParseUint(ev.Get("Fax-Transfer-Rate"), 10, 0); err == nil {
				f.TransferRate = uint(rate)
			}
			f.sessionlog.Log(fmt.Sprintf("Remote ID: \"%v\", Transfer Rate: %v, ECM=%v", f.RemoteID, f.TransferRate, f.Ecm))

		case "spandsp::rxfaxpageresult":
			action = "received"
			fallthrough
		case "spandsp::txfaxpageresult":
			if action == "" {
				action = "sent"
			}
			// A page was transferred
			if pages, err := strconv.ParseUint(ev.Get("Fax-Document-Transferred-Pages"), 10, 0); err == nil {
				f.TransferredPages = uint(pages)
			}

			pr := new(PageResult)
			pr.Page = f.TransferredPages

			if badrows, err := strconv.ParseUint(ev.Get("Fax-Bad-Rows"), 10, 0); err == nil {
				pr.BadRows = uint(badrows)
			}
			pr.EncodingName = ev.Get("Fax-Encoding-Name")
			if imgsize, err := parseResolution(ev.Get("Fax-Image-Pixel-Size")); err == nil {
				pr.ImagePixelSize = *imgsize
			}
			if filesize, err := parseResolution(ev.Get("Fax-File-Image-Pixel-Size")); err == nil {
				pr.FilePixelSize = *filesize
			}
			if imgres, err := parseResolution(ev.Get("Fax-Image-Resolution")); err == nil {
				pr.ImageResolution = *imgres
			}
			if fileres, err := parseResolution(ev.Get("Fax-File-Image-Resolution")); err == nil {
				pr.FileResolution = *fileres
			}
			if size, err := strconv.ParseUint(ev.Get("Fax-Image-Size"), 10, 0); err == nil {
				pr.ImageSize = uint(size)
			}
			if badrowrun, err := strconv.ParseUint(ev.Get("Fax-Longest-Bad-Row-Run"), 10, 0); err == nil {
				pr.LongestBadRowRun = uint(badrowrun)
			}

			f.PageResults = append(f.PageResults, *pr)
			f.sessionlog.Log(fmt.Sprintf("Page %d %v: %v", f.TransferredPages, action, *pr))

		case "spandsp::rxfaxresult":
			fallthrough
		case "spandsp::txfaxresult":
			if totalpages, err := strconv.ParseUint(ev.Get("Fax-Document-Total-Pages"), 10, 0); err == nil {
				f.TotalPages = uint(totalpages)
			}
			if transferredpages, err := strconv.ParseUint(ev.Get("Fax-Document-Transferred-Pages"), 10, 0); err == nil {
				f.TransferredPages = uint(transferredpages)
			}
			if ecm := ev.Get("Fax-Ecm-Used"); ecm == "on" {
				f.Ecm = true
			}
			f.RemoteID = ev.Get("Fax-Remote-Station-Id")
			if resultcode, err := strconv.Atoi(ev.Get("Fax-Result-Code")); err == nil {
				f.ResultCode = resultcode
			}
			f.ResultText = ev.Get("Fax-Result-Text")
			if ev.Get("Fax-Success") == "1" {
				f.Success = true
			}
			if rate, err := strconv.ParseUint(ev.Get("Fax-Transfer-Rate"), 10, 0); err == nil {
				f.TransferRate = uint(rate)
			}

		}
	}

}
Esempio n. 4
0
func getSpeakFromEvent(e *eventsocket.Event) string {
	return e.Get("Speak")
}
Esempio n. 5
0
func getRecordFilenameFromEvent(e *eventsocket.Event) string {
	return e.Get("Path")
}
Esempio n. 6
0
func getCallerIdNameFromEvent(e *eventsocket.Event) string {
	return e.Get("Caller-Caller-ID-Name")
}
Esempio n. 7
0
func getCallerIdNumFromEvent(e *eventsocket.Event) string {
	return e.Get("Caller-Caller-ID-Number")
}
Esempio n. 8
0
func getMemberIdFromEvent(e *eventsocket.Event) string {
	return e.Get("Member-ID")
}