2017-01-06 2 views
0

以下私はGroupChatに使用される3つのテーブルを持っています。グループを作成しています。GroupTableにすべてのデータを挿入してから、groupCreationの成功時に呼び出します。insertConnectionId function MapGroupConnectionIdのバックエンドでSignalR接続IDを生成し、groupIdとgroupCreaterIdを使用してGroupTableに挿入します。そのうまくいけば、友だちIDからなるグループ友達テーブルがあります。その特定のグループに属しているすべての人にSignalRを通してメッセージを送ってください。私はグループテーブルのgroupConnectionIDを、そのグループに関連するすべてのメンバーに割り当てます。そして、その特定のグループにメッセージを送信して、 oupFriends、Hub.Client.ALLのためにのみ動作しますが、私は間違った方法でそれをやっている場合は、他の機能のために、私を導いてくださいいない私のハブは、私がsignalRグループチャット信号RとWeb API

//Group Table 

groupID groupName groupImage groupCreaterId groupConnectionId groupsignalrIsConnected 
    1   dude  someurl  421  somestringID  TRUE 
    2   god  someurl  444  somestringID  TRUE 
    3   heaven  someurl  543  Null    FALSE 
    4   hell  someurl  678  Null    FALSE 


//Group Friends Table 

groupFriendsTabID groupId groupFriendsId 
     111    2 444 
     112    3 678 
     113    2 421 
     114    4 444 
     115    1 543 
     116    4 421 
     117    1 678 
     118    2 543 
     119    3 444 


    //Group Message Table 

    groupMesTabId groupId groupsenderId groupMessage 
     22    1 543    hello 
     23    3 678    hi 


//My HUB 
[HubName("groupChatHub")] 
public class GroupChatHub : Hub 
{ 
    GroupRepository group= new GroupRepository(); 


    public void **MapGroupConnectionId**(long groupID,int groupCreatorId) 
     { 
     if (groupID != 0 && groupCreatorId!=0) 
      { 
      CBG.MapGroupConnectionId(groupID, Context.ConnectionId); 
       Clients.Client(Context.ConnectionId).configureUserSettings();} 
      } 

    public override Task OnConnected() 
    { 
     var connectionId = Context.ConnectionId; 
     return base.OnConnected(); 
    } 
    public override Task OnDisconnected(bool stopCalled) 
    { 
     var connectionId = Context.ConnectionId; 
     return base.OnDisconnected(stopCalled); 
    } 
    public override Task OnReconnected() 
    { 
     return base.OnReconnected(); 
    } 
} 

    //My WEBAPI// 
    public class GroupController : ApiControllerWithHub<GroupchatHub> 
    { 
     public IhttpActionResult InsertNewMessage(messageModel model) 
     { 
       //Here i am inserting new message to Database using some function it works fine// 

      after success of inserting message i need to send that message to groupmembers using signalr 

    //here i am fetching the connectionID through groupID from group table 
     var connectionID=repository.getConnection(model.groupID) 

      var messager = "11"; 
    Hub.Clients.All.getGroupChat(messager); // this works 

    Hub.Clients.clients(connectionID).getGroupChat(messager);this not working it except IList<string> 

    Hub.Clients.Groups(groupName,ConnectionID).getGroupChat(messager); this is not working 
     } 
    return ok(Model); 
    } 



//MyClientEnd// 

    var Grouphub 

//this insertConnectionId is called once the group is created on the success of group creation and SignalRconnectionstring is inserted in GroupTable 

function insertConnectionId(groupId,groupCreatorID) 
$.connection.hub.start().done(function() { 
    console.log('Now connected, connection ID=' + $.connection.hub.id); 
    console.log("Connected, transport = " +  $.connection.hub.transport.name); 
    Grouphub.server.mapGroupConnectionId(groupID, groupCreatorID); 
}); 
$.connection.hub.error(function (error) { 
    console.log('SignalR error: ' + error) 
}); 

}); 

Grouphub = $.connection.groupChatHub 
Grouphub.client.getGroupChat = function (data) { 
    alert("in"); 

} 

答えて

0

に新しいです私のような同様のプロジェクトを行っていますそして、さまざまな分野でそれを使用

は、それはあなたが、それは私が使用している方法で、私はちょうど知りたいと思った、私を助け、プロジェクトの

https://github.com/DenizGokce/SignalR

+0

@thanks :)を助けるこの例をチェックしてくださいユーザーがシグナル接続文字列をバインドして、データベースに格納する上記のコード、それを達成するための良い方法、またはより良い方法があれば私に教えてください – Nikil

関連する問題