using Grpc.Core; using Grpc.Core.Logging; using MessagePack; using System; namespace MagicOnion.Client { public static class StreamingHubClient { public static TStreamingHub Connect(Channel channel, TReceiver receiver, string host = null, CallOptions option = default(CallOptions), MessagePackSerializerOptions serializerOptions = null, ILogger logger = null) where TStreamingHub : IStreamingHub { return Connect(new DefaultCallInvoker(channel), receiver, host, option, serializerOptions, logger); } public static TStreamingHub Connect(CallInvoker callInvoker, TReceiver receiver, string host = null, CallOptions option = default(CallOptions), MessagePackSerializerOptions serializerOptions = null, ILogger logger = null) where TStreamingHub : IStreamingHub { var ctor = StreamingHubClientRegistry.consturtor; StreamingHubClientBase client = null; if (ctor == null) { #if ((ENABLE_IL2CPP && !UNITY_EDITOR) || NET_STANDARD_2_0) throw new InvalidOperationException("Does not registered client factory, dynamic code generation is not supported on IL2CPP. Please use code generator(moc)."); #else var type = StreamingHubClientBuilder.ClientType; client = (StreamingHubClientBase)Activator.CreateInstance(type, new object[] { callInvoker, host, option, serializerOptions, logger }); #endif } else { client = (StreamingHubClientBase)(object)ctor(callInvoker, receiver, host, option, serializerOptions, logger); } client.__ConnectAndSubscribe(receiver); return (TStreamingHub)(object)client; } } public static class StreamingHubClientRegistry where TStreamingHub : IStreamingHub { public static Func consturtor; public static void Register(Func ctor) { consturtor = ctor; } } }