Red5 Websocket chat application support multiple chat rooms - websocket

Using Red5 and
https://github.com/Red5/red5-websocket-chat
I try to do a basic chat.
It works ok for a example channel
var socket = new WebSocket('ws://serverIP:80/chat', 'chat');
Is there any way to do something similar to chat rooms using Red5 Websocket chat?
An example I want to do from JavaScript is using URL:
var socketRoom1 = new WebSocket('ws://serverIP:80/chat/Room1', 'chat');
var socketRoom2 = new WebSocket('ws://serverIP:80/chat/Room2', 'chat');
...
var socketRoomN = new WebSocket('ws://serverIP:80/chat/RoomN', 'chat');
or using Protocol:
var socketRoom1 = new WebSocket('ws://serverIP:80/chat', 'Room1');
var socketRoom2 = new WebSocket('ws://serverIP:80/chat', 'Room2');
...
var socketRoomN = new WebSocket('ws://serverIP:80/chat', 'RoomN');
But I only can make it works in JavaScript with that:
var socket = new WebSocket('ws://serverIP:80/chat', 'chat');
Thanks for your time.

You are able to do this by integrating with the Red5 scopes and creating the new scopes as needed. Scopes are basically interchangeable with "rooms" or contexts. This endeavor will require that you learn at least at a basic level how the scopes work. You'll also need to modify / extend the listener to add/remove the scopes as needed and to route your messages.
https://github.com/Red5/red5-websocket-chat/blob/master/src/main/java/org/red5/demos/chat/WebSocketChatDataListener.java
Here's some additional reading regarding scopes / rooms:
http://ria101.wordpress.com/2010/03/09/red5-cabin-fever-advanced-scope-and-room-management/
http://gregoire.org/2009/04/07/on-demand-room-scope-creation/

Related

Having issue in conversation of UCMA with MS Bot Framework

I am working on MS Bot Framework Integration with UCMA(Skype For Business OnPremise aka SFB onPrimise) SDK.
I am using directline channel for connection and the Connection is successfully established between two, but when a dialog prompt with Yes, No options is returned From BOT to SFB, and when I send my answer as yes then BOT do not recognize it as my answer. It creates new conversation Id for every single statement. How to overcome this issue?
Below is my code from UCMA
static DirectLineClient client = null;
client = new Microsoft.Bot.Connector.DirectLine.DirectLineClient("DirectLineSecretKey");
botConversation = client.Conversations.NewConversation();
string message = e.TextBody;
Microsoft.Bot.Connector.DirectLine.Models.Message msg = new Microsoft.Bot.Connector.DirectLine.Models.Message
{
FromProperty = "AMOL",
Text = message
};
await client.Conversations.PostMessageAsync(botConversation.ConversationId, msg);
var messages = await client.Conversations.GetMessagesAsync(botConversation.ConversationId, watermark);
InstantMessagingFlow instantMessagingFlow = (InstantMessagingFlow)sender;
watermark = messages.Watermark;
foreach (var m in messages.Messages)
{
if (m.FromProperty != "AMOL")
instantMessagingFlow.BeginSendInstantMessage(m.Text, MyMethod, instantMessagingFlow);
}
I am doing the same and it works for me. The problem in your code is, you create conversation id for each and every request and bot is considering the request as new fresh new request.
Let me know if you need any help on this.

Can't send custom Slack Message with version 3 of Bot Connector

