// . public void JoinRoom(string roomKey, string userName) { // if (roomKey == C.MAIN_CHAT_GROUP) Store.Add(new User(Context.ConnectionId, userName)); // id Clients[Context.ConnectionId].OnJoinRoom(Context.ConnectionId); // Groups.Add(Context.ConnectionId, roomKey); // UpdateUsers(); } // public void Send(ChatMessage message) { // - if (message.Content.Length > 0) { // message.Date = DateTime.Now; // message.SenderKey = Context.ConnectionId; // message.Content = HttpUtility.HtmlEncode(message.Content); message.SenderName = HttpUtility.HtmlEncode(message.SenderName); // Clients[message.RoomKey].OnSend(message); Store.SaveMessage(message); } }
var CHAT = {}; var OPTIONS = {}; function Start(data) { // , OPTIONS.SenderName = data.name; OPTIONS.RoomKey = 'MAIN'; CHAT = $.connection.chat; // , CHAT.OnSend = OnSend; CHAT.OnJoinRoom = OnJoinRoom; } // function OnJoinRoom(key) { OPTIONS.SenderKey = key; } // function OnUpdateUsers(data) { /* ... , data - User, IUser */ } // , Chat.Send function Send() { var messageInput = $("#msg"), // , ChatMessage msg = { 'SenderName': OPTIONS.MyName, 'RoomKey': OPTIONS.RoomKey, 'Content': messageInput.val() }; CHAT.send(msg); // : - messageInput.val(""); messageInput.focus(); } // , function OnSend(msg) { var chatContent = $(".chat_content"), msgClass = 'chat_message'; /* ... , msg - , ChatMessage */ }
// ( ) public void Call(string recieverKey, string senderKey, string senderName) { Clients[recieverKey].OnCall(senderKey, senderName); } // public void RejectCall(string senderKey, string recieverKey, string recieverName) { Clients[senderKey].OnRejectCall(recieverKey, recieverName); } // public void AcceptCall(string calleePulicKey, string calleeName, string myName) { string myKey = Guid.NewGuid().ToString().Replace("-", ""); string calleeKey = Guid.NewGuid().ToString().Replace("-", ""); string roomKey = Guid.NewGuid().ToString().Replace("-", ""); var model = new RoomModel { MyPublicKey = Context.ConnectionId, MyKey = myKey, MyName = myName, CalleePublicKey = calleePulicKey, CalleeKey = calleeKey, CalleeName = calleeName, RoomKey = roomKey }; // Store.SaveRoomInfo(model); // Clients[calleePulicKey].OnAcceptCall(false, roomKey); Clients[Context.ConnectionId].OnAcceptCall(true, roomKey); }
function OnAcceptCall(isMy, roomKey) { document.location = '@Url.Action("Room", "Home")' + '?isMy=' + isMy + '&roomKey=' + roomKey; }
private function Connect():void { if (!isConnected && rtmpConnection == null) { // rtmpConnection = new NetConnection(); rtmpConnection.connect(connectStr); // rtmpConnection.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus_rtmpConnection); } isConnected = true; } private function StartPublish():void { // nsPublish = new NetStream(rtmpConnection); nsPublish.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus_nsPublish); // 0 nsPublish.bufferTime = 0; // nsPublish.publish(publishName); // nsPublish.attachCamera(camera); nsPublish.attachAudio(microphone); isPublish = true; } private function StartSubscribe():void { // C nsSubscribe = new NetStream(rtmpConnection); // nsSubscribe.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus_nsSubscribe); // 0 nsSubscribe.bufferTime = 0; // var volume:Number = sldrVolume.value / 100; var st:SoundTransform = new SoundTransform(volume); nsSubscribe.soundTransform = st; // nsSubscribe.play(subscribeName); // videoRemote.attachNetStream(nsSubscribe); isSubscribe = true; }
private function onTick_Timer(event:TimerEvent):void { if(!isConnected)// { lblEndTime.text = "..."; Connect(); startTime = new Date(); } else { if(!isPublish && needPublish)// { lblEndTime.text = "..."; StartPublish(); } if(!isSubscribe)// { lblEndTime.text = "..."; StartSubscribe(); } if(isPublish && isSubscribe)// , { var now:Date = new Date(); var toStart:TimeSpan = new TimeSpan(now.getTime() - startTime.getTime()); lblEndTime.text = toStart.getTotalMinutes() + ':' + toStart.getSeconds(); } } }
Source: https://habr.com/ru/post/154455/
All Articles