SocketsSample Send to Connection (#1285)

This commit is contained in:
Mikael Mengistu 2018-01-11 11:34:02 -08:00 committed by GitHub
parent a9d643a93e
commit e3679cb3c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -30,6 +30,11 @@ namespace SocketsSample.Hubs
return Clients.Others.InvokeAsync("Send", $"{Context.ConnectionId}: {message}");
}
public Task SendToConnection(string connectionId, string message)
{
return Clients.Client(connectionId).InvokeAsync("Send", $"Private message from {Context.ConnectionId}: {message}");
}
public Task SendToGroup(string groupName, string message)
{
return Clients.Group(groupName).InvokeAsync("Send", $"{Context.ConnectionId}@{groupName}: {message}");

View File

@ -25,8 +25,15 @@
<input type="text" id="message-text" placeholder="Type a message, name or group" />
<input type="button" id="broadcast" class="btn" value="Broadcast" />
<input type="button" id="broadcast-exceptme" class="btn" value="Broadcast (Others)" />
<input type="button" id="join" class="btn" value="Enter Name" />
</div>
</form>
<h4>To Connection</h4>
<form class="form-inline">
<div class="input-prepend input-append">
<input type="text" name="connection-message" id="connection-message-text" placeholder="Type a message" />
<input type="text" name="connection-id" id="connection-id" placeholder="Type a connection id" />
<input type="button" id="connection-send" class="btn" value="Send to Connection" />
</div>
</form>
@ -178,4 +185,10 @@
invoke(connection, 'SendToOthers', data);
});
click('connection-send', function (event) {
let data = getText('connection-message-text');
let id = getText('connection-id');
invoke(connection, 'SendToConnection', id, data);
});
</script>