#if UNITY_WEBGL using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net; namespace ET { public class WService : AService { private long idGenerater = 200000000; private readonly Dictionary channels = new Dictionary(); public override void Dispose() { if (this.IsDisposed()) { return; } this.Id = 0; foreach (var kv in this.channels.ToArray()) { kv.Value.Dispose(); } } public WService(IEnumerable prefixs) { this.ServiceType = ServiceType.Outer; } public WService() { this.ServiceType = ServiceType.Outer; } private long GetId { get { return ++this.idGenerater; } } public override void Create(long id, IPEndPoint ipEndPoint, string address) { if (!this.channels.TryGetValue(id, out _)) { WChannel channel = new WChannel(id, ipEndPoint, this, address); this.channels[channel.Id] = channel; } } public override void Remove(long id, int error = 0) { WChannel channel; if (!this.channels.TryGetValue(id, out channel)) { return; } channel.Error = error; this.channels.Remove(id); channel.Dispose(); } protected void Get(long id, IPEndPoint ipEndPoint) { // if (!this.channels.TryGetValue(id, out _)) // { // this.Create(id, ipEndPoint); // } } public WChannel Get(long id) { WChannel channel = null; this.channels.TryGetValue(id, out channel); return channel; } public override void Send(long channelId, long actorId, MemoryStream stream) { this.channels.TryGetValue(channelId, out WChannel channel); if (channel == null) { return; } channel.Send(stream); } public override void Update() { } public override bool IsDisposed() { return this.Id == 0; } } } #endif