Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Manu
DirectoTalk.Sender
Commits
8e640def
Commit
8e640def
authored
Mar 21, 2020
by
Manu
🏅
Browse files
Implement waveOut sender logic
parent
06aba6fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
DirectoTalk.Sender/CallingMachine.cs
View file @
8e640def
...
...
@@ -13,9 +13,9 @@ namespace DirectoTalk.Sender
private
WaveIn
waveSource
=
null
;
public
CallingMachine
(
string
ipToCall
)
public
CallingMachine
(
string
destinationAddress
,
int
destinationPort
)
{
NetworkHandler
=
new
NetworkHandler
(
ipToCall
);
NetworkHandler
=
new
NetworkHandler
(
destinationAddress
,
destinationPort
);
}
public
void
StartCall
()
...
...
DirectoTalk.Sender/NetworkHandler.cs
View file @
8e640def
using
System
;
using
System.Net.Http
;
using
System.Net.Http.Headers
;
using
System.Net.Sockets
;
using
System.Threading.Tasks
;
namespace
DirectoTalk.Sender
{
public
class
NetworkHandler
:
IDisposable
{
private
readonly
HttpClient
h
ttpClient
=
new
HttpClient
();
private
readonly
HttpClient
_H
ttpClient
=
new
HttpClient
();
public
NetworkHandler
(
string
destinationAddress
)
private
readonly
string
_DestinationAddress
;
private
readonly
int
_DestinationPort
;
private
readonly
UdpClient
_UdpClient
;
public
NetworkHandler
(
string
destinationAddress
,
int
destinationPort
)
{
httpClient
.
BaseAddress
=
new
Uri
(
destinationAddress
);
_DestinationAddress
=
destinationAddress
;
_DestinationPort
=
destinationPort
;
_UdpClient
=
new
UdpClient
();
}
public
async
Task
<
SendResult
>
SendAudio
(
byte
[]
buffer
)
{
ByteArrayContent
binaryContent
=
new
ByteArrayContent
(
buffer
);
try
{
_
=
Task
.
Run
(
async
()
=>
await
SendUdpPacket
(
buffer
).
ConfigureAwait
(
false
));
return
new
SendResult
(
"OK"
,
"packet on the way"
);
}
catch
(
Exception
ex
)
{
return
new
SendResult
(
"Error"
,
ex
.
Message
);
}
}
/// <summary>
/// Asynchronously sends a UDP package with the given content.
/// </summary>
/// <param name="sourcePort"></param>
/// <param name="destinationAddress"></param>
/// <param name="destinationPort"></param>
/// <param name="data"></param>
private
async
Task
SendUdpPacket
(
byte
[]
data
)
{
await
_UdpClient
.
SendAsync
(
data
,
data
.
Length
,
_DestinationAddress
,
_DestinationPort
).
ConfigureAwait
(
false
);
}
private
async
Task
<
SendResult
>
SendTcpPacket
(
byte
[]
data
)
{
ByteArrayContent
binaryContent
=
new
ByteArrayContent
(
data
);
binaryContent
.
Headers
.
ContentType
=
new
MediaTypeHeaderValue
(
"application/octet-stream"
);
using
(
var
httpRequest
=
new
HttpRequestMessage
())
...
...
@@ -24,19 +57,19 @@ namespace DirectoTalk.Sender
httpRequest
.
Content
=
binaryContent
;
try
{
HttpResponseMessage
response
=
await
h
ttpClient
.
SendAsync
(
httpRequest
).
ConfigureAwait
(
false
);
HttpResponseMessage
response
=
await
_H
ttpClient
.
SendAsync
(
httpRequest
).
ConfigureAwait
(
false
);
return
new
SendResult
(
response
.
StatusCode
.
ToString
(),
await
response
.
Content
.
ReadAsStringAsync
().
ConfigureAwait
(
false
));
}
catch
(
Exception
ex
)
{
return
new
SendResult
(
"
XXX
"
,
$"
{
ex
.
Message
}
{
ex
.
InnerException
?.
Message
}
"
);
return
new
SendResult
(
"
Err
"
,
$"
{
ex
.
Message
}
{
ex
.
InnerException
?.
Message
}
"
);
}
}
}
public
void
Dispose
()
{
h
ttpClient
.
Dispose
();
_H
ttpClient
.
Dispose
();
}
}
}
\ No newline at end of file
DirectoTalk.Sender/TalkWindow.xaml
View file @
8e640def
...
...
@@ -21,8 +21,8 @@
<TextBox Margin="10" Padding="5" Text="127.0.0.1"></TextBox>
</DockPanel>
<DockPanel Grid.Row="0" Grid.Column="1" >
<Label Margin="10" Padding="5">
Unused
:</Label>
<TextBox Margin="10" Padding="5"></TextBox>
<Label Margin="10" Padding="5">
Destination port
:</Label>
<TextBox Margin="10" Padding="5"
Text="{Binding DestinationPort}"
></TextBox>
</DockPanel>
<Button Grid.Row="1" Grid.Column="0" Margin="10" Padding="5" Click="CallButton_Click" IsEnabled="{Binding IsCallEnabled}">TRANSMIT VOICE</Button>
<Button Grid.Row="1" Grid.Column="1" Margin="10" Padding="5" Click="HangUpButton_Click" IsEnabled="{Binding IsHangUpEnabled}">HANG UP</Button>
...
...
DirectoTalk.Sender/ViewModels/TalkViewModel.cs
View file @
8e640def
...
...
@@ -8,20 +8,34 @@ namespace DirectoTalk.Sender.ViewModels
public
TalkViewModel
()
{
CallingMachine
=
new
CallingMachine
(
IpToCall
);
CallingMachine
=
new
CallingMachine
(
DestinationAddress
,
DestinationPort
);
}
private
string
ipToCall
=
"https://
127.0.0.1"
;
public
string
IpToCall
private
string
destinationAddress
=
"
127.0.0.1"
;
public
string
DestinationAddress
{
get
{
return
ipToCall
;
return
destinationAddress
;
}
set
{
ipToCall
=
value
;
OnPropertyChanged
(
nameof
(
IpToCall
));
destinationAddress
=
value
;
OnPropertyChanged
(
nameof
(
DestinationAddress
));
}
}
private
int
destinationPort
=
42000
;
public
int
DestinationPort
{
get
{
return
destinationPort
;
}
set
{
destinationPort
=
value
;
OnPropertyChanged
(
nameof
(
DestinationPort
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment