Skip to content

Commit 6fccaee

Browse files
committed
Server to client Chat working
1 parent 7b33809 commit 6fccaee

26 files changed

+96
-86
lines changed
18 KB
Binary file not shown.

SyncPlayWPF/SyncPlayWPF/Pages/NewSessionPage.xaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
<RowDefinition Height="auto"/>
5656
<RowDefinition Height="auto"/>
5757
</Grid.RowDefinitions>
58-
<custom:PromptingLabel Grid.Row="0" x:Name="ServerAddressField" PromptingText="Server Address" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
59-
<custom:PromptingLabel Grid.Row="1" x:Name="UsernameField" PromptingText="Username" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
58+
<custom:PromptingLabel Text="localhost:5005" Grid.Row="0" x:Name="ServerAddressField" PromptingText="Server Address" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
59+
<custom:PromptingLabel Text="sammy" Grid.Row="1" x:Name="UsernameField" PromptingText="Username" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
6060
<custom:PromptingPasswordBox Grid.Row="2" x:Name="PasswordField" PromptingText="Password" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
61-
<custom:PromptingLabel Grid.Row="3" x:Name="RoomNameField" PromptingText="Room Name" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
61+
<custom:PromptingLabel Text="ck" Grid.Row="3" x:Name="RoomNameField" PromptingText="Room Name" FocusedUnderlineBrush="{StaticResource DarkMode_ContrastedGradient}"/>
6262

6363
</Grid>
6464

SyncPlayWPF/SyncPlayWPF/Pages/NewSessionPage.xaml.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ private void JoinRoom_Clicked(object sender, RoutedEventArgs e) {
3636
$"Room Name : {roomName}");
3737

3838
Common.Shared.WindowPageTransition.ShowPage(new Pages.SessionLandingPage());
39-
39+
Common.Shared.Wrapper = new SyncPlay.SyncPlayWrapper(
40+
serverIp,
41+
serverPort,
42+
username,
43+
password,
44+
roomName,
45+
new SyncPlay.MediaPlayers.VLCMediaPlayer.Connector());
46+
4047
}
4148
}
4249
}

SyncPlayWPF/SyncPlayWPF/Pages/SessionPages/ChatSession.xaml

Lines changed: 2 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -18,66 +18,8 @@
1818

1919
<!-- Chat Messages -->
2020
<ScrollViewer Style="{StaticResource FavsScrollViewer}">
21-
<StackPanel Grid.Row="0" Margin="20,10,10,10">
22-
<custom:ChatMessage
23-
MessageContent="I use arch. Also Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc pharetra nisi nibh, nec ultricies dui placerat vel. Mauris sodales mollis est sed elementum. Pellentesque odio massa, pulvinar dictum semper eget, dignissim non velit. Nulla id sem vitae eros scelerisque dictum. Ut dictum dui in sagittis sodales. Pellentesque tincidunt diam eget lorem lacinia, sodales iaculis est aliquet. Aliquam erat volutpat. Donec a dui risus. Donec luctus volutpat eleifend. Nullam posuere gravida ipsum id rhoncus. Morbi faucibus at ex sit amet sodales."
24-
MessageSender="Jimbo"
25-
MessageTime="5:30 PM"
26-
Style="{StaticResource IncomingMessage}"/>
27-
<custom:ChatMessage
28-
MessageContent="Jim, I have no idea what you're talking about. Like for reals, I have no idea"
29-
MessageSender="Sammy"
30-
MessageTime="5:32 PM"
31-
Style="{StaticResource OutgoingMessage}"/>
32-
<custom:ChatMessage
33-
MessageContent="I'm just saying that Im using Arch. Nothing else."
34-
MessageSender="Jimbo"
35-
MessageTime="5:30 PM"
36-
Style="{StaticResource IncomingMessage}"/>
37-
<custom:ChatMessage
38-
MessageContent="No one cares, jim."
39-
MessageSender="Sammy"
40-
MessageTime="5:32 PM"
41-
Style="{StaticResource OutgoingMessage}"/>
42-
<custom:ChatMessage
43-
MessageContent="Literally no one"
44-
MessageSender="Sammy"
45-
MessageTime="5:32 PM"
46-
IsInitialMessage="False"
47-
Style="{StaticResource OutgoingMessage}"/>
48-
<custom:ChatMessage
49-
MessageContent="I hate you"
50-
MessageSender="Jimbo"
51-
MessageTime="5:30 PM"
52-
Style="{StaticResource IncomingMessage}"/>
53-
<custom:ChatMessage
54-
MessageContent="Hate you too bud"
55-
MessageSender="Sammy"
56-
MessageTime="5:32 PM"
57-
IsInitialMessage="True"
58-
Style="{StaticResource OutgoingMessage}"/>
59-
<custom:ChatMessage
60-
MessageContent="Okay sam, What operating system do you use?"
61-
MessageSender="Jimbo"
62-
MessageTime="5:30 PM"
63-
Style="{StaticResource IncomingMessage}"/>
64-
<custom:ChatMessage
65-
MessageContent="Windows"
66-
MessageSender="Sammy"
67-
MessageTime="5:32 PM"
68-
IsInitialMessage="True"
69-
Style="{StaticResource OutgoingMessage}"/>
70-
<custom:ChatMessage
71-
MessageContent="Why?"
72-
MessageSender="Sammy"
73-
MessageTime="5:32 PM"
74-
IsInitialMessage="False"
75-
Style="{StaticResource OutgoingMessage}"/>
76-
<custom:ChatMessage
77-
MessageContent="Windows... That explains a lot. Explains so, so much."
78-
MessageSender="Jimbo"
79-
MessageTime="5:30 PM"
80-
Style="{StaticResource IncomingMessage}"/>
21+
<StackPanel Grid.Row="0" Margin="20,10,10,10" x:Name="MessageStack">
22+
8123
</StackPanel>
8224
</ScrollViewer>
8325

