Skip to content

Commit 718cbff

Browse files
chore: revise chat example and update to latest version
1 parent 9bdebdb commit 718cbff

File tree

5 files changed

+144
-74
lines changed

5 files changed

+144
-74
lines changed

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/ChatPeerToPeer/Hubs/ChatHub.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ namespace Telerik.Examples.Mvc.Areas.ChatPeerToPeer.Hubs
44
{
55
public class ChatHub : Hub
66
{
7-
public void Send(object sender, string message)
7+
public void Send(string senderId, string senderName, string message)
88
{
9-
Clients.Others.broadcastMessage(sender, message);
9+
// Broadcast the message to all clients except the sender.
10+
Clients.Others.broadcastMessage(senderId, senderName, message);
1011
}
11-
public void SendTyping(object sender)
12+
13+
public void SendTyping(string senderId, string senderName)
1214
{
13-
Clients.Others.typing(sender);
15+
// Broadcast the typing notification to all clients except the sender.
16+
Clients.Others.typing(senderId, senderName);
1417
}
1518
}
1619
}

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/ChatPeerToPeer/Views/Home/Index.cshtml

Lines changed: 82 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,103 @@
1212

1313
@(Html.Kendo().Chat()
1414
.Name("chat")
15-
.User(user => user
16-
.Name(@name)
17-
.IconUrl("https://demos.telerik.com/kendo-ui/content/chat/avatar.png")
18-
)
15+
.AuthorId(@name)
16+
.IsTypingField("isTyping")
17+
.FileAttachment(false)
1918
.Events(events => events
20-
.TypingStart("onTypingStart")
21-
.Post("onPost")
19+
.Input("onInput")
20+
.SendMessage("onSendMessage")
2221
)
2322
)
2423

