X-Git-Url: https://git.kengrimes.com/?p=henge%2Fkiak.git;a=blobdiff_plain;f=strappPeerConnection.js;fp=strappPeerConnection.js;h=8512bc28e5a58b42b05dc29dcd10f24b897dc647;hp=0000000000000000000000000000000000000000;hb=44e0b2d571c71ebd410b78366c8bc9dc463a96c4;hpb=d17ac76d8256b00eb253138a554c7d3d51139b9e diff --git a/strappPeerConnection.js b/strappPeerConnection.js new file mode 100644 index 0000000..8512bc2 --- /dev/null +++ b/strappPeerConnection.js @@ -0,0 +1,159 @@ +/** + * @file Messaging module providing capability for files to communicate with each other + * @author Jordan Lavatai and Ken Grimes + * @version 0.0.1 + * @license AGPL-3.0 + * @copyright Strapp.io + */ + +/** Remote Peer States: + unintialized + + +/* SPC default object */ +class StrappPeerConnection extends File { + GET() { + } + POST() { + } + CONNECT() { + } + OPTIONS() { + } + DELETE() { + } + +} + + +strappPeerConnection.defaults = Object.assign({}, File.defaults, { + state: '', + messageCount: 0, + messageHandler: new Map(), /* TODO: seperate handling? */ + remotePeer: { + bestConnectionType: '', + state: '', + peerID: '' /* clientID of Peer* / + } +} + +/* GET - gets the data (queued messages) from a spc */ +/* POST - sends a msg through a spc to the remote peer */ +/* CONNECT - Tries to establish a connection with an spc */ +/* local or remote peer of the spc? */ + /* Local is part of uri, make it remote*/ + +/* File System */ +/* Convert entire file system into json objects that can be read into memory */ + + +/* Send */ +/* Receive */ +/* Reconnect WebRTC */ +/* Reconnect WS */ +/* Determine remote peers bestConnectionType */ +/* Restablish connection */ + + +/** @func Send a message to the remote peer + * @desc + * + * @arg {Object} message - message in LMKID format, except no message ID yet + * @this {Object} - Refers to the SPC that is calling send + * @return {Object} - Promise for the response from the send message + */ +function send(message) { + /* Determine if 'this' is a SPC object */ + + + /* 'send data' means to create a strapp protocol message and send it over whichever + transmission channel is available */ + switch (this.state) { + case 'unintialized': + case 'offline': + if (this.establishConnection(clientKey, data)) { + send(clientKey, data) + } + else { + storeMessage(this, message) + } + + break + case 'disconnected': + this.reestablishConnection(clientKey, data) + /* Store the message */ + /* Fail if reconnection attempt fails */ + break + case 'polling': { + /* does remote peer have the ability to upgrade? */ + /* If so, attempt to upgrade */ + /* If upgrade fails, retry the send method else send via polling */ + break + } + case 'webSocket': { + /* does remote peer have the ability to upgrade? */ + /* If so, attempt to upgrade */ + /* If upgrade fails, retry the send method else send via polling */ + break + } + case 'webRTC': { + /* If remote peer is connected, send data */ + /* Else Attemp to fix connection, if connection is dead, set this.state and try this again. Will + Enter the 'disconnected' state */ + break + } + + } +} + + + +/** @func Attempts to connect the local peer to the remote peer + * @desc + * + * @ret {boolean} True if successful, false if not + */ +function establishSPC() { + +} + +/** @func Attempts to reconnect the local peer to the remote peer + * @desc This function assumes that the remotePeer property for the SPC object has + * been elevated to a status higher than uninitialized. + * + * @ret {boolean} True if successful, false if not + */ +function reestablishSPC() { + /* If successful, send all the cached messages that were saved when connection was down */ +} + + +/** @func Stores the message + * @desc + * + */ +function storeMessage() { +} + +/** @func Determines the multimedia signaling protocol for the given session description + * @desc Does some basic duck typing to determine the type of Session Description + * @arg {Object} Session Description Object + * @return {String} Returns 'planB' if Session Description is planB, 'Unified' if + * Session Description is Unified + */ +function determineSessionDescription(sessionDescription) { +} + +/** @func Converts a planB session description to Unified session description + * @arg {Object} Session Description Object + * @return {Object} PlanB Session Description + */ +function toUnified(sessionDescription) { +} + +/** @func Converts a Unified session description to planB session description + * @arg {Object} Session Description Object + * @return {Object} PlanB Session Description + */ +function toPlanB(sessionDescription) { +}