FskErr KprWebSocketEndpointNew(KprWebSocketEndpoint* it, void *refcon)
{
	FskErr err = kFskErrNone;
	KprWebSocketEndpoint self = NULL;
	
	bailIfError(FskMemPtrNewClear(sizeof(KprWebSocketEndpointRecord), it));
	self = *it;
	FskInstrumentedItemNew(self, NULL, &gKprWebSocketEndpointInstrumentation);
	
	self->refcon = refcon;
	self->state = kKprWebSocketStateConnecting;

	FskDebugStr("CREATE: KprWebSocketEndpoint\n");
	return err;
bail:
	if (self) KprWebSocketEndpointDispose(self);
	return err;
}
Exemple #2
0
void KPR_WebSocketClient(xsMachine* the)
{
	FskErr err;
	xsIntegerValue c = xsToInteger(xsArgc);
	KPR_WebSocketClientRecord *self = NULL;
	KprWebSocketEndpoint endpoint = NULL;
	
	bailIfError(FskMemPtrNewClear(sizeof(KPR_WebSocketClientRecord), &self));
	
	xsThrowIfFskErr(KprWebSocketEndpointNew(&endpoint, self));
	
	endpoint->openCallback = KPR_WebSocketClient_onOpen;
	endpoint->closeCallback = KPR_WebSocketClient_onClose;
	endpoint->textCallback = KPR_WebSocketClient_onTextMessage;
	endpoint->binaryCallback = KPR_WebSocketClient_onBinaryMessage;
	endpoint->errorCallback = KPR_WebSocketClient_onError;
	
	self->endpoint = endpoint;
	self->the = the;
	self->slot = xsThis;
	self->code = the->code;
	xsSetHostData(self->slot, self);
	// xsCall1(xsGet(xsGlobal, xsID_Object), xsID_seal, self->slot);
	
	if (c >= 1) {
		bailIfError(KprWebSocketEndpointConnect(endpoint, xsToString(xsArg(0)), NULL));
	}

	xsRemember(self->slot);

	return;
	
bail:
	KprWebSocketEndpointDispose(endpoint);
	FskMemPtrDispose(self);
	xsThrowIfFskErr(err);
}