I have a bot that replies with a message consisting only of attachments. When it works on Slack, it uses Slack attachment formatting quite heavily, thus I have to use ChannelData property.
In version 1 of BotConnector, the code was like this
var reply = message.CreateReplyMessage();
reply.Attachments = new List<Attachment>();
var attachments = new List<object>(); //Slack-formatted attachments
//filling attachments...
reply.ChannelData = new {attachments};
and it worked. Now, in version 3 code has changed to
var reply = activity.CreateReply();
reply.Attachments = new List<Attachment>();
var attachments = new List<object>(); //Slack-formatted attachments
//filling attachments...
reply.ChannelData = new {attachments};
var connector = new ConnectorClient(new Uri(activity.ServiceUrl));
await connector.Conversations.ReplyToActivityAsync(reply);
which, basically, boils down to using different method to create reply, and another one to send the reply back.
Now, the problem is, that I don't get the reply back to Slack. Diagnostics in AppInsight show me that somewhere in Connector something like this happens:
Exception type: System.ArgumentNullException
Failed method: SlackChannel.SlackMapper+d__5.MoveNext
Exception Message: value cannot be null. Parameter name: source
ChannelData: {}
message: Invalid ChannelData
Please note that ChannelData in this diagnostics seems to be empty. So what I gather from all this is that something has changed in the way BotConnector processes ChannelData. How can I find out what exactly am I doing wrong?
Actually the problem is inside the ConnectorClient client, which strips channelData. The reason for that lies in its serialization settings which use ReadOnlyJsonContractResolver, which skips all read-only properties - and of course all the properties in anonymous class are read-only.
Knowing that, the solution is quite simple:
reply.ChannelData = JObject.FromObject(new {attachments});
Note the explicit use of JObject instead of anonymous class.

Creating two separate websocket connections for send and receive on localhost

I am new to websockets.
It is expected to send data(any data) on the send websocket connection using some port(ex:8000) and the localhost should echo the same data to the browser using a different websocket connection through a different port(ex:9000).
I understand websocket supports full duplex communication on a single connection,but the above is the design to implement.
Question 1) Is the above design possible?
Question 2) If yes,how to create two websocket connections(one to send and one to receive) to a single localhost websocket server?
1) Yes.
2) Creating two separated websockets. They will be different objects though.
You could blend both objects in a composite object like this:
var compositeWebSocket = function(urlSend, urlReceive){
var me = {};
var wsSend = new WebSocket(urlSend);
var wsReceive = new WebSocket(urlReceive);
var open = 0;
wsSend.onopen = opening;
wsReceive.onopen = opening;
var opening = function(){
if(open == 2){
if(me.onopen)
me.onopen();
}
else
open++;
};
var closing = funcion(){
try{wsSend.close();}catch(){}
try{wsReceive.close();}catch(){}
if(me.onclose)
me.onclose();
}
me.send = wsSend.send;
wsReceive.onmessage = function(msg){
if(me.onmessage)
me.onmessage(msg);
}
return me;
}
(Whatch out, this code is not tested and it is just an idea)

Best practice for sending unrelated data from server to client over WebSocket connection(s)

I am currently working on a single page web app that has a growing number of real-time widgets concurrently requiring different datasources. My question is which approach is best for using WebSockets as the vehicle for this data:
Option 1: The client opens a single socket connection with the server, then uses an API similar to the following to subscribe/unsubscribe/get/post data:
var socket = new WebSocket([URL]);
socket.emit("subscribe", [OPTIONS]);
socket.emit("unsubscribe", [OPTIONS]);
socket.emit("get", [OPTIONS]);
socket.emit("post", [OPTIONS])
Option 2: The client opens a socket for every source of data it needs to run the widgets on the page. Keep in mind that there could be many widgets requiring many different sources of data. For example, it would look something like this:
var sock1 = new WebSocket([URL]);
var widget1 = new Widget1(sock1);
var sock2 = new WebSocket([URL]);
var widget2 = new Widget2(sock2);
var sock3 = new WebSocket([URL]);
var widget3 = new Widget3(sock3);
Any insight would be much appreciated.
Andy

What is the purpose of a resource in a WebSocket URL?

Looking at the W3 spec on WebSockets, I see
var socket = new WebSocket('ws://game.example.com:12010/updates');
socket.onopen = function () {
setInterval(function() {
if (socket.bufferedAmount == 0)
socket.send(getUpdateData());
}, 50);
};
I understand that the socket services lives on port 12010 at game.example.com, but what is the purpose of the '/updates' resource in the URL? If the service lives at some port, what good will a resource do?
You can expose different logical WebSockets on the same port, using different URI's.
Lets take chat as an example. You could use the URI to determine the particular channel or chat room you want to join.
var socket = new WebSocket('ws://chat.example.com/games');
var socket = new WebSocket('ws://chat.example.com/movies');
var socket = new WebSocket('ws://chat.example.com/websockets');
You can also use query strings. Imagine a stock ticker:
var socket = new WebSocket('ws://www.example.com/ticker?code=MSFT');
var socket = new WebSocket('ws://www.example.com/ticker?code=GOOG');

Resources