Пример #1
0
 String _sendPlatformMessage(String name,
                             PlatformMessageResponseCallback callback,
                             ByteData data)
 {
     // native 'Window_sendPlatformMessage';
     return(string.Empty); // Tmp to resolve build
 }
Пример #2
0
        public Future handlePlatformMessage(
            string channel, byte[] data,
            PlatformMessageResponseCallback callback)
        {
            MessageHandler handler = _handlers[channel];

            if (handler == null)
            {
                ui_.channelBuffers.push(channel, data, callback);
                return(Future.value());
            }

            return(handler(data).then(bytes => {
                var response = (byte[])bytes;
                callback(response);
                return FutureOr.nil;
            }, onError: exception => {
                UIWidgetsError.reportError(new UIWidgetsErrorDetails(
                                               exception: exception,
                                               library: "services library",
                                               context: new ErrorDescription("during a platform message callback"))
                                           );
                callback(null);
                return FutureOr.nil;
            }));
        }
Пример #3
0
        /// Wraps the given [callback] in another callback that ensures that the
        /// original callback is called in the zone it was registered in.
        static PlatformMessageResponseCallback _zonedPlatformMessageResponseCallback(PlatformMessageResponseCallback callback)
        {
            if (callback == null)
            {
                return(null);
            }

            // Store the zone in which the callback is being registered.
            Zone registrationZone = Zone.current;

            return((data) => registrationZone.runUnaryGuarded(callback, data));
        }
Пример #4
0
        /// Sends a message to a platform-specific plugin.
        ///
        /// The `name` parameter determines which plugin receives the message. The
        /// `data` parameter contains the message payload and is typically UTF-8
        /// encoded JSON but can be arbitrary data. If the plugin replies to the
        /// message, `callback` will be called with the response.
        ///
        /// The framework invokes [callback] in the same zone in which this method
        /// was called.
        public void sendPlatformMessage(String name,
                                        ByteData data,
                                        PlatformMessageResponseCallback callback)
        {
            String error =
                _sendPlatformMessage(name, _zonedPlatformMessageResponseCallback(callback), data);

            if (error != null)
            {
                throw new Exception(error);
            }
        }
Пример #5
0
        public unsafe void sendPlatformMessage(string name,
                                               byte[] data, PlatformMessageResponseCallback callback)
        {
            fixed(byte *bytes = data)
            {
                var    callbackHandle = GCHandle.Alloc(callback);
                IntPtr errorPtr       = Window_sendPlatformMessage(name, _sendPlatformMessageCallback,
                                                                   (IntPtr)callbackHandle, bytes, data?.Length ?? 0);

                if (errorPtr != IntPtr.Zero)
                {
                    callbackHandle.Free();
                    throw new Exception(Marshal.PtrToStringAnsi(errorPtr));
                }
            }
        }
Пример #6
0
 public void runUnaryGuarded(PlatformMessageResponseCallback callback, ByteData data)
 {
     // TODO:
 }
Пример #7
0
 internal _StoredMessage(byte[] data, PlatformMessageResponseCallback callback)
 {
     _data     = data;
     _callback = callback;
 }