Click here to Skip to main content
14,544,882 members
Rate this:
Please Sign up or sign in to vote.
See more:
I searched and tried many way but I couldn't. There are information about group chat on web but there are not about private chat. what way should i follow? Can u share article or advice about this? This is my last stage of my project. Please.

public void Send(string user, string content, string recipientId,string image)
    var sender = _userService.GetByUserName(Context.User.Identity.Name);
    Message message = new Message
        Content = content,
        RecipientId = recipientId,
        SenderId = sender.Id
    Clients.Users(recipientId, sender.Id).SendAsync("ReceiveMessage", user, content, image);

<pre>"use strict";

var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub").build();

connection.on("ReceiveMessage", function (user, content,image) {
    var d = new Date();
    var date = d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
    var msg = content;
    var kullanici = user;
    var img = new Image();
    img.src =image;

    document.querySelector("#messageList").innerHTML += "<li class='left clearfix'>" +
        "<span class='chat-img pull-left'>"
        + "<img src='"+ img.src + "' width='50' height='50'/>" +
        "</span>" +
        "<div class='chat-body clearfix' style='color: white'>" +
        " <div class='header'>" +
        "" style="color: blue">" + kullanici + "" + "<small class='pull-right text-muted'>" +
        "<span class='glyphicon glyphicon - time'>" + "</span>" + date +
        " </small >" +
        "</div >" +
        " <p style='color:white'>" +
        msg +
        "</p >" +
        "</div >" +
        " </li >";


connection.start().then(function () {
    document.querySelector("#sendButton").disabled = false;
}).catch(function (err) {
    return console.error(err.toString());

document.querySelector("#sendButton").addEventListener("click", function (event) {
    var user = document.querySelector("#userInput").value;
    var content = document.querySelector("#messageInput").value;
    var recipientId = document.querySelector("#recipient").value;
    var image = document.querySelector("#userImage1").src;
    connection.invoke("Send", user, content, recipientId,image).catch(function (err) {
        return console.error(err.toString());

What I have tried:

I searched and tried many way but I couldn't.
Updated 18-May-20 10:23am
F-ES Sitecore 18-May-20 15:25pm
The hard part of making an online chat is managing the messages etc. If you have found a "group chat" then all you have to do is modify the code to restrict who can join the chat, especially if the code already covers multiple chats.
Member 14769019 18-May-20 15:51pm
I want to uplaod pics. Can I?
MadMyche 18-May-20 16:05pm
Not pics, but you can post the relevant that code you do have
Member 14769019 18-May-20 16:21pm
But I cant tell another way.
This is step1:

this is step 2:
Member 14769019 18-May-20 16:21pm
And ı will sahare my code.
ZurdoDev 18-May-20 16:30pm
Do what was first said. Just tweak it so that instead of group, it is private.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100