Phoenix:一次只允许在频道上订阅一个子主题

时间:2015-12-30 19:26:53

标签: websocket elixir phoenix-framework

如果用户已加入主题,请说出for i in revisions[0:10]: print(i) #<rev revid="698019402" parentid="698018324" user="Termininja" timestamp="2016-01-03T13:51:27Z" comment="short link" /> #<rev revid="698018324" parentid="697691358" user="AXRL" timestamp="2016-01-03T13:39:14Z" comment="/* See also */" /> #<rev revid="697691358" parentid="697690475" user="Zekenyan" timestamp="2016-01-01T05:31:33Z" comment="first coffee trade" /> #<rev revid="697690475" parentid="697272803" user="Zekenyan" timestamp="2016-01-01T05:18:11Z" comment="since country of origin is not first sighting of someone drinking coffee I have removed the origin section completely" /> #<rev revid="697272803" parentid="697272470" minor="" user="Materialscientist" timestamp="2015-12-29T11:13:18Z" comment="Reverted edits by [[Special:Contribs/Media3dd|Media3dd]] ([[User talk:Media3dd|talk]]) to last version by Materialscientist" /> #<rev revid="697272470" parentid="697270507" user="Media3dd" timestamp="2015-12-29T11:09:14Z" comment="/* External links */" /> #<rev revid="697270507" parentid="697270388" minor="" user="Materialscientist" timestamp="2015-12-29T10:45:46Z" comment="Reverted edits by [[Special:Contribs/89.197.43.130|89.197.43.130]] ([[User talk:89.197.43.130|talk]]) to last version by Mahdijiba" /> #<rev revid="697270388" parentid="697265765" user="89.197.43.130" anon="" timestamp="2015-12-29T10:44:02Z" comment="/* See also */" /> #<rev revid="697265765" parentid="697175433" user="Mahdijiba" timestamp="2015-12-29T09:45:03Z" comment="" /> #<rev revid="697175433" parentid="697167005" user="EvergreenFir" timestamp="2015-12-28T19:51:25Z" comment="Reverted 1 pending edit by [[Special:Contributions/2.24.63.78|2.24.63.78]] to revision 696892548 by Zefr: [[WP:CENTURY]]" /> ,然后用户在同一频道上加入另一个子主题,例如public class Company { public Company () { Id = null; TipoCompanyString = ((int)Enums.EnumType.TipoCompany.Matriz).ToString(); TipoCompany = Enums.EnumType.TipoCompany.Matriz; Name = string.Empty; } public int? Id { get; set; } public string Name { get; set; } public string TipoCompanyString { get; set; } public Enums.EnumType.TipoCompany TipoCompany { get { var intValue = Convert.ToInt32(TipoCompanyString); return (Enums.EnumType.TipoCompany)intValue; } set { TipoCompanyString = ((int)value).ToString() } } } public class CompanyMap : EntityTypeConfiguration<Company> { public CompanyMap() { ToTable("COMPANY"); HasKey(t => new { t.Id}); Property(t => t.Id).HasDatabaseGeneratedOption(DatabaseGeneratedOption.None).HasColumnName("EMP_ID"); Property(t => t.Name) .IsRequired() .HasMaxLength(35) .HasColumnType("Varchar") .HasColumnName("EMP_NM"); Property(t => t.TipoCompanyString) .IsRequired() .HasColumnType("Varchar") .HasColumnName("EMP_TYPE"); } } public class EnumTypeCompany { public enum TypeCompany { [Description("Matriz")] Matriz = 01, [Description("Filial")] Filial = 02, } } 。如何强制用户从后端离开“rooms:lobby”。我试过过滤广播,但没有运气。我宁愿通过过滤广播来终止与旧子主题的连接。

"rooms:lobby"

我知道可以从前端留下一个主题,但我需要确保只有他们正在查看的当前主题才能获得有效负载,而不是在特定频道上订阅的任何先前主题。< / p>

1 个答案:

答案 0 :(得分:1)

根据您的评论,您似乎想要为每条路线加入1个频道,并且您希望在路线更改时切换频道而不是累积多个频道。我猜你是从高级React组件加入生命周期方法(例如ComponentWillMount)中的通道。

如果是这样,为什么不在ComponentWillUnmount中终止客户端的频道?这应该在您的路由更改客户端之前触发。