SyncPlayWPF/SyncPlayWPF/Pages/SessionPages/ChatSession.xaml.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,29 @@ namespace SyncPlayWPF.Pages.SessionPages {
2020
public partial class ChatSession : UserControl {
2121
public ChatSession() {
2222
InitializeComponent();
23+
24+
this.Loaded += OnPageLoad;
25+
}
26+
27+
private void OnPageLoad(object sender, RoutedEventArgs e) {
28+
Common.Shared.Wrapper.SyncPlayClient.OnNewChatMessage += NewChatMessage;
29+
}
30+
31+
private void NewChatMessage(SyncPlay.SyncPlayClient sender, SyncPlay.EventArgs.ChatMessageEventArgs e) {
32+
Console.WriteLine("NEW MESSAGE!");
33+
Dispatcher.Invoke(() => {
34+
var msgballoon = new CustomControls.ChatMessage();
35+
msgballoon.Style = (Style)this.FindResource("IncomingMessage");
36+
msgballoon.MessageSender = e.Sender.Username;
37+
msgballoon.MessageContent = e.Message;
38+
msgballoon.MessageTime = DateTime.Now.ToString("hh:mm tt");
39+
40+
var text = new TextBlock();
41+
text.Text = e.Message;
42+
43+
MessageStack.Children.Add(msgballoon);
44+
});
45+
2346
}
2447
}
2548
}

SyncPlayWPF/SyncPlayWPF/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("2021.201.46.0")]
55-
[assembly: AssemblyFileVersion("2021.201.46.0")]
54+
[assembly: AssemblyVersion("2021.201.63.0")]
55+
[assembly: AssemblyFileVersion("2021.201.63.0")]

SyncPlayWPF/SyncPlayWPF/SyncPlay/NetworkClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public bool Connect() {
3333
}
3434