2524
<script>
26-
function startHub(startCallback) {
27-
var hub = $.connection.chatHub;
25+
const currentUser = {
26+
id: '@name',
27+
name: 'User123',
28+
iconUrl: "https://demos.telerik.com/kendo-ui/content/chat/avatar.png"
29+
};
30+
var isTyping = false;
31+
var chatHub;
2832
29-
$.connection.hub.start().done(function () {
30-
startCallback(hub)
31-
});
33+
$(function () {
34+
chatHub = $.connection.chatHub;
3235
33-
return hub;
34-
}
36+
chatHub.client.broadcastMessage = function (senderId, senderName, message) {
37+
const chat = $("#chat").getKendoChat();
3538
36-
$(document).ready(function () {
37-
window.chat = $('#chat').getKendoChat();
38-
window.chatHub = startHub(function (hub) { });
39+
// Check for a "typing" message.
40+
let typingMessages = $.grep(chat.dataSource.data(), function (item) {
41+
return item.isTyping == true ? item.id : "";
42+
});
3943
40-
chatHub.on("broadcastMessage", function (sender, message) {
41-
var message = {
42-
type: "text",
43-
text: message
44-
};
44+
if (typingMessages.length > 0) {
45+
if (typingMessages[0].id != null) {
46+
let messageObject = chat.dataSource.get(typingMessages[0].id);
47+
if (messageObject) {
48+
// Update the "typing" message with the received message text.
49+
let updatedMessage = chat.updateMessage(messageObject, {
50+
text: message,
51+
isTyping: false
52+
});
53+
}
54+
}
55+
} else {
56+
// Post the received message in the Chat.
57+
chat.postMessage({
58+
id: kendo.guid(),
59+
authorId: senderId,
60+
authorName: senderId,
61+
authorImageUrl: currentUser.iconUrl,
62+
text: message,
63+
isTyping: false
64+
});
65+
}
66+
};
4567
46-
chat.renderMessage(message, sender);
47-
});
68+
chatHub.client.typing = function (senderId, senderName) {
69+
console.log(senderName + ' is typing');
70+
const chat = $("#chat").getKendoChat();
4871
49-
chatHub.on("typing", function (sender) {
50-
chat.renderMessage({ type: "typing" }, sender);
72+
chat.postMessage({
73+
id: kendo.guid(),
74+
isTyping: true,
75+
authorId: senderId,
76+
authorName: senderId,
77+
authorImageUrl: currentUser.iconUrl
78+
});
79+
};
80+
81+
// Start the connection.
82+
$.connection.hub.start().done(function () {
83+
console.log('SignalR connection started.');
84+
}).fail(function (err) {
85+
console.error('Error starting SignalR connection: ' + err.toString());
5186
});
5287
});
5388
54-
function onTypingStart(e) {
55-
chatHub.invoke("sendTyping", chat.getUser());
89+
// The 'Input' will notify the SignallR Hub that the current client is typing.
90+
// The Hub, in turn, will notify all the other clients that the user has started typing.
91+
function onInput(e) {
92+
// If not already typing, send typing notification.
93+
if (!isTyping) {
94+
isTyping = true;
95+
chatHub.server.sendTyping(currentUser.id, currentUser.name);
96+
}
5697
}
5798
58-
function onPost(args) {
59-
chatHub.invoke("send", chat.getUser(), args.text);
99+
// The 'SendMessage' handler will send the user data and the typed text to the SignalR Hub.
100+
// The Hub will then forward that info to the other clients.
101+
function onSendMessage(args) {
102+
// Update the message data based on the current user's data.
103+
args.message.id = kendo.guid();
104+
args.message.authorId = currentUser.id;
105+
args.message.authorName = currentUser.name;
106+
args.message.authorImageUrl = currentUser.iconUrl;
107+
108+
// Stop typing when sending a message.
109+
if (isTyping) {
110+
isTyping = false;
111+
}
112+
chatHub.server.send(args.message.authorId, args.message.authorName, args.message.text);
60113
}
61114
</script>
62-

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Telerik.Examples.Mvc.csproj

Lines changed: 41 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,8 @@
182182
<Reference Include="jsoup-1.15.3, Version=13.10.0.0, Culture=neutral, PublicKeyToken=8783d630753e2b3f, processorArchitecture=MSIL">
183183
<HintPath>..\packages\net.sf.mpxj-for-csharp.13.10.0\lib\net45\jsoup-1.15.3.dll</HintPath>
184184
</Reference>
185-
<Reference Include="Kendo.Mvc, Version=2025.2.520.462, Culture=neutral, PublicKeyToken=121fae78165ba3d4, processorArchitecture=MSIL">
186-
<HintPath>..\packages\Telerik.UI.for.AspNet.Mvc5.Lite.2025.2.520\lib\net462\Kendo.Mvc.dll</HintPath>
185+
<Reference Include="Kendo.Mvc, Version=2025.3.825.462, Culture=neutral, PublicKeyToken=121fae78165ba3d4, processorArchitecture=MSIL">
186+
<HintPath>..\packages\Telerik.UI.for.AspNet.Mvc5.Lite.2025.3.825\lib\net462\Kendo.Mvc.dll</HintPath>
187187
</Reference>
188188
<Reference Include="log4j-api-2.17.2, Version=13.10.0.0, Culture=neutral, PublicKeyToken=8783d630753e2b3f, processorArchitecture=MSIL">
189189
<HintPath>..\packages\net.sf.mpxj-for-csharp.13.10.0\lib\net45\log4j-api-2.17.2.dll</HintPath>
@@ -506,38 +506,38 @@
506506
<Private>True</Private>
507507
<Private>True</Private>
508508
</Reference>
509-
<Reference Include="Telerik.Documents.Core, Version=2025.2.520.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
510-
<HintPath>..\packages\Telerik.Documents.Core.2025.2.520\lib\netstandard2.0\Telerik.Documents.Core.dll</HintPath>
509+
<Reference Include="Telerik.Documents.Core, Version=2025.3.806.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
510+
<HintPath>..\packages\Telerik.Documents.Core.2025.3.806\lib\netstandard2.0\Telerik.Documents.Core.dll</HintPath>
511511
</Reference>
512-
<Reference Include="Telerik.Documents.Fixed, Version=2025.2.520.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
513-
<HintPath>..\packages\Telerik.Documents.Fixed.2025.2.520\lib\netstandard2.0\Telerik.Documents.Fixed.dll</HintPath>
512+
<Reference Include="Telerik.Documents.Fixed, Version=2025.3.806.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
513+
<HintPath>..\packages\Telerik.Documents.Fixed.2025.3.806\lib\netstandard2.0\Telerik.Documents.Fixed.dll</HintPath>
514514
</Reference>
515-
<Reference Include="Telerik.Documents.ImageUtils, Version=2025.2.520.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
516-
<HintPath>..\packages\Telerik.Documents.ImageUtils.2025.2.520\lib\netstandard2.0\Telerik.Documents.ImageUtils.dll</HintPath>
515+
<Reference Include="Telerik.Documents.ImageUtils, Version=2025.3.806.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
516+
<HintPath>..\packages\Telerik.Documents.ImageUtils.2025.3.806\lib\netstandard2.0\Telerik.Documents.ImageUtils.dll</HintPath>
517517
</Reference>
518-
<Reference Include="Telerik.FontIcons, Version=4.3.0.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
519-
<HintPath>..\packages\Telerik.FontIcons.4.3.0\lib\netstandard2.0\Telerik.FontIcons.dll</HintPath>
518+
<Reference Include="Telerik.FontIcons, Version=4.5.0.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
519+
<HintPath>..\packages\Telerik.FontIcons.4.5.0\lib\netstandard2.0\Telerik.FontIcons.dll</HintPath>
520520
</Reference>
521-
<Reference Include="Telerik.Licensing.Runtime, Version=1.6.5.0, Culture=neutral, PublicKeyToken=98bb5b04e55c09ef, processorArchitecture=MSIL">
522-
<HintPath>..\packages\Telerik.Licensing.1.6.5\lib\net462\Telerik.Licensing.Runtime.dll</HintPath>
521+
<Reference Include="Telerik.Licensing.Runtime, Version=1.6.16.0, Culture=neutral, PublicKeyToken=98bb5b04e55c09ef, processorArchitecture=MSIL">
522+
<HintPath>..\packages\Telerik.Licensing.1.6.16\lib\net462\Telerik.Licensing.Runtime.dll</HintPath>
523523
</Reference>
524-
<Reference Include="Telerik.SvgIcons, Version=4.3.0.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
525-
<HintPath>..\packages\Telerik.SvgIcons.4.3.0\lib\netstandard2.0\Telerik.SvgIcons.dll</HintPath>
524+
<Reference Include="Telerik.SvgIcons, Version=4.5.0.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
525+
<HintPath>..\packages\Telerik.SvgIcons.4.5.0\lib\netstandard2.0\Telerik.SvgIcons.dll</HintPath>
526526
</Reference>
527-
<Reference Include="Telerik.Web.Captcha, Version=2.0.2.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
528-
<HintPath>..\packages\Telerik.Web.Captcha.2.0.2\lib\net462\Telerik.Web.Captcha.dll</HintPath>
527+
<Reference Include="Telerik.Web.Captcha, Version=2.0.3.0, Culture=neutral, PublicKeyToken=20b4b0547069c4f8, processorArchitecture=MSIL">
528+
<HintPath>..\packages\Telerik.Web.Captcha.2.0.3\lib\net462\Telerik.Web.Captcha.dll</HintPath>
529529
</Reference>
530-
<Reference Include="Telerik.Windows.Documents.Core, Version=2025.2.520.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
531-
<HintPath>..\packages\Telerik.Windows.Documents.Core.2025.2.520\lib\net462\Telerik.Windows.Documents.Core.dll</HintPath>
530+
<Reference Include="Telerik.Windows.Documents.Core, Version=2025.3.806.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
531+
<HintPath>..\packages\Telerik.Windows.Documents.Core.2025.3.806\lib\net462\Telerik.Windows.Documents.Core.dll</HintPath>
532532
</Reference>
533-
<Reference Include="Telerik.Windows.Documents.Flow, Version=2025.2.520.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
534-
<HintPath>..\packages\Telerik.Windows.Documents.Flow.2025.2.520\lib\net462\Telerik.Windows.Documents.Flow.dll</HintPath>
533+
<Reference Include="Telerik.Windows.Documents.Flow, Version=2025.3.806.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
534+
<HintPath>..\packages\Telerik.Windows.Documents.Flow.2025.3.806\lib\net462\Telerik.Windows.Documents.Flow.dll</HintPath>
535535
</Reference>
536-
<Reference Include="Telerik.Windows.Zip, Version=2025.2.520.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
537-
<HintPath>..\packages\Telerik.Windows.Zip.2025.2.520\lib\net462\Telerik.Windows.Zip.dll</HintPath>
536+
<Reference Include="Telerik.Windows.Zip, Version=2025.3.806.462, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
537+
<HintPath>..\packages\Telerik.Windows.Zip.2025.3.806\lib\net462\Telerik.Windows.Zip.dll</HintPath>
538538
</Reference>
539-
<Reference Include="Telerik.Zip, Version=2025.2.520.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
540-
<HintPath>..\packages\Telerik.Zip.2025.2.520\lib\netstandard2.0\Telerik.Zip.dll</HintPath>
539+
<Reference Include="Telerik.Zip, Version=2025.3.806.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7, processorArchitecture=MSIL">
540+
<HintPath>..\packages\Telerik.Zip.2025.3.806\lib\netstandard2.0\Telerik.Zip.dll</HintPath>
541541
</Reference>
542542
<Reference Include="txw2-3.0.2, Version=13.10.0.0, Culture=neutral, PublicKeyToken=8783d630753e2b3f, processorArchitecture=MSIL">
543543
<HintPath>..\packages\net.sf.mpxj-for-csharp.13.10.0\lib\net45\txw2-3.0.2.dll</HintPath>
@@ -2793,6 +2793,21 @@
27932793
<Content Include="Content\kendo\2025.2.520\razor\Country.cshtml" />
27942794
<Content Include="Content\kendo\2025.2.520\razor\Boolean.cshtml" />
27952795
<Content Include="Content\kendo\2025.2.520\razor\AdaptiveProductCustomEditor.cshtml" />
2796+
<Content Include="Content\kendo\2025.3.825\razor\Url.cshtml" />
2797+
<Content Include="Content\kendo\2025.3.825\razor\Time.cshtml" />
2798+
<Content Include="Content\kendo\2025.3.825\razor\String.cshtml" />
2799+
<Content Include="Content\kendo\2025.3.825\razor\Password.cshtml" />
2800+
<Content Include="Content\kendo\2025.3.825\razor\Number.cshtml" />
2801+
<Content Include="Content\kendo\2025.3.825\razor\Integer.cshtml" />
2802+
<Content Include="Content\kendo\2025.3.825\razor\GridForeignKey.cshtml" />
2803+
<Content Include="Content\kendo\2025.3.825\razor\EmailAddress.cshtml" />
2804+
<Content Include="Content\kendo\2025.3.825\razor\Email.cshtml" />
2805+
<Content Include="Content\kendo\2025.3.825\razor\DateTime.cshtml" />
2806+
<Content Include="Content\kendo\2025.3.825\razor\Date.cshtml" />
2807+
<Content Include="Content\kendo\2025.3.825\razor\Currency.cshtml" />
2808+
<Content Include="Content\kendo\2025.3.825\razor\Country.cshtml" />
2809+
<Content Include="Content\kendo\2025.3.825\razor\Boolean.cshtml" />
2810+
<Content Include="Content\kendo\2025.3.825\razor\AdaptiveProductCustomEditor.cshtml" />
27962811
<None Include="packages.config" />
27972812
<Content Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" />
27982813
<Content Include="Images\200.png" />
@@ -5318,13 +5333,13 @@
53185333
<Error Condition="!Exists('..\packages\net.sf.mpxj-ikvm.11.1.0\build\net.sf.mpxj-ikvm.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\net.sf.mpxj-ikvm.11.1.0\build\net.sf.mpxj-ikvm.targets'))" />
53195334
<Error Condition="!Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets'))" />
53205335
<Error Condition="!Exists('..\packages\net.sf.mpxj-for-csharp.13.10.0\build\net.sf.mpxj-for-csharp.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\net.sf.mpxj-for-csharp.13.10.0\build\net.sf.mpxj-for-csharp.targets'))" />
5321-
<Error Condition="!Exists('..\packages\Telerik.Licensing.1.6.5\build\Telerik.Licensing.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Telerik.Licensing.1.6.5\build\Telerik.Licensing.targets'))" />
5336+
<Error Condition="!Exists('..\packages\Telerik.Licensing.1.6.16\build\Telerik.Licensing.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Telerik.Licensing.1.6.16\build\Telerik.Licensing.targets'))" />
53225337
</Target>
53235338
<Import Project="..\packages\EntityFramework.6.5.1\build\EntityFramework.targets" Condition="Exists('..\packages\EntityFramework.6.5.1\build\EntityFramework.targets')" />
53245339
<Import Project="..\packages\net.sf.mpxj-ikvm.11.1.0\build\net.sf.mpxj-ikvm.targets" Condition="Exists('..\packages\net.sf.mpxj-ikvm.11.1.0\build\net.sf.mpxj-ikvm.targets')" />
53255340
<Import Project="..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets" Condition="Exists('..\packages\NETStandard.Library.2.0.3\build\netstandard2.0\NETStandard.Library.targets')" />
53265341
<Import Project="..\packages\net.sf.mpxj-for-csharp.13.10.0\build\net.sf.mpxj-for-csharp.targets" Condition="Exists('..\packages\net.sf.mpxj-for-csharp.13.10.0\build\net.sf.mpxj-for-csharp.targets')" />
5327-
<Import Project="..\packages\Telerik.Licensing.1.6.5\build\Telerik.Licensing.targets" Condition="Exists('..\packages\Telerik.Licensing.1.6.5\build\Telerik.Licensing.targets')" />
5342+
<Import Project="..\packages\Telerik.Licensing.1.6.16\build\Telerik.Licensing.targets" Condition="Exists('..\packages\Telerik.Licensing.1.6.16\build\Telerik.Licensing.targets')" />
53285343
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
53295344
Other similar extension points exist, see Microsoft.Common.targets.
53305345
<Target Name="BeforeBuild">

Telerik.Examples.Mvc/Telerik.Examples.Mvc/Views/Shared/_Layout.cshtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<meta name="viewport" content="width=device-width, initial-scale=1">
66
<title>@ViewBag.Title - My Telerik MVC Application</title>
77
@{
8-
var kendoVersion = "2025.2.520";
9-
var themeVersion = "11.0.2";
8+
var kendoVersion = "2025.3.825";
9+
var themeVersion = "12.0.0";
1010

1111
string path = Server.MapPath("~/Areas");
1212
List<string> allfiles = Directory.GetDirectories(path, "*", SearchOption.TopDirectoryOnly).ToList();

Telerik.Examples.Mvc/Telerik.Examples.Mvc/packages.config

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,17 @@
106106
<package id="System.ValueTuple" version="4.5.0" targetFramework="net48" />
107107
<package id="System.Xml.ReaderWriter" version="4.3.1" targetFramework="net48" />
108108
<package id="System.Xml.XDocument" version="4.3.0" targetFramework="net48" />
109-
<package id="Telerik.Documents.Core" version="2025.2.520" targetFramework="net48" />
110-
<package id="Telerik.Documents.Fixed" version="2025.2.520" targetFramework="net48" />
111-
<package id="Telerik.Documents.ImageUtils" version="2025.2.520" targetFramework="net48" />
112-
<package id="Telerik.FontIcons" version="4.3.0" targetFramework="net48" />
113-
<package id="Telerik.Licensing" version="1.6.5" targetFramework="net48" />
114-
<package id="Telerik.SvgIcons" version="4.3.0" targetFramework="net48" />
115-
<package id="Telerik.UI.for.AspNet.Mvc5.Lite" version="2025.2.520" targetFramework="net48" />
116-
<package id="Telerik.Web.Captcha" version="2.0.2" targetFramework="net48" />
117-
<package id="Telerik.Windows.Documents.Core" version="2025.2.520" targetFramework="net48" />
118-
<package id="Telerik.Windows.Documents.Flow" version="2025.2.520" targetFramework="net48" />
119-
<package id="Telerik.Windows.Zip" version="2025.2.520" targetFramework="net48" />
120-
<package id="Telerik.Zip" version="2025.2.520" targetFramework="net48" />
109+
<package id="Telerik.Documents.Core" version="2025.3.806" targetFramework="net48" />
110+
<package id="Telerik.Documents.Fixed" version="2025.3.806" targetFramework="net48" />
111+
<package id="Telerik.Documents.ImageUtils" version="2025.3.806" targetFramework="net48" />
112+
<package id="Telerik.FontIcons" version="4.5.0" targetFramework="net48" />
113+
<package id="Telerik.Licensing" version="1.6.16" targetFramework="net48" />
114+
<package id="Telerik.SvgIcons" version="4.5.0" targetFramework="net48" />
115+
<package id="Telerik.UI.for.AspNet.Mvc5.Lite" version="2025.3.825" targetFramework="net48" />
116+
<package id="Telerik.Web.Captcha" version="2.0.3" targetFramework="net48" />
117+
<package id="Telerik.Windows.Documents.Core" version="2025.3.806" targetFramework="net48" />
118+
<package id="Telerik.Windows.Documents.Flow" version="2025.3.806" targetFramework="net48" />
119+
<package id="Telerik.Windows.Zip" version="2025.3.806" targetFramework="net48" />
120+
<package id="Telerik.Zip" version="2025.3.806" targetFramework="net48" />
121121
<package id="WebGrease" version="1.6.0" targetFramework="net48" />
122122
</packages>

0 commit comments

Comments
 (0)