private static NativeMessageListenerHelper ToMessageListener(IMessageListener listener) { listener = (IMessageListener) new NativeNearbyConnectionsClient.OnGameThreadMessageListener(listener); NativeMessageListenerHelper messageListenerHelper = new NativeMessageListenerHelper(); messageListenerHelper.SetOnMessageReceivedCallback((NativeMessageListenerHelper.OnMessageReceived)((localClientId, endpointId, data, isReliable) => listener.OnMessageReceived(endpointId, data, isReliable))); messageListenerHelper.SetOnDisconnectedCallback((Action <long, string>)((localClientId, endpointId) => listener.OnRemoteEndpointDisconnected(endpointId))); return(messageListenerHelper); }
public void SendConnectionRequest(string name, string remoteEndpointId, byte[] payload, Action <ConnectionResponse> responseCallback, IMessageListener listener) { Misc.CheckNotNull <string>(remoteEndpointId, nameof(remoteEndpointId)); Misc.CheckNotNull <byte[]>(payload, nameof(payload)); Misc.CheckNotNull <Action <ConnectionResponse> >(responseCallback, nameof(responseCallback)); Misc.CheckNotNull <IMessageListener>(listener, nameof(listener)); responseCallback = Callbacks.AsOnGameThreadCallback <ConnectionResponse>(responseCallback); using (NativeMessageListenerHelper messageListener = NativeNearbyConnectionsClient.ToMessageListener(listener)) this.mManager.SendConnectionRequest(name, remoteEndpointId, payload, (Action <long, NativeConnectionResponse>)((localClientId, response) => responseCallback(response.AsResponse(localClientId))), messageListener); }
private static NativeMessageListenerHelper ToMessageListener(IMessageListener listener) { listener = new OnGameThreadMessageListener(listener); var helper = new NativeMessageListenerHelper(); helper.SetOnMessageReceivedCallback( (localClientId, endpointId, data, isReliable) => listener.OnMessageReceived( endpointId, data, isReliable)); helper.SetOnDisconnectedCallback((localClientId, endpointId) => listener.OnRemoteEndpointDisconnected(endpointId)); return(helper); }
private static NativeMessageListenerHelper ToMessageListener(IMessageListener listener) { listener = new OnGameThreadMessageListener(listener); NativeMessageListenerHelper nativeMessageListenerHelper = new NativeMessageListenerHelper(); nativeMessageListenerHelper.SetOnMessageReceivedCallback(delegate(long localClientId, string endpointId, byte[] data, bool isReliable) { listener.OnMessageReceived(endpointId, data, isReliable); }); nativeMessageListenerHelper.SetOnDisconnectedCallback(delegate(long localClientId, string endpointId) { listener.OnRemoteEndpointDisconnected(endpointId); }); return(nativeMessageListenerHelper); }
public void SendConnectionRequest(string name, string remoteEndpointId, byte[] payload, Action <ConnectionResponse> responseCallback, IMessageListener listener) { Misc.CheckNotNull(remoteEndpointId, "remoteEndpointId"); Misc.CheckNotNull(payload, "payload"); Misc.CheckNotNull(responseCallback, "responseCallback"); Misc.CheckNotNull(listener, "listener"); responseCallback = Callbacks.AsOnGameThreadCallback(responseCallback); using (NativeMessageListenerHelper listener2 = ToMessageListener(listener)) { mManager.SendConnectionRequest(name, remoteEndpointId, payload, delegate(long localClientId, NativeConnectionResponse response) { responseCallback(response.AsResponse(localClientId)); }, listener2); } }