3535
public void SendMessage(string Message) {
36-
Console.WriteLine(Message);
36+
//Console.WriteLine(Message);
3737
var bytes = Encoding.ASCII.GetBytes(Message);
3838
stream.Write(bytes, 0, bytes.Length);
3939
stream.Flush();
@@ -67,7 +67,7 @@ private void ProcessIncoming() {
6767
private void NotifySubscribersOnNewMessage(String message) {
6868
if (String.IsNullOrWhiteSpace(message)) return;
6969
//Misc.Common.PrintInColor(message, ConsoleColor.Yellow);
70-
Console.WriteLine(message);
70+
//Console.WriteLine(message);
7171
if (OnNewMessage == null) return;
7272
OnNewMessage(this, message);
7373
}

SyncPlayWPF/SyncPlayWPF/SyncPlay/Client.cs renamed to SyncPlayWPF/SyncPlayWPF/SyncPlay/SyncPlayClient.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public class SyncPlayClient {
2626
private bool Seeked = false;
2727
private bool clientIgnoreOnFly = false;
2828

29+
//TODO: Fix the issue where the client has no idea what users were in the session before joining. This crashing every time one of them sends a message.
30+
2931
#region Front Facing Accessors
3032
/// <summary>
3133
/// This function will get the pause state of the client
@@ -40,7 +42,7 @@ public bool GetPause() {
4042
/// </summary>
4143
/// <param name="state">Boolean state</param>
4244
public void SetPause(bool state) {
43-
OnDebugLog(this, state ? "Client Paused" : "Client Resumed");
45+
OnDebugLog?.Invoke(this, state ? "Client Paused" : "Client Resumed");
4446
clientIgnoreOnFly = true;
4547
this.isPaused = state;
4648
}
@@ -280,10 +282,10 @@ private void NewIncomingMessage(NetworkClient sender, string message) {
280282
var username = chatkey.Value<String>("username");
281283
var chatmessage = chatkey.Value<String>("message");
282284
Misc.Common.PrintInColor($"The user {username} said '{chatmessage}'", ConsoleColor.Green);
283-
OnDebugLog(this, $"The user {username} said '{chatmessage}'");
285+
OnDebugLog?.Invoke(this, $"The user {username} said '{chatmessage}'");
284286
if (OnNewChatMessage != null) {
285287
User s;
286-
UserDictionary.TryGetValue(username, out s);
288+
if (!UserDictionary.TryGetValue(username, out s)) throw new Exception($"Cannot find user {username}");
287289
var args = new EventArgs.ChatMessageEventArgs(s, chatmessage);
288290
OnNewChatMessage(this, args);
289291
}
@@ -331,12 +333,12 @@ private void NewIncomingMessage(NetworkClient sender, string message) {
331333

332334
switch (eventName) {
333335
case "joined":
334-
OnDebugLog(this, $"The user {username} has joined the room");
336+
OnDebugLog?.Invoke(this, $"The user {username} has joined the room");
335337
AddNewUser(username);
336338
break;
337339

338340
case "left":
339-
OnDebugLog(this, $"The user {username} has left the room");
341+
OnDebugLog?.Invoke(this, $"The user {username} has left the room");
340342
RemoveUser(username);
341343
break;
342344

@@ -356,7 +358,7 @@ private void NewIncomingMessage(NetworkClient sender, string message) {
356358
filesetargs.File = user.File;
357359

358360
OnFileSet?.Invoke(this, filesetargs);
359-
OnDebugLog(this, $"The user {username} has loaded the file {filename}");
361+
OnDebugLog?.Invoke(this, $"The user {username} has loaded the file {filename}");
360362
}
361363
}
362364
#endregion
@@ -403,7 +405,7 @@ private void NewIncomingMessage(NetworkClient sender, string message) {
403405
if ((bool)playstatekey["doSeek"]) {
404406

405407
playPosition = serverPosition;
406-
OnDebugLog(this, $"Seeking to {Misc.Common.ConvertSecondsToTimeStamp((int)playPosition)}");
408+
OnDebugLog?.Invoke(this, $"Seeking to {Misc.Common.ConvertSecondsToTimeStamp((int)playPosition)}");
407409

408410
// Create an even args object to notify the player that it needs to seek because someone on the
409411
// server side seeked

SyncPlayWPF/SyncPlayWPF/SyncPlay/SyncPlayWrapper.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66

77
namespace SyncPlay {
88
public class SyncPlayWrapper {
9-
public SyncPlayClient SClient;
9+
public SyncPlayClient SyncPlayClient;
1010
public MediaPlayerInterface Player;
1111
public int RemoteSeekOffset = 1;
1212

1313
public SyncPlayWrapper(string serverip, int port, string username, string password, string room, MediaPlayerInterface mp) {
14-
this.SClient = new SyncPlayClient(serverip, port, username, password, room, "1.6.8");
14+
this.SyncPlayClient = new SyncPlayClient(serverip, port, username, password, room, "1.6.8");
1515
Player = mp;
1616

17-
mp.OnSeek += SClient.SetPlayPosition;
18-
mp.OnPauseStateChange += SClient.SetPause;
17+
mp.OnSeek += SyncPlayClient.SetPlayPosition;
18+
mp.OnPauseStateChange += SyncPlayClient.SetPause;
1919

20-
SClient.OnPlayerStateChange += PlayerStateChanged;
20+
SyncPlayClient.OnPlayerStateChange += PlayerStateChanged;
2121

2222
mp.StartPlayerInstance();
2323
}
-1 KB
Binary file not shown.

0 commit comments

Comments
 (0)