所以我有一个 Swift 客户端、Node.js 服务器,并且正在使用 socket.io。我遇到一个问题,当用户在连接到服务器时从 WiFi 更改为 LTE(被动地,如果他们手动关闭 wifi,则可以正常工作)时,由于某种原因,他们不会重新连接到服务器(只是遇到 ping 超时) )。我尝试将 ping 超时增加到 50 秒,但没有效果。我的用户在连接到同一个房间时相互交互,所以这是一个大问题。
我在客户端的连接代码如下所示:
var socket: SocketIOClient?
fileprivate var manager: SocketManager?
func establishConnection(_ completion: (() -> Void)? = nil) {
let socketUrlString: String = serverURL
self.manager = SocketManager(socketURL: URL(string: socketUrlString)!, config: [.forceWebsockets(true), .log(false), .reconnects(true), .extraHeaders(["id": myDatabaseID])])
self.socket = manager?.defaultSocket
self.socket?.connect()
//self.socket?.on events go here
}
Run Code Online (Sandbox Code Playgroud)
在客户端,我的连接代码如下所示:
const io = require('socket.io')(http, {
pingTimeout: 10000
});
io.on('connection', onConnection);
function onConnection(socket){
let headerDatabaseID = socket.handshake.headers.id
//in the for loop below, …
Run Code Online (Sandbox Code Playgroud) 我尝试从该站点获取代理:https : //hidemy.name/en/proxy-list/?type=4#list
这是我的 Puppeteer 抓取代码(部署到 Heroku),它返回 .goto() 行标题中的错误:
const preparePageForTests = async (page) => {
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36';
await page.setUserAgent(userAgent);
await page.evaluateOnNewDocument(() => {
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
});
// Pass the Chrome Test.
await page.evaluateOnNewDocument(() => {
// We can mock this in as much depth as we need for the test.
window.navigator.chrome = {
app: {
isInstalled: false,
},
webstore: {
onInstallStageChanged: …
Run Code Online (Sandbox Code Playgroud) 所以我继续使用 Bright Data,注册了一个帐户,并获得了我的 Search Engine Crawler 代理。下面是我的抓取功能:
async function scrape() {
try {
const preparePageForTests = async (page) => {
const userAgent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36';//'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36';
await page.setUserAgent(userAgent);
await page.evaluateOnNewDocument(() => {
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
});
// Pass the Chrome Test.
await page.evaluateOnNewDocument(() => {
// We can mock this in as much depth as we need for the …
Run Code Online (Sandbox Code Playgroud) 所以我试图在下图中的封闭区域中刮取所有音乐会:
https://i.stack.imgur.com/7QIMM.jpg
问题是列表只显示前 10 个选项,直到您在该特定 div 中向下滚动到底部,然后它会动态显示更多选项,直到没有更多结果。我尝试按照下面的答案链接,但无法向下滚动以显示所有“音乐会”:
这是我的基本代码:
const browser = await puppeteerExtra.launch({ args: [
'--no-sandbox'
]});
async function functionName() {
const page = await browser.newPage();
await preparePageForTests(page);
page.once('load', () => console.log('Page loaded!'));
await page.goto(`https://www.google.com/search?q=concerts+near+poughkeepsie&client=safari&rls=en&uact=5&ibp=htl;events&rciv=evn&sa=X&fpstate=tldetail`);
const resultList = await page.waitForSelector(".odIJnf");
const scrollableSection = await page.waitForSelector("#Q5Vznb"); //I think this is the div that contains all the concert items.
const results = await page.$$(".odIJnf"); //this needs to be iterable to be used in the for loop
//this …
Run Code Online (Sandbox Code Playgroud) 我正在使用 socket.io 与我的应用程序的 swift 客户端与服务器进行通信。本质上,客户端在打开应用程序时加入套接字连接,并且作业会立即添加到 Redis 队列中(该作业需要几秒到 15 秒左右的时间)。服务器有一个作业 ID 到客户端的响应。处理此作业时,有时客户端会断开连接。这背后似乎没有任何规律或原因,因为断开连接的时间完全不一致,而且断开连接也不像是在函数中的特定点发生的。我想也许我是手动与客户端断开连接,所以我在客户端每次断开连接之前设置套接字发射(当这些发射被发射到服务器时,服务器会打印一些内容,告诉我断开连接来自哪里)。这表明断开连接是自动的,因为在结束套接字连接之前客户端永远不会收到发射。这是在 Heroku 上运行的。这是我的代码:
//queue initialization
const queue = new Queue('queue', process.env.REDIS_URL)
//client pings this endpoint to get the job id in the queue
app.post('/process', async function(request, response) {
let job = await queue({request: request.body});
console.log("Logging job as " + job.id)
response.json({ id: job.id });
});
queue.process(10, async (job) => { //10 is the max workers per job
console.log("Started processing")
const client = await pool.connect()
let item = job.data.request
let title …
Run Code Online (Sandbox Code Playgroud) 由于某种原因,此设置不起作用。我想做的就是不在主线程上运行作业的处理,因为它阻塞了我的事件循环。Procfile 看起来像:
web: node app.js
worker: node worker.js
Run Code Online (Sandbox Code Playgroud)
包.json:
{
"name": "server-testing",
"version": "1.0.0",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "npm start"
},
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"bull": "^3.22.6",
"express": "^4.17.1",
"throng": "^5.0.0"
},
"engines": {
"node": "14.17.6"
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序.js:
const express = require('express');
const app = express();
const http = require('http').Server(app);
const Queue = require('bull');
const workQueue = new Queue('work', process.env.REDIS_URL)
app.post('/addJob', async function(request, response) { …
Run Code Online (Sandbox Code Playgroud) 下面看起来很多,但主要只是输出。
我正在尝试使用 multer (通过 iPhone 上的 Alamofire 发送包含视频(.mov 格式)的请求)作为输入的缓冲区,然后我希望它作为缓冲区输出,然后将结果发送到S3。我想我已经很接近了,但我不认为 Fluent-ffmpeg 可以传入缓冲区。这是使用此构建包部署在 Heroku 上的: https: //github.com/jonathanong/heroku-buildpack-ffmpeg-latest。 …… 我如何正确地传递它?
const multer = require('multer')
const upload = multer({ limits: { fieldSize: 100_000_000 } })
app.post('/create', upload.single('video'), async function (request, response, next) {
let data = request.body
console.log(data) // prints [Object: null prototype] { param1: '' }
let bufferStream = new stream.PassThrough();
console.log(request.file.buffer) // prints '<Buffer 00 00 00 14 66 74 79 70 71 74 20 20 00 00 00 00 71 …
Run Code Online (Sandbox Code Playgroud) 我在堆栈中有一些带有动画偏移的按钮。由于某种原因,动画偏移按钮无法单击。当偏移量约为 250 左右时,按钮似乎可以单击一秒钟,然后在偏移量低于该值时再次变得不可单击...非常感谢任何帮助!
struct ContentView: View {
@State var offset: CGFloat = -300
var body: some View {
HStack {
Button(action: {
print("clickable")
}, label: {
Text("Click me")
})
Button(action: {
print("clickable2")
}, label: {
Text("Click me2")
})
Button(action: {
print("clickable3")
}, label: {
Text("Click me3")
})
}.offset(x: offset)
.onAppear(perform: {
withAnimation(.linear(duration: 10).repeatForever()) {
offset = 300
}
})
}
}
Run Code Online (Sandbox Code Playgroud) 我注意到,与使用SwiftUI 中的通用动画类UIView.animate
相比,它不那么古怪,更“平滑”,延迟也更少。withAnimation { }
话虽这么说,我有一些Flashcards
正在翻转。问题是,当我使用 时withAnimation { }
,会出现一些滞后,有时会让卡片看起来甚至没有翻转(看起来只是卡片内的内容立即发生变化)。我在 ScrollView 中同时渲染了 5 个抽认卡。我如何使用UIView.animate()
动画来实现变化?
struct Flashcard<Front, Back>: View where Front: View, Back: View {
var front: () -> Front
var back: () -> Back
@State var flipped: Bool = false
@State var flashcardRotation = 0.0
@State var contentRotation = 0.0
init(@ViewBuilder front: @escaping () -> Front, @ViewBuilder back: @escaping () -> Back) {
self.front = front
self.back = back
}
var body: some …
Run Code Online (Sandbox Code Playgroud) 因此,当在 SwiftUI 中呈现视图时,我尝试以不同的方式显示不同的元素(一个是从前缘滑入,另一个元素是从屏幕底部向上滑动)。我的基本视图结构如下:
struct ViewName: View {
@ObservedObject var appState: AppState //this is just a class that tracks the state of app variables, in my case it holds a variable called 'showView' that indicates whether or not to show the view.
var body: some View {
ZStack {
Color.white
.edgesIgnoringSafeArea(.all)
VStack {
Text("Test")
}.transition(AnyTransition.asymmetric(insertion: .move(edge: .leading), removal: .move(edge: .trailing)))
VStack {
Spacer()
HStack {
Text("Test2")
Spacer()
Text("Test3")
}
}.transition(AnyTransition.move(edge: .bottom))
}
}
}
Run Code Online (Sandbox Code Playgroud)
在其他地方,我用以下内容初始化了视图:
if appState.showView {
ViewName(appState: appState)
} …
Run Code Online (Sandbox Code Playgroud)