public void NKaddScriptMessageHandler(NKScriptMessageHandler scriptMessageHandler, string name) { msgHandlers.Add(name, scriptMessageHandler); var script = "NKScripting.messageHandlers['" + name + "'] = NKScripting.getMessageHandlers('" + name + "');"; context.NKevaluateJavaScript(script, ""); }
// MAIN PROCESS PIPE EVENT LOOP private async Task _processServerMessages(Stream stream) { var message = await readObjectAsync(stream); if (message == null) { return; } if (message.command == NKRemotingMessage.Command.NKevaluateJavaScript) { var _ = context.NKevaluateJavaScript(message.args[0], message.args[1]); } else if (message.command == NKRemotingMessage.Command.NKEvent) { var eventType = message.args[0]; NKEvent eventObject = new NKEvent((IDictionary <string, object>)(NKData.jsonDeserialize(message.args[1]))); NKEventEmitter.global.emit <NKEvent>(eventType, eventObject, false); } if (!cancelToken.IsCancellationRequested) { await _processServerMessages(stream); } else { return; } }
// Private JavaScript scripts and helpers async private Task<object> evaluateExpression(string expression, bool retain = true) { if (retain) { var result = await _context.NKevaluateJavaScript(expression); if (result != null) { var wrapped = wrapScriptObject(result); return wrapped; } return null; } else { return _context.NKevaluateJavaScript(expression); } }
private void Button_Click(object sender, RoutedEventArgs e) { host.NKevaluateJavaScript(JsInput.Text).ContinueWith(task => { JsOutput.Text = JsOutput.Text + "\n> " + JsInput.Text + "\n" + task.Result; JsOutput.UpdateLayout(); JsOutputScroll.ChangeView(null, double.MaxValue, null); }, TaskScheduler.FromCurrentSynchronizationContext()); }
public void eject() { if (!injected) { return; } if (_context == null) { return; } _context.NKevaluateJavaScript(cleanup); }