// // Copyright (C) 2014 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // namespace GooglePlayGames.BasicApi.Nearby { using System; using System.Collections.Generic; // move this inside IMessageListener and IDiscoveryListener are always declared. #if UNITY_ANDROID /// /// Interface for managing connections and communications between devices using Nearby Connections. /// public interface INearbyConnectionClient { /// /// Gets the maximum length of an unreliable message payload. /// /// Maximum length of an unreliable message payload. int MaxUnreliableMessagePayloadLength(); /// /// Gets the maximum length of a reliable message payload. /// /// Maximum length of a reliable message payload. int MaxReliableMessagePayloadLength(); /// /// Sends a reliable message to a list of recipients. /// /// List of recipient endpoint IDs. /// The message payload to send. void SendReliable(List recipientEndpointIds, byte[] payload); /// /// Sends an unreliable message to a list of recipients. /// /// List of recipient endpoint IDs. /// The message payload to send. void SendUnreliable(List recipientEndpointIds, byte[] payload); /// /// Starts advertising the local device to nearby devices. /// /// The name to advertise. /// List of application identifiers. /// Optional advertising duration. /// Callback for advertising result. /// Callback for incoming connection requests. void StartAdvertising(string name, List appIdentifiers, TimeSpan? advertisingDuration, Action resultCallback, Action connectionRequestCallback); /// /// Stops advertising the local device to nearby devices. /// void StopAdvertising(); /// /// Sends a connection request to a remote endpoint. /// /// The name of the local device. /// The ID of the remote endpoint. /// The connection request payload. /// Callback for the connection response. /// Listener for message events. void SendConnectionRequest(string name, string remoteEndpointId, byte[] payload, Action responseCallback, IMessageListener listener); /// /// Accepts a connection request from a remote endpoint. /// /// The ID of the remote endpoint. /// The connection acceptance payload. /// Listener for message events. void AcceptConnectionRequest(string remoteEndpointId, byte[] payload, IMessageListener listener); /// /// Starts discovering nearby endpoints for a specific service. /// /// The service ID to discover. /// Optional timeout for advertising discovery. /// Listener for discovery events. void StartDiscovery(string serviceId, TimeSpan? advertisingTimeout, IDiscoveryListener listener); /// /// Stops discovering endpoints for a specific service. /// /// The service ID to stop discovering. void StopDiscovery(string serviceId); /// /// Rejects a connection request from a remote endpoint. /// /// The ID of the endpoint that sent the request. void RejectConnectionRequest(string requestingEndpointId); /// /// Disconnects from a remote endpoint. /// /// The ID of the remote endpoint to disconnect from. void DisconnectFromEndpoint(string remoteEndpointId); /// /// Stops all connections to nearby endpoints. /// void StopAllConnections(); /// /// Gets the app bundle ID. /// /// The app bundle ID. string GetAppBundleId(); /// /// Gets the service ID used for discovery and connection. /// /// The service ID. string GetServiceId(); } #endif /// /// Interface for receiving messages and notifications about remote endpoints. /// public interface IMessageListener { /// /// Called when a message is received from a remote endpoint. /// /// The ID of the remote endpoint. /// The data of the received message. /// Indicates whether the message is reliable. void OnMessageReceived(string remoteEndpointId, byte[] data, bool isReliableMessage); /// /// Called when a remote endpoint has disconnected. /// /// The ID of the disconnected endpoint. void OnRemoteEndpointDisconnected(string remoteEndpointId); } /// /// Interface for receiving notifications about discovered endpoints. /// public interface IDiscoveryListener { /// /// Called when an endpoint is found during discovery. /// /// The details of the discovered endpoint. void OnEndpointFound(EndpointDetails discoveredEndpoint); /// /// Called when an endpoint is lost during discovery. /// /// The ID of the lost endpoint. void OnEndpointLost(string lostEndpointId); } }