@casual-simulation/causal-tree-client-socketio
Advanced tools
Comparing version 0.9.14 to 0.9.17
{ | ||
"name": "@casual-simulation/causal-tree-client-socketio", | ||
"version": "0.9.14", | ||
"version": "0.9.17", | ||
"description": "A set of services that can be used to network with @casual-simulation/causal-tree-server-socketio", | ||
@@ -46,4 +46,4 @@ "keywords": [ | ||
"dependencies": { | ||
"@casual-simulation/causal-tree-store-browser": "^0.9.14", | ||
"@casual-simulation/causal-trees": "^0.9.14", | ||
"@casual-simulation/causal-tree-store-browser": "^0.9.17", | ||
"@casual-simulation/causal-trees": "^0.9.17", | ||
"@casual-simulation/crypto": "^0.9.7", | ||
@@ -55,3 +55,3 @@ "@casual-simulation/crypto-browser": "^0.9.8", | ||
}, | ||
"gitHead": "659b46a08485907524e89216ef8ed60b3834b8d8" | ||
"gitHead": "2de02cad6452e12c60fac257ecf1d0eb5f2cc406" | ||
} |
@@ -1,2 +0,2 @@ | ||
import { RealtimeChannelConnection, RealtimeChannelInfo, Atom, AtomOp, SiteInfo, StoredCausalTree, SiteVersionInfo, DeviceInfo, User, RealtimeChannelResult } from '@casual-simulation/causal-trees'; | ||
import { RealtimeChannelConnection, RealtimeChannelInfo, Atom, AtomOp, SiteInfo, StoredCausalTree, SiteVersionInfo, DeviceInfo, User, RealtimeChannelResult, Event } from '@casual-simulation/causal-trees'; | ||
import { Observable } from 'rxjs'; | ||
@@ -19,4 +19,4 @@ /** | ||
constructor(socket: typeof io.Socket, connectionStateChanged: Observable<boolean>, info: RealtimeChannelInfo); | ||
login(user: User): Promise<RealtimeChannelResult<DeviceInfo>>; | ||
joinChannel(): Promise<RealtimeChannelResult<void>>; | ||
login(user: User): Observable<RealtimeChannelResult<DeviceInfo>>; | ||
joinChannel(): Observable<RealtimeChannelResult<void>>; | ||
exchangeInfo(version: SiteVersionInfo): Promise<RealtimeChannelResult<SiteVersionInfo>>; | ||
@@ -30,2 +30,3 @@ requestSiteId(site: SiteInfo): Promise<RealtimeChannelResult<boolean>>; | ||
emit(event: Atom<AtomOp>[]): Promise<RealtimeChannelResult<void>>; | ||
sendEvents(events: Event[]): Promise<void>; | ||
_request<T>(name: string, data: any): Promise<T>; | ||
@@ -32,0 +33,0 @@ readonly connectionStateChanged: Observable<boolean>; |
@@ -9,3 +9,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}; | ||
import { Subject, BehaviorSubject, } from 'rxjs'; | ||
import { Subject, BehaviorSubject } from 'rxjs'; | ||
import { map } from 'rxjs/operators'; | ||
import { socketEvent } from './Utils'; | ||
/** | ||
@@ -29,13 +31,10 @@ * Defines a RealtimeChannelConnection that can use Socket.IO. | ||
login(user) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
const info = yield this._request(`login`, user); | ||
let loginResults = socketEvent(this._socket, 'login_result', (err, info) => ({ | ||
error: err, | ||
info: info, | ||
})); | ||
this._socket.emit('login', user); | ||
return loginResults.pipe(map(({ error, info }) => { | ||
if (error) { | ||
return { | ||
success: true, | ||
value: info, | ||
}; | ||
} | ||
catch (err) { | ||
const issue = err; | ||
return { | ||
success: false, | ||
@@ -45,31 +44,33 @@ value: null, | ||
type: 'not_authenticated', | ||
reason: issue.error, | ||
reason: error.error, | ||
}, | ||
}; | ||
} | ||
}); | ||
return { | ||
success: true, | ||
value: info, | ||
}; | ||
})); | ||
} | ||
joinChannel() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
try { | ||
yield this._request(`join_channel`, this.info); | ||
let joinResults = socketEvent(this._socket, `join_channel_result_${this.info.id}`, (err) => ({ | ||
error: err, | ||
})); | ||
this._socket.emit('join_channel', this.info); | ||
return joinResults.pipe(map(({ error }) => { | ||
if (error) { | ||
return { | ||
success: true, | ||
success: false, | ||
value: null, | ||
error: { | ||
type: 'not_authorized', | ||
reason: error, | ||
}, | ||
}; | ||
} | ||
catch (err) { | ||
if (err === 'unauthorized') { | ||
return { | ||
success: false, | ||
value: null, | ||
error: { | ||
type: 'not_authorized', | ||
reason: err, | ||
}, | ||
}; | ||
} | ||
throw err; | ||
} | ||
}); | ||
return { | ||
success: true, | ||
value: null, | ||
}; | ||
})); | ||
} | ||
@@ -136,2 +137,7 @@ exchangeInfo(version) { | ||
} | ||
sendEvents(events) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this._socket.emit(`remote_event_${this.info.id}`, events); | ||
}); | ||
} | ||
_request(name, data) { | ||
@@ -138,0 +144,0 @@ return new Promise((resolve, reject) => { |
@@ -10,3 +10,3 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
import io from 'socket.io-client'; | ||
import { BehaviorSubject, } from 'rxjs'; | ||
import { BehaviorSubject } from 'rxjs'; | ||
export class SocketManager { | ||
@@ -13,0 +13,0 @@ /** |
import { Observable } from 'rxjs'; | ||
import * as io from 'socket.io-client'; | ||
export declare function socketEvent<T>(socket: typeof io.Socket, eventName: string): Observable<T>; | ||
export declare function socketEvent<T>(socket: typeof io.Socket, eventName: string, selector?: (...args: any[]) => T): Observable<T>; | ||
//# sourceMappingURL=Utils.d.ts.map |
import { fromEventPattern } from 'rxjs'; | ||
export function socketEvent(socket, eventName) { | ||
export function socketEvent(socket, eventName, selector) { | ||
return fromEventPattern(handler => { | ||
@@ -7,4 +7,4 @@ socket.on(eventName, handler); | ||
socket.off(eventName, handler); | ||
}); | ||
}, selector); | ||
} | ||
//# sourceMappingURL=Utils.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29